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

fix: add support for SELFBALANCE opcode #395

Merged
merged 10 commits into from
May 27, 2024
Merged

fix: add support for SELFBALANCE opcode #395

merged 10 commits into from
May 27, 2024

Conversation

Karrq
Copy link
Contributor

@Karrq Karrq commented May 23, 2024

Motivation

When an account balance is read, and zk mode is enabled, we intercept the BALANCE opcode and read the balance from the L2 Eth system contract.
When checking the test address's balance (via address(this).balance), any balance change seems to not be reflected, causing failures on some tests.

Solution

address(this).balance doesn't always use the BALANCE opcode, but the SELFBALANCE opcode instead (or at least, it can use that opcode), as it is more gas efficient.
Adding support for this opcode ensures that this pattern reads the expected contract balance.

@Karrq Karrq requested a review from nbaztec May 23, 2024 22:51
@Karrq Karrq self-assigned this May 23, 2024
@Karrq Karrq requested a review from Jrigada May 23, 2024 22:51
@Karrq Karrq requested a review from nbaztec May 24, 2024 18:12
@Karrq Karrq requested a review from nbaztec May 27, 2024 19:26
@Karrq Karrq merged commit 4761d29 into dev May 27, 2024
10 checks passed
@Karrq Karrq deleted the fix/selfbalance branch May 27, 2024 22:38
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

Successfully merging this pull request may close these issues.

2 participants