-
Notifications
You must be signed in to change notification settings - Fork 107
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
new(tests): Identity precompile test #1047
Open
marioevz
wants to merge
3
commits into
main
Choose a base branch
from
identity-2021-consensus-issue-test
base: main
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
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 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 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 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 @@ | ||
"""abstract: EIP-2: Homestead Precompile Identity Test Cases.""" |
This file contains 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,103 @@ | ||
"""abstract: EIP-2: Homestead Identity Precompile Test Cases.""" | ||
|
||
import pytest | ||
|
||
from ethereum_test_tools import ( | ||
Account, | ||
Alloc, | ||
Environment, | ||
StateTestFiller, | ||
Transaction, | ||
keccak256, | ||
) | ||
from ethereum_test_tools import Opcodes as Op | ||
|
||
|
||
@pytest.mark.with_all_call_opcodes( | ||
selector=lambda call_opcode: call_opcode | ||
not in [Op.EXTCALL, Op.EXTDELEGATECALL, Op.EXTSTATICCALL] | ||
# EXT*CALL opcodes do not contain accept the return data size/offset as an argument | ||
) | ||
@pytest.mark.valid_from("Byzantium") | ||
def test_identity_return_overwrite( | ||
state_test: StateTestFiller, | ||
pre: Alloc, | ||
call_opcode: Op, | ||
): | ||
"""Test the return data of the identity precompile overwriting its input.""" | ||
env = Environment() | ||
code = ( | ||
sum(Op.MSTORE8(offset=i, value=(i + 1)) for i in range(4)) # memory = [1, 2, 3, 4] | ||
+ call_opcode( | ||
address=4, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we have global space constants for the precompiles? |
||
args_offset=0, | ||
args_size=4, # args = [1, 2, 3, 4] | ||
ret_offset=1, | ||
ret_size=4, | ||
) # memory = [1, 1, 2, 3, 4] | ||
+ Op.RETURNDATACOPY( | ||
dest_offset=0, offset=0, size=Op.RETURNDATASIZE() | ||
) # memory correct = [1, 2, 3, 4, 4], corrupt = [1, 1, 2, 3, 4] | ||
+ Op.SSTORE(1, Op.SHA3(offset=0, size=Op.MSIZE)) | ||
) | ||
contract_address = pre.deploy_contract( | ||
code=code, | ||
) | ||
tx = Transaction( | ||
sender=pre.fund_eoa(), | ||
to=contract_address, | ||
gas_limit=100_000, | ||
) | ||
|
||
post = { | ||
contract_address: Account( | ||
storage={ | ||
1: keccak256(bytes([1, 2, 3, 4, 4]).ljust(32, b"\0")), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this benefit from leftpadding? |
||
}, | ||
), | ||
} | ||
|
||
state_test(env=env, pre=pre, post=post, tx=tx) | ||
|
||
|
||
@pytest.mark.with_all_call_opcodes() | ||
@pytest.mark.valid_from("Byzantium") | ||
def test_identity_return_buffer_modify( | ||
state_test: StateTestFiller, | ||
pre: Alloc, | ||
call_opcode: Op, | ||
): | ||
"""Test the modification of the input range to attempt to modify the return buffer.""" | ||
env = Environment() | ||
code = ( | ||
sum(Op.MSTORE8(offset=i, value=(i + 1)) for i in range(4)) # memory = [1, 2, 3, 4] | ||
+ call_opcode( | ||
address=4, | ||
args_offset=0, | ||
args_size=4, # args = [1, 2, 3, 4] | ||
) # memory = [1, 2, 3, 4] | ||
+ Op.MSTORE8(offset=0, value=5) # memory = [5, 2, 3, 4] | ||
+ Op.MSTORE8(offset=4, value=5) # memory = [5, 2, 3, 4, 5] | ||
+ Op.RETURNDATACOPY( | ||
dest_offset=0, offset=0, size=Op.RETURNDATASIZE() | ||
) # memory correct = [1, 2, 3, 4, 5], corrupt = [5, 2, 3, 4, 5] | ||
+ Op.SSTORE(1, Op.SHA3(offset=0, size=Op.MSIZE)) | ||
) | ||
contract_address = pre.deploy_contract( | ||
code=code, | ||
) | ||
tx = Transaction( | ||
sender=pre.fund_eoa(), | ||
to=contract_address, | ||
gas_limit=100_000, | ||
) | ||
|
||
post = { | ||
contract_address: Account( | ||
storage={ | ||
1: keccak256(bytes([1, 2, 3, 4, 5]).ljust(32, b"\0")), | ||
}, | ||
), | ||
} | ||
|
||
state_test(env=env, pre=pre, post=post, tx=tx) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if possible I prefer to have concrete looking memory input like
0x000102030405
because when reading the code we will have to stop and calculate or sometimes we don't see what exactly the result of a calculation and when its not obvious we can have a bug and difficulty to find it.