-
Notifications
You must be signed in to change notification settings - Fork 146
feat(tests): add EIP-7951 for secp256r1 curve #1670
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f8f4fc3
feat: configure test env for osaka
LouisTsai-Csie cf29165
feat: add tests for rip-7212 to support secp256r1
LouisTsai-Csie c914817
test: add gas requirement and call type test
LouisTsai-Csie 008425d
test(P256VERIFY): add fork transition tests
LouisTsai-Csie 1e528f4
test: use precompile as set code delegated address
LouisTsai-Csie 58061fe
test: add precompile as tx entry point
LouisTsai-Csie 15a998c
refactor: add eip checklist marker
LouisTsai-Csie 6b3ff06
refactor: update rip7212 to eip7951
LouisTsai-Csie d533100
feat: add curve params and negative tests
LouisTsai-Csie d17c7f1
refactor: update precompile as set code delegated address
LouisTsai-Csie de89b7d
fix: update bounded value to include precompile
LouisTsai-Csie ae3ece5
doc: add comments for external test vectors
LouisTsai-Csie 2a1099a
docs: update changelog
LouisTsai-Csie 8e99f4b
refactor: rename filename
LouisTsai-Csie 44a62c1
fix: update frontier configuration
LouisTsai-Csie 30d9cde
Revert "fix: update frontier configuration"
marioevz b8b39e2
refactor: improve precompile address handling in tests
marioevz 2c8bf2f
fix: tox
marioevz 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
""" | ||
abstract: Tests [EIP-7951: Precompile for secp256r1 Curve Support](https://eips.ethereum.org/EIPS/eip-7951) | ||
Test cases for [EIP-7951: Precompile for secp256r1 Curve Support](https://eips.ethereum.org/EIPS/eip-7951)]. | ||
""" |
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,161 @@ | ||
"""Shared pytest definitions local to EIP-7951 tests.""" | ||
|
||
from typing import SupportsBytes | ||
|
||
import pytest | ||
|
||
from ethereum_test_forks import Fork | ||
from ethereum_test_tools import EOA, Address, Alloc, Bytecode, Storage, Transaction, keccak256 | ||
from ethereum_test_tools import Opcodes as Op | ||
|
||
from .spec import Spec | ||
|
||
|
||
@pytest.fixture | ||
def vector_gas_value() -> int | None: | ||
""" | ||
Gas value from the test vector if any. | ||
|
||
If `None` it means that the test scenario did not come from a file, so no comparison is needed. | ||
|
||
The `vectors_from_file` function reads the gas value from the file and overwrites this fixture. | ||
""" | ||
return None | ||
|
||
|
||
@pytest.fixture | ||
def precompile_gas(vector_gas_value: int | None) -> int: | ||
"""Gas cost for the precompile.""" | ||
if vector_gas_value is not None: | ||
assert vector_gas_value == Spec.P256VERIFY_GAS, ( | ||
f"Calculated gas {vector_gas_value} != Vector gas {Spec.P256VERIFY_GAS}" | ||
) | ||
return Spec.P256VERIFY_GAS | ||
|
||
|
||
@pytest.fixture | ||
def precompile_gas_modifier() -> int: | ||
""" | ||
Modify the gas passed to the precompile, for testing purposes. | ||
|
||
By default the call is made with the exact gas amount required for the given opcode, | ||
but when this fixture is overridden, the gas amount can be modified to, e.g., test | ||
a lower amount and test if the precompile call fails. | ||
""" | ||
return 0 | ||
|
||
|
||
@pytest.fixture | ||
def call_opcode() -> Op: | ||
""" | ||
Type of call used to call the precompile. | ||
|
||
By default it is Op.CALL, but it can be overridden in the test. | ||
""" | ||
return Op.CALL | ||
|
||
|
||
@pytest.fixture | ||
def call_contract_post_storage() -> Storage: | ||
""" | ||
Storage of the test contract after the transaction is executed. | ||
Note: Fixture `call_contract_code` fills the actual expected storage values. | ||
""" | ||
return Storage() | ||
|
||
|
||
@pytest.fixture | ||
def call_succeeds() -> bool: | ||
""" | ||
By default, depending on the expected output, we can deduce if the call is expected to succeed | ||
or fail. | ||
""" | ||
return True | ||
|
||
|
||
@pytest.fixture | ||
def call_contract_code( | ||
precompile_address: int, | ||
precompile_gas: int, | ||
precompile_gas_modifier: int, | ||
expected_output: bytes | SupportsBytes, | ||
call_succeeds: bool, | ||
call_opcode: Op, | ||
call_contract_post_storage: Storage, | ||
) -> Bytecode: | ||
"""Code of the test contract.""" | ||
expected_output = bytes(expected_output) | ||
assert call_opcode in [Op.CALL, Op.CALLCODE, Op.DELEGATECALL, Op.STATICCALL] | ||
value = [0] if call_opcode in [Op.CALL, Op.CALLCODE] else [] | ||
|
||
code = Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE()) + Op.SSTORE( | ||
call_contract_post_storage.store_next(call_succeeds), | ||
call_opcode( | ||
precompile_gas + precompile_gas_modifier, | ||
precompile_address, | ||
*value, | ||
0, | ||
Op.CALLDATASIZE(), | ||
0, | ||
0, | ||
) | ||
+ Op.SSTORE( | ||
call_contract_post_storage.store_next(len(expected_output)), Op.RETURNDATASIZE() | ||
), | ||
) | ||
if call_succeeds: | ||
# Add integrity check only if the call is expected to succeed. | ||
code += Op.RETURNDATACOPY(0, 0, Op.RETURNDATASIZE()) + Op.SSTORE( | ||
call_contract_post_storage.store_next(keccak256(expected_output)), | ||
Op.SHA3(0, Op.RETURNDATASIZE()), | ||
) | ||
return code | ||
|
||
|
||
@pytest.fixture | ||
def call_contract_address(pre: Alloc, call_contract_code: Bytecode) -> Address: | ||
"""Address where the test contract will be deployed.""" | ||
return pre.deploy_contract(call_contract_code) | ||
|
||
|
||
@pytest.fixture | ||
def sender(pre: Alloc) -> EOA: | ||
"""Sender of the transaction.""" | ||
return pre.fund_eoa() | ||
|
||
|
||
@pytest.fixture | ||
def post(call_contract_address: Address, call_contract_post_storage: Storage): | ||
"""Test expected post outcome.""" | ||
return { | ||
call_contract_address: { | ||
"storage": call_contract_post_storage, | ||
}, | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def tx_gas_limit(fork: Fork, input_data: bytes, precompile_gas: int) -> int: | ||
"""Transaction gas limit used for the test (Can be overridden in the test).""" | ||
intrinsic_gas_cost_calculator = fork.transaction_intrinsic_cost_calculator() | ||
memory_expansion_gas_calculator = fork.memory_expansion_gas_calculator() | ||
extra_gas = 100_000 | ||
return ( | ||
extra_gas | ||
+ intrinsic_gas_cost_calculator(calldata=input_data) | ||
+ memory_expansion_gas_calculator(new_bytes=len(input_data)) | ||
+ precompile_gas | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def tx( | ||
input_data: bytes, | ||
tx_gas_limit: int, | ||
call_contract_address: Address, | ||
sender: EOA, | ||
) -> Transaction: | ||
"""Transaction for the test.""" | ||
return Transaction( | ||
gas_limit=tx_gas_limit, data=input_data, to=call_contract_address, sender=sender | ||
) |
Oops, something went wrong.
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.