Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BALANCE opcode must return a different value for the origin account #225

Open
Lohann opened this issue Nov 20, 2023 · 1 comment
Open

BALANCE opcode must return a different value for the origin account #225

Lohann opened this issue Nov 20, 2023 · 1 comment

Comments

@Lohann
Copy link

Lohann commented Nov 20, 2023

Crate version: v0.41.0

Related: #222
While using this EVM to sync with ethereum mainnet, I've a found a sync mismatch when processing the transaction at block 165514:
https://etherscan.io/tx/0xe01fcce5f0fb0d04d253908ebadbada9308731a8bd0d1f1b37ad3af111e6a055

Issue

The BALANCE Opcode must return a different balance for the origin account (a.k.a. tx signer), instead of returning the actual balance, it must return the worst case balance for this account, which is balance - (tx.gasPrice * tx.gasLimit), because the transaction is being processed, and we don't know the final the balance.

Example contract:

ORIGIN # or CALLER, once they are the same here
BALANCE
PUSH1 0x00
SSTORE
STOP

Expected Behavior:

before execute transaction: 0x47e512b02979c8b8
returned by BALANCE opcode: 0x47336ff3fab4c8b8 == balance - (gas_price * gas_limit)
after apply state changes: 0x47c014fbdbd794b8 == balance - (gas_price * gas_used)

Actual behavior:

before execute transaction: 0x47e512b02979c8b8
returned by BALANCE opcode: 0x47e512b02979c8b8
after apply state changes: 0x47c014fbdbd794b8

Workaround

Decrement the tx sender balance before execute the tx,and increment again after apply the state changes.

@sorpaas
Copy link
Member

sorpaas commented Nov 20, 2023

I think this is fixed in the next branch, but I'll keep this in note and make sure it's actually the case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants