Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Skip invalid tx #32

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open

Skip invalid tx #32

wants to merge 46 commits into from

Conversation

xiaodino
Copy link

@xiaodino xiaodino commented Nov 3, 2022

Please see #115 and #104

@xiaodino xiaodino changed the title Add begin_tx_invalid_nonce and begin_tx_not_enough_gas [IN PROGRESS] Add begin_tx_invalid_nonce and begin_tx_not_enough_gas Nov 3, 2022
@xiaodino xiaodino changed the title [IN PROGRESS] Add begin_tx_invalid_nonce and begin_tx_not_enough_gas [IN PROGRESS] Add begin_tx_invalid_nonce and begin_tx_not_enough_eth Nov 11, 2022
@xiaodino xiaodino marked this pull request as draft November 18, 2022 06:10
@xiaodino xiaodino changed the title [IN PROGRESS] Add begin_tx_invalid_nonce and begin_tx_not_enough_eth Add begin_tx_invalid_nonce and begin_tx_not_enough_eth Nov 22, 2022
@xiaodino xiaodino changed the title Add begin_tx_invalid_nonce and begin_tx_not_enough_eth Skip invalid tx Nov 22, 2022
@xiaodino xiaodino marked this pull request as ready for review November 22, 2022 05:23
@xiaodino xiaodino requested a review from Brechtpd November 22, 2022 13:31
[step.rw_indices[7], step.rw_indices[8], step.rw_indices[9]]
.map(|idx| block.rws[idx].account_value_pair());
let [caller_nonce_pair, caller_balance_pair, callee_balance_pair, (callee_code_hash, _)] =
[4, 7, 8, 9].map(|idx| block.rws[step.rw_indices[idx]].account_value_pair());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Brechtpd Where are [4, 7, 8, 9] from?

let nonce_prev = state.sdb.get_account(&caller_address).1.nonce.as_u64();
// Increase caller's nonce when the tx is not invalid
let nonce = if !state.tx.invalid_tx {
state.sdb.increase_nonce(&caller_address) + 1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line should be nonce_prev+1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the implementation I think that's what this does, because increase_nonce, a bit surprisingly, returns the old nonce, not the new nonce.

@xiaodino xiaodino marked this pull request as ready for review January 29, 2023 06:28
@@ -304,7 +304,8 @@ impl<'a> CircuitInputStateRef<'a> {
// AccountNonExisting proofs lookups).
if (!matches!(op.field, AccountField::CodeHash)
&& (matches!(rw, RW::READ) || (op.value_prev.is_zero() && op.value.is_zero())))
&& account.is_empty() && !self.tx.invalid_tx
&& account.is_empty()
&& !self.tx.invalid_tx

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For invalid transactions we also need to read the balance/nonce which could from a non-existing account, so I don't think we can just disable the check here? Or are those reads prevented in some other way?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current also did account balance reads before doing the codehash check, it seems that is incorrect: privacy-scaling-explorations#1118 (comment).

Let's way a bit until these things are fixed on the master before updating the code there.

Comment on lines +352 to +353
// state.sdb.increase_nonce(&caller_address) + 1
nonce_prev + 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the transaction is valid the nonce in the account state should be increased right? Could you explain more why we shouldn't update the nonce in the account for valid transactions they way it was done before (this code changes the behavior for normal transactions)?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah never mind, I see the code on the master has been updated to not use increase_nonce either.

@@ -20,6 +20,7 @@ import (
// while replaying a transaction in debug mode as well as transaction
// execution status, the amount of gas used and the return value
type ExecutionResult struct {
Invalid bool `json:"invalid"`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid is not a field in github.com/ethereum/go-ethereum/internal/ethapi.ExecutionResult

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's okay, this is mainly only there to make things a bit cleaner and to handle error messages better. If we run a trace against a real node and it errors our or returns nothing we'll also know it's invalid.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

5 participants