Skip to content

Commit efb5a00

Browse files
refactor: update vector and data types
1 parent 4546872 commit efb5a00

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

tests/byzantium/eip198_modexp_precompile/helpers.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class ModExpInput(TestParameterGroup):
2323
exponent: Bytes
2424
modulus: Bytes
2525
extra_data: Bytes = Field(default_factory=Bytes)
26+
raw_input: Bytes | None = None
2627

2728
@property
2829
def length_base(self) -> Bytes:
@@ -41,6 +42,8 @@ def length_modulus(self) -> Bytes:
4142

4243
def __bytes__(self):
4344
"""Generate input for the MODEXP precompile."""
45+
if self.raw_input is not None:
46+
return self.raw_input
4447
return (
4548
self.length_base
4649
+ self.length_exponent
@@ -60,22 +63,31 @@ def from_bytes(cls, input_data: Bytes | str) -> "ModExpInput":
6063
"""
6164
if isinstance(input_data, str):
6265
input_data = Bytes(input_data)
63-
base_length = int.from_bytes(input_data[0:32], byteorder="big")
64-
exponent_length = int.from_bytes(input_data[32:64], byteorder="big")
65-
modulus_length = int.from_bytes(input_data[64:96], byteorder="big")
66+
assert not isinstance(input_data, str)
67+
padded_input_data = input_data
68+
if len(padded_input_data) < 96:
69+
padded_input_data = Bytes(padded_input_data.ljust(96, b"\0"))
70+
71+
base_length = int.from_bytes(padded_input_data[0:32], byteorder="big")
72+
exponent_length = int.from_bytes(padded_input_data[32:64], byteorder="big")
73+
modulus_length = int.from_bytes(padded_input_data[64:96], byteorder="big")
74+
75+
total_required_length = 96 + base_length + exponent_length + modulus_length
76+
if len(padded_input_data) < total_required_length:
77+
padded_input_data = Bytes(
78+
padded_input_data.ljust(min(1024, total_required_length), b"\0")
79+
)
6680

6781
current_index = 96
68-
base = input_data[current_index : current_index + base_length]
82+
base = padded_input_data[current_index : current_index + base_length]
6983
current_index += base_length
7084

71-
exponent = input_data[current_index : current_index + exponent_length]
85+
exponent = padded_input_data[current_index : current_index + exponent_length]
7286
current_index += exponent_length
7387

74-
modulus = input_data[current_index : current_index + modulus_length]
75-
76-
modulus = modulus.ljust(min(1024, modulus_length), b"\x00")
88+
modulus = padded_input_data[current_index : current_index + modulus_length]
7789

78-
return cls(base=base, exponent=exponent, modulus=modulus)
90+
return cls(base=base, exponent=exponent, modulus=modulus, raw_input=input_data)
7991

8092

8193
class ModExpOutput(TestParameterGroup):

tests/osaka/eip7883_modexp_gas_increase/test_modexp_thresholds.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
import pytest
99

1010
from ethereum_test_checklists import EIPChecklist
11-
from ethereum_test_tools import (
12-
Alloc,
13-
StateTestFiller,
14-
Transaction,
15-
)
11+
from ethereum_test_tools import Alloc, StateTestFiller, Transaction
1612
from ethereum_test_tools.vm.opcode import Opcodes as Op
1713

1814
from ...byzantium.eip198_modexp_precompile.helpers import ModExpInput

tests/osaka/eip7883_modexp_gas_increase/vector/legacy.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@
135135
"Name": "legacy-case-27"
136136
},
137137
{
138-
"Input": "000000000000000000000000000000000000000000000000000000000000002100000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010035ee4e488f45e64d2f07becd54646357381d32f30b74c299a8c25d5202c04938ef6c4764a04f10fc908b78c4486886000f6d290251a79681a83b950c7e5c373510",
139-
"Expected": "01",
138+
"Input": "000000000000000000000000000000000000000000000000000000000000002100000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010035ee4e488f45e64d2f07becd54646357381d32f30b74c299a8c25d5202c04938ef6c4764a04f10fc908b78c4486886000f6d290251a79681a83b950c7e5c37351",
139+
"Expected": "01000000000000000000000000000000",
140140
"Name": "legacy-case-31"
141141
},
142142
{

tests/osaka/eip7883_modexp_gas_increase/vector/vectors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
},
142142
{
143143
"Input": "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000181000000000000000000000000000000000000000000000000000000000000000801ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2cffffffffffffffffffffffffffffffffffffffffffffffffffffffff3b10000000006c01ffffffffffffffffffffffffffffffffffffffffffffffdffffb97ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff3bffffffffffffffffffffffffffffffffffffffffffffffffffffffffebafd93b37ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc5bb6affffffff3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2a",
144-
"Expected": "0001",
144+
"Expected": "0001000000000000",
145145
"Name": "guido-4-even",
146146
"GasOld": 1026,
147147
"GasNew": 94448

0 commit comments

Comments
 (0)