Skip to content

Commit 4fb09e4

Browse files
committed
Reformat eip4750.py
1 parent 92ee66d commit 4fb09e4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

eips_code/eip4750.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from dataclasses import dataclass
22
from eip3540 import ValidationException
33

4+
45
@dataclass
56
class FunctionType:
67
inputs: int
78
outputs: int
89

10+
911
MAGIC = b'\xEF\x00'
1012
VERSION = 0x01
1113
S_TERMINATOR = 0x00
@@ -43,6 +45,7 @@ class FunctionType:
4345
for opcode in range(0x60, 0x7f + 1): # PUSH1..PUSH32
4446
immediate_sizes[opcode] = opcode - 0x60 + 1
4547

48+
4649
# Validate EOF code.
4750
# Raises ValidationException on invalid code
4851
def validate_eof(code: bytes):
@@ -115,6 +118,7 @@ def validate_eof(code: bytes):
115118
if len(section_sizes[S_TYPE]) > 0 and (code[pos] != 0 or code[pos + 1] != 0):
116119
raise ValidationException("invalid type of section 0")
117120

121+
118122
# Validates any code
119123
def is_valid_eof(code: bytes) -> bool:
120124
try:
@@ -123,6 +127,7 @@ def is_valid_eof(code: bytes) -> bool:
123127
return False
124128
return True
125129

130+
126131
# Raises ValidationException on invalid code
127132
def validate_code_section(func_id: int, code: bytes, types: list[FunctionType] = [FunctionType(0, 0)]):
128133
# Note that EOF1 already asserts this with the code section requirements
@@ -142,7 +147,7 @@ def validate_code_section(func_id: int, code: bytes, types: list[FunctionType] =
142147
if opcode == 0x5c or opcode == 0x5d:
143148
if pos + 2 > len(code):
144149
raise ValidationException("truncated relative jump offset")
145-
offset = int.from_bytes(code[pos:pos+2], byteorder = "big", signed = True)
150+
offset = int.from_bytes(code[pos:pos + 2], byteorder="big", signed=True)
146151

147152
rjumpdest = pos + 2 + offset
148153
if rjumpdest < 0 or rjumpdest >= len(code):
@@ -152,22 +157,22 @@ def validate_code_section(func_id: int, code: bytes, types: list[FunctionType] =
152157
elif opcode == 0xb0:
153158
if pos + 2 > len(code):
154159
raise ValidationException("truncated CALLF immediate")
155-
section_id = int.from_bytes(code[pos:pos+2], byteorder = "big", signed = False)
160+
section_id = int.from_bytes(code[pos:pos + 2], byteorder="big", signed=False)
156161

157162
if section_id >= len(types):
158163
raise ValidationException("invalid section id")
159164
elif opcode == 0xb2:
160165
if pos + 2 > len(code):
161166
raise ValidationException("truncated JUMPF immediate")
162-
section_id = int.from_bytes(code[pos:pos+2], byteorder = "big", signed = False)
167+
section_id = int.from_bytes(code[pos:pos + 2], byteorder="big", signed=False)
163168

164169
if section_id >= len(types):
165170
raise ValidationException("invalid section id")
166171

167172
if types[section_id].outputs != types[func_id].outputs:
168-
raise ValidationException("incompatible function type for JUMPF")
173+
raise ValidationException("incompatible function type for JUMPF")
169174

170-
# Save immediate value positions
175+
# Save immediate value positions
171176
immediates.update(range(pos, pos + immediate_sizes[opcode]))
172177
# Skip immediates
173178
pos += immediate_sizes[opcode]

0 commit comments

Comments
 (0)