33 Tests the MODEXP precompile, located at address 0x0000..0005. Test cases from the EIP are
44 labelled with `EIP-198-caseX` in the test id.
55"""
6+
67from dataclasses import dataclass
78
89import pytest
@@ -34,6 +35,7 @@ class ModExpInput(TestParameterGroup):
3435 modulus (str): The modulus value for the MODEXP precompile.
3536 extra_data (str): Defines extra padded data to be added at the end of the calldata
3637 to the precompile. Defaults to an empty string.
38+
3739 """
3840
3941 base : str
@@ -42,9 +44,7 @@ class ModExpInput(TestParameterGroup):
4244 extra_data : str = ""
4345
4446 def create_modexp_tx_data (self ):
45- """
46- Generates input for the MODEXP precompile.
47- """
47+ """Generate input for the MODEXP precompile."""
4848 return (
4949 "0x"
5050 + f"{ int (len (self .base )/ 2 ):x} " .zfill (64 )
@@ -59,16 +59,12 @@ def create_modexp_tx_data(self):
5959
6060@dataclass (kw_only = True , frozen = True , repr = False )
6161class ModExpRawInput (TestParameterGroup ):
62- """
63- Helper class to directly define a raw input to the MODEXP precompile.
64- """
62+ """Helper class to directly define a raw input to the MODEXP precompile."""
6563
6664 raw_input : str
6765
6866 def create_modexp_tx_data (self ):
69- """
70- The raw input is already the MODEXP precompile input.
71- """
67+ """Raw input is already the MODEXP precompile input."""
7268 return self .raw_input
7369
7470
@@ -81,6 +77,7 @@ class ExpectedOutput(TestParameterGroup):
8177 call_return_code (str): The return_code from CALL, 0 indicates unsuccessful call
8278 (out-of-gas), 1 indicates call succeeded.
8379 returned_data (str): The output returnData is the expected output of the call
80+
8481 """
8582
8683 call_return_code : str
@@ -89,7 +86,7 @@ class ExpectedOutput(TestParameterGroup):
8986
9087@pytest .mark .valid_from ("Byzantium" )
9188@pytest .mark .parametrize (
92- ["input " , "output" ],
89+ ["mod_exp_input " , "output" ],
9390 [
9491 (
9592 ModExpInput (base = "" , exponent = "" , modulus = "02" ),
@@ -206,11 +203,9 @@ class ExpectedOutput(TestParameterGroup):
206203 ids = lambda param : param .__repr__ (), # only required to remove parameter names (input/output)
207204)
208205def test_modexp (
209- state_test : StateTestFiller , input : ModExpInput , output : ExpectedOutput , pre : Alloc
206+ state_test : StateTestFiller , mod_exp_input : ModExpInput , output : ExpectedOutput , pre : Alloc
210207):
211- """
212- Test the MODEXP precompile
213- """
208+ """Test the MODEXP precompile."""
214209 env = Environment ()
215210 sender = pre .fund_eoa ()
216211
@@ -228,16 +223,14 @@ def test_modexp(
228223 + Op .MSTORE (
229224 0 ,
230225 (
231- (
232- # Need to `ljust` this PUSH32 in order to ensure the code starts
233- # in memory at offset 0 (memory right-aligns stack items which are not
234- # 32 bytes)
235- Op .PUSH32 (
236- bytes (
237- Op .CODECOPY (0 , 16 , Op .SUB (Op .CODESIZE (), 16 ))
238- + Op .RETURN (0 , Op .SUB (Op .CODESIZE , 16 ))
239- ).ljust (32 , bytes (1 ))
240- )
226+ # Need to `ljust` this PUSH32 in order to ensure the code starts
227+ # in memory at offset 0 (memory right-aligns stack items which are not
228+ # 32 bytes)
229+ Op .PUSH32 (
230+ bytes (
231+ Op .CODECOPY (0 , 16 , Op .SUB (Op .CODESIZE (), 16 ))
232+ + Op .RETURN (0 , Op .SUB (Op .CODESIZE , 16 ))
233+ ).ljust (32 , bytes (1 ))
241234 )
242235 ),
243236 )
@@ -252,7 +245,7 @@ def test_modexp(
252245 tx = Transaction (
253246 ty = 0x0 ,
254247 to = account ,
255- data = input .create_modexp_tx_data (),
248+ data = mod_exp_input .create_modexp_tx_data (),
256249 gas_limit = 500000 ,
257250 gas_price = 10 ,
258251 protected = True ,
0 commit comments