55
66import pytest
77
8+ from ethereum_test_checklists import EIPChecklist
89from ethereum_test_tools import (
10+ Address ,
911 Alloc ,
1012 Environment ,
1113 StateTestFiller ,
3335 # Source: https://github.com/C2SP/wycheproof/blob/main/testvectors/ecdsa_secp256r1_sha256_test.json
3436)
3537@pytest .mark .parametrize ("precompile_address" , [Spec .P256VERIFY ], ids = ["" ])
36- @pytest .mark .eip_checklist ("precompile/test/call_contexts/normal" )
37- @pytest .mark .eip_checklist ("precompile/test/inputs/valid" )
38+ @EIPChecklist .Precompile .Test .CallContexts .Normal ()
39+ @EIPChecklist .Precompile .Test .Inputs .Valid ()
40+ @EIPChecklist .Precompile .Test .Inputs .MaxValues ()
3841def test_valid (state_test : StateTestFiller , pre : Alloc , post : dict , tx : Transaction ):
3942 """Test P256Verify precompile."""
4043 state_test (env = Environment (), pre = pre , post = post , tx = tx )
@@ -189,14 +192,16 @@ def test_valid(state_test: StateTestFiller, pre: Alloc, post: dict, tx: Transact
189192)
190193@pytest .mark .parametrize ("expected_output" , [Spec .INVALID_RETURN_VALUE ], ids = ["" ])
191194@pytest .mark .parametrize ("precompile_address" , [Spec .P256VERIFY ], ids = ["" ])
192- @pytest .mark .eip_checklist ("precompile/test/inputs/all_zeros" )
193- @pytest .mark .eip_checklist ("precompile/test/inputs/invalid" )
194- @pytest .mark .eip_checklist ("precompile/test/inputs/invalid/crypto" )
195- @pytest .mark .eip_checklist ("precompile/test/inputs/invalid/corrupted" )
196- @pytest .mark .eip_checklist ("precompile/test/input_lengths/zero" )
197- @pytest .mark .eip_checklist ("precompile/test/input_lengths/static/correct" )
198- @pytest .mark .eip_checklist ("precompile/test/input_lengths/static/too_short" )
199- @pytest .mark .eip_checklist ("precompile/test/input_lengths/static/too_long" )
195+ @EIPChecklist .Precompile .Test .Inputs .AllZeros ()
196+ @EIPChecklist .Precompile .Test .Inputs .Invalid ()
197+ @EIPChecklist .Precompile .Test .Inputs .Invalid .Crypto ()
198+ @EIPChecklist .Precompile .Test .Inputs .Invalid .Corrupted ()
199+ @EIPChecklist .Precompile .Test .InputLengths .Zero ()
200+ @EIPChecklist .Precompile .Test .InputLengths .Static .Correct ()
201+ @EIPChecklist .Precompile .Test .InputLengths .Static .TooShort ()
202+ @EIPChecklist .Precompile .Test .InputLengths .Static .TooLong ()
203+ @EIPChecklist .Precompile .Test .OutOfBounds .Max ()
204+ @EIPChecklist .Precompile .Test .OutOfBounds .MaxPlusOne ()
200205def test_invalid (state_test : StateTestFiller , pre : Alloc , post : dict , tx : Transaction ):
201206 """Negative tests for the P256VERIFY precompile."""
202207 state_test (env = Environment (), pre = pre , post = post , tx = tx )
@@ -236,8 +241,8 @@ def test_invalid(state_test: StateTestFiller, pre: Alloc, post: dict, tx: Transa
236241 ],
237242)
238243@pytest .mark .parametrize ("precompile_address" , [Spec .P256VERIFY ], ids = ["" ])
239- @pytest . mark . eip_checklist ( "precompile/test/gas_usage/constant/exact" )
240- @pytest . mark . eip_checklist ( "precompile/test/gas_usage/constant/oog" )
244+ @EIPChecklist . Precompile . Test . GasUsage . Constant . Exact ( )
245+ @EIPChecklist . Precompile . Test . GasUsage . Constant . Oog ( )
241246def test_gas (state_test : StateTestFiller , pre : Alloc , post : dict , tx : Transaction ):
242247 """Test P256Verify precompile gas requirements."""
243248 state_test (env = Environment (), pre = pre , post = post , tx = tx )
@@ -262,9 +267,9 @@ def test_gas(state_test: StateTestFiller, pre: Alloc, post: dict, tx: Transactio
262267 ],
263268)
264269@pytest .mark .parametrize ("precompile_address" , [Spec .P256VERIFY ], ids = ["" ])
265- @pytest . mark . eip_checklist ( "precompile/test/call_contexts/delegate" )
266- @pytest . mark . eip_checklist ( "precompile/test/call_contexts/static" )
267- @pytest . mark . eip_checklist ( "precompile/test/call_contexts/callcode" )
270+ @EIPChecklist . Precompile . Test . CallContexts . Delegate ( )
271+ @EIPChecklist . Precompile . Test . CallContexts . Static ( )
272+ @EIPChecklist . Precompile . Test . CallContexts . Callcode ( )
268273def test_call_types (
269274 state_test : StateTestFiller ,
270275 pre : Alloc ,
@@ -286,7 +291,7 @@ def test_call_types(
286291 ),
287292 ],
288293)
289- @pytest . mark . eip_checklist ( "precompile/test/call_contexts/tx_entry" )
294+ @EIPChecklist . Precompile . Test . CallContexts . TxEntry ( )
290295def test_precompile_as_tx_entry_point (
291296 state_test : StateTestFiller ,
292297 pre : Alloc ,
@@ -297,6 +302,58 @@ def test_precompile_as_tx_entry_point(
297302 state_test (env = Environment (), pre = pre , post = post , tx = tx )
298303
299304
305+ @pytest .mark .parametrize (
306+ "input_data,precompile_address,expected_output" ,
307+ [
308+ pytest .param (
309+ Spec .H0 + Spec .R0 + Spec .S0 + Spec .X0 + Spec .Y0 ,
310+ Spec .P256VERIFY ,
311+ Spec .SUCCESS_RETURN_VALUE ,
312+ id = "valid_input_with_value_transfer" ,
313+ ),
314+ ],
315+ )
316+ @EIPChecklist .Precompile .Test .ValueTransfer .NoFee ()
317+ def test_precompile_will_return_success_with_tx_value (
318+ state_test : StateTestFiller ,
319+ pre : Alloc ,
320+ input_data : bytes ,
321+ expected_output : bytes ,
322+ precompile_address : Address ,
323+ ):
324+ """Test P256Verify precompile will not fail if value is sent."""
325+ sender = pre .fund_eoa ()
326+ storage = Storage ()
327+
328+ call_256verify_bytecode = (
329+ Op .CALLDATACOPY (0 , 0 , Op .CALLDATASIZE ())
330+ + Op .CALL (
331+ gas = Spec .P256VERIFY_GAS ,
332+ address = Spec .P256VERIFY ,
333+ value = Op .CALLVALUE (),
334+ args_offset = 0 ,
335+ args_size = Op .CALLDATASIZE (),
336+ ret_offset = 0 ,
337+ ret_size = 32 ,
338+ )
339+ + Op .SSTORE (storage .store_next (True ), Op .DUP1 ())
340+ + Op .SSTORE (storage .store_next (expected_output ), Op .MLOAD (0 ))
341+ + Op .SSTORE (storage .store_next (len (expected_output )), Op .RETURNDATASIZE ())
342+ + Op .STOP
343+ )
344+
345+ contract_address = pre .deploy_contract (call_256verify_bytecode )
346+ tx = Transaction (
347+ sender = sender ,
348+ gas_limit = 1000000 ,
349+ to = contract_address ,
350+ value = 1000 ,
351+ data = input_data ,
352+ )
353+ post = {contract_address : {"storage" : storage }}
354+ state_test (env = Environment (), pre = pre , post = post , tx = tx )
355+
356+
300357@pytest .mark .parametrize (
301358 "input_data,expected_output" ,
302359 [
@@ -334,8 +391,8 @@ def test_precompile_as_tx_entry_point(
334391 ],
335392)
336393@pytest .mark .parametrize ("precompile_address" , [Spec .P256VERIFY ], ids = ["" ])
337- @pytest . mark . eip_checklist ( "precompile/test/inputs/valid" )
338- @pytest . mark . eip_checklist ( "precompile/test/inputs/invalid/crypto" )
394+ @EIPChecklist . Precompile . Test . Inputs . Valid ( )
395+ @EIPChecklist . Precompile . Test . Inputs . Invalid . Crypto ( )
339396def test_modular_comparison (state_test : StateTestFiller , pre : Alloc , post : dict , tx : Transaction ):
340397 """
341398 Test the modular comparison condition for secp256r1 precompile.
@@ -363,10 +420,10 @@ def test_modular_comparison(state_test: StateTestFiller, pre: Alloc, post: dict,
363420 ],
364421)
365422@pytest .mark .parametrize ("precompile_address" , [Spec .P256VERIFY ], ids = ["" ])
423+ @EIPChecklist .Precompile .Test .CallContexts .Initcode .Tx ()
366424def test_contract_creation_transaction (
367425 state_test : StateTestFiller ,
368426 pre : Alloc ,
369- post : dict ,
370427 tx : Transaction ,
371428 input_data : bytes ,
372429 expected_output : bytes ,
@@ -426,10 +483,10 @@ def test_contract_creation_transaction(
426483)
427484@pytest .mark .parametrize ("precompile_address" , [Spec .P256VERIFY ], ids = ["" ])
428485@pytest .mark .parametrize ("opcode" , [Op .CREATE , Op .CREATE2 ])
486+ @EIPChecklist .Precompile .Test .CallContexts .Initcode .CREATE ()
429487def test_contract_initcode (
430488 state_test : StateTestFiller ,
431489 pre : Alloc ,
432- post : dict ,
433490 tx : Transaction ,
434491 input_data : bytes ,
435492 expected_output : bytes ,
0 commit comments