forked from ethereum/execution-specs
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(tests): RESERVE_BALANCE precompile with tests #14
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
Open
pdobacz
wants to merge
9
commits into
forks/monad_nine
Choose a base branch
from
mip4
base: forks/monad_nine
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b0d15c4
Extract is_reserve_balance_violated function
pdobacz 31173b9
feat(tests): RESERVE_BALANCE precompile with tests
pdobacz 7c27872
Generic precompile tests aware of Monad precompiles
pdobacz d5b842b
Move & rename MONAD_NEXT to MONAD_NINE (post-rebase)
pdobacz aa0a112
Revert "Gas-dependent error message for `method not supported`"
pdobacz eaee82c
Make the call gas stipend revert scenario compatible
pdobacz 3414971
fix typo claude insists on fixing...
pdobacz 2b9d255
feat(mip4): revert when Monad precompile called via delegating EOA
pdobacz 9f71185
Apply suggestion from greptile
pdobacz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/ethereum/forks/monad_nine/vm/precompiled_contracts/reserve_balance.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| """ | ||
| Ethereum Virtual Machine (EVM) RESERVE BALANCE PRECOMPILED CONTRACT. | ||
|
|
||
| .. contents:: Table of Contents | ||
| :backlinks: none | ||
| :local: | ||
|
|
||
| Introduction | ||
| ------------ | ||
|
|
||
| Implementation of the RESERVE BALANCE precompiled contract for MIP-4. | ||
| """ | ||
|
|
||
| from ethereum_types.numeric import U256 | ||
|
|
||
| from ...vm import Evm | ||
| from ...vm.exceptions import InvalidParameter, RevertInMonadPrecompile | ||
| from ...vm.gas import GAS_WARM_ACCESS, charge_gas | ||
|
|
||
| # Function selector for dippedIntoReserve() | ||
| # keccak256("dippedIntoReserve()")[:4].hex() == "3a61584e" | ||
| DIPPED_INTO_RESERVE_SELECTOR = bytes.fromhex("3a61584e") | ||
|
|
||
|
|
||
| def _is_call(evm: Evm) -> bool: | ||
| # STATICCALL: is_static is True | ||
| # DELEGATECALL: should_transfer_value is False | ||
| # CALLCODE: code_address != current_target | ||
| if evm.message.is_static: | ||
| return False | ||
| if not evm.message.should_transfer_value: | ||
| return False | ||
| if evm.message.code_address != evm.message.current_target: | ||
| return False | ||
| return True | ||
|
|
||
|
|
||
| def reserve_balance(evm: Evm) -> None: | ||
| """ | ||
| Return whether execution is in reserve balance violation. | ||
|
|
||
| The precompile must be invoked via CALL. Invocations via STATICCALL, | ||
| DELEGATECALL, or CALLCODE must revert. | ||
|
|
||
| The method is not payable and must revert with the error message | ||
| "value is nonzero" when called with a nonzero value. | ||
|
|
||
| Calldata must be exactly the 4-byte function selector (0x3a61584e). | ||
| If the selector does not match, the precompile reverts with "method | ||
| not supported". If extra calldata is appended beyond the selector, | ||
| the precompile reverts with "input is invalid". | ||
|
|
||
| Reverts consume all gas provided to the call frame. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| evm : | ||
| The current EVM frame. | ||
|
|
||
| """ | ||
| from ..interpreter import is_reserve_balance_violated | ||
|
|
||
| data = evm.message.data | ||
|
|
||
| # Must be invoked via CALL only (not STATICCALL, DELEGATECALL, CALLCODE) | ||
| if not _is_call(evm): | ||
| raise InvalidParameter | ||
|
|
||
| # GAS | ||
| charge_gas(evm, GAS_WARM_ACCESS) | ||
|
|
||
| if len(data) < 4: | ||
| evm.output = b"method not supported" | ||
| raise RevertInMonadPrecompile | ||
|
|
||
| if data[:4] != DIPPED_INTO_RESERVE_SELECTOR: | ||
| evm.output = b"method not supported" | ||
| raise RevertInMonadPrecompile | ||
|
|
||
| if evm.message.value != 0: | ||
| evm.output = b"value is nonzero" | ||
| raise RevertInMonadPrecompile | ||
|
|
||
| if len(data) > 4: | ||
| evm.output = b"input is invalid" | ||
| raise RevertInMonadPrecompile | ||
|
|
||
| # OPERATION | ||
| violation = is_reserve_balance_violated( | ||
| evm.message.block_env.state, | ||
| evm.message.tx_env, | ||
| ) | ||
| # Return bool encoded as uint256 (32 bytes) | ||
| evm.output = U256(1 if violation else 0).to_be_bytes32() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.