Skip to content

Commit 74fb2a4

Browse files
obatirouSamWilsn
authored andcommitted
refactor: modexp exponent_head stricter type
1 parent 3712229 commit 74fb2a4

File tree

12 files changed

+76
-76
lines changed

12 files changed

+76
-76
lines changed

src/ethereum/arrow_glacier/vm/precompiled_contracts/modexp.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def modexp(evm: Evm) -> None:
3535

3636
exp_start = U256(96) + base_length
3737

38-
exp_head = Uint.from_be_bytes(
38+
exp_head = U256.from_be_bytes(
3939
buffer_read(data, exp_start, min(U256(32), exp_length))
4040
)
4141

@@ -89,7 +89,7 @@ def complexity(base_length: U256, modulus_length: U256) -> Uint:
8989
return words ** Uint(2)
9090

9191

92-
def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
92+
def iterations(exponent_length: U256, exponent_head: U256) -> Uint:
9393
"""
9494
Calculate the number of iterations required to perform a modular
9595
exponentiation.
@@ -102,7 +102,7 @@ def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
102102
103103
exponent_head :
104104
First 32 bytes of the exponent (with leading zero padding if it is
105-
shorter than 32 bytes), as an unsigned integer.
105+
shorter than 32 bytes), as a U256.
106106
107107
Returns
108108
-------
@@ -113,15 +113,15 @@ def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
113113
if exponent_length <= U256(32) and exponent_head == U256(0):
114114
count = Uint(0)
115115
elif exponent_length <= U256(32):
116-
bit_length = Uint(exponent_head.bit_length())
116+
bit_length = exponent_head.bit_length()
117117

118118
if bit_length > Uint(0):
119119
bit_length -= Uint(1)
120120

121121
count = bit_length
122122
else:
123123
length_part = Uint(8) * (Uint(exponent_length) - Uint(32))
124-
bits_part = Uint(exponent_head.bit_length())
124+
bits_part = exponent_head.bit_length()
125125

126126
if bits_part > Uint(0):
127127
bits_part -= Uint(1)
@@ -135,7 +135,7 @@ def gas_cost(
135135
base_length: U256,
136136
modulus_length: U256,
137137
exponent_length: U256,
138-
exponent_head: Uint,
138+
exponent_head: U256,
139139
) -> Uint:
140140
"""
141141
Calculate the gas cost of performing a modular exponentiation.
@@ -154,7 +154,7 @@ def gas_cost(
154154
155155
exponent_head :
156156
First 32 bytes of the exponent (with leading zero padding if it is
157-
shorter than 32 bytes), as an unsigned integer.
157+
shorter than 32 bytes), as a U256.
158158
159159
Returns
160160
-------

src/ethereum/berlin/vm/precompiled_contracts/modexp.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def modexp(evm: Evm) -> None:
3535

3636
exp_start = U256(96) + base_length
3737

38-
exp_head = Uint.from_be_bytes(
38+
exp_head = U256.from_be_bytes(
3939
buffer_read(data, exp_start, min(U256(32), exp_length))
4040
)
4141

@@ -89,7 +89,7 @@ def complexity(base_length: U256, modulus_length: U256) -> Uint:
8989
return words ** Uint(2)
9090

9191

92-
def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
92+
def iterations(exponent_length: U256, exponent_head: U256) -> Uint:
9393
"""
9494
Calculate the number of iterations required to perform a modular
9595
exponentiation.
@@ -102,7 +102,7 @@ def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
102102
103103
exponent_head :
104104
First 32 bytes of the exponent (with leading zero padding if it is
105-
shorter than 32 bytes), as an unsigned integer.
105+
shorter than 32 bytes), as a U256.
106106
107107
Returns
108108
-------
@@ -113,15 +113,15 @@ def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
113113
if exponent_length <= U256(32) and exponent_head == U256(0):
114114
count = Uint(0)
115115
elif exponent_length <= U256(32):
116-
bit_length = Uint(exponent_head.bit_length())
116+
bit_length = exponent_head.bit_length()
117117

118118
if bit_length > Uint(0):
119119
bit_length -= Uint(1)
120120

121121
count = bit_length
122122
else:
123123
length_part = Uint(8) * (Uint(exponent_length) - Uint(32))
124-
bits_part = Uint(exponent_head.bit_length())
124+
bits_part = exponent_head.bit_length()
125125

126126
if bits_part > Uint(0):
127127
bits_part -= Uint(1)
@@ -135,7 +135,7 @@ def gas_cost(
135135
base_length: U256,
136136
modulus_length: U256,
137137
exponent_length: U256,
138-
exponent_head: Uint,
138+
exponent_head: U256,
139139
) -> Uint:
140140
"""
141141
Calculate the gas cost of performing a modular exponentiation.
@@ -154,7 +154,7 @@ def gas_cost(
154154
155155
exponent_head :
156156
First 32 bytes of the exponent (with leading zero padding if it is
157-
shorter than 32 bytes), as an unsigned integer.
157+
shorter than 32 bytes), as a U256.
158158
159159
Returns
160160
-------

src/ethereum/byzantium/vm/precompiled_contracts/modexp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def modexp(evm: Evm) -> None:
3535

3636
exp_start = U256(96) + base_length
3737

38-
exp_head = Uint.from_be_bytes(
38+
exp_head = U256.from_be_bytes(
3939
buffer_read(data, exp_start, min(U256(32), exp_length))
4040
)
4141

@@ -101,7 +101,7 @@ def complexity(base_length: U256, modulus_length: U256) -> Uint:
101101
)
102102

103103

104-
def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
104+
def iterations(exponent_length: U256, exponent_head: U256) -> Uint:
105105
"""
106106
Calculate the number of iterations required to perform a modular
107107
exponentiation.
@@ -114,7 +114,7 @@ def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
114114
115115
exponent_head :
116116
First 32 bytes of the exponent (with leading zero padding if it is
117-
shorter than 32 bytes), as an unsigned integer.
117+
shorter than 32 bytes), as a U256.
118118
119119
Returns
120120
-------
@@ -137,7 +137,7 @@ def gas_cost(
137137
base_length: U256,
138138
modulus_length: U256,
139139
exponent_length: U256,
140-
exponent_head: Uint,
140+
exponent_head: U256,
141141
) -> Uint:
142142
"""
143143
Calculate the gas cost of performing a modular exponentiation.
@@ -156,7 +156,7 @@ def gas_cost(
156156
157157
exponent_head :
158158
First 32 bytes of the exponent (with leading zero padding if it is
159-
shorter than 32 bytes), as an unsigned integer.
159+
shorter than 32 bytes), as a U256.
160160
161161
Returns
162162
-------

src/ethereum/cancun/vm/precompiled_contracts/modexp.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def modexp(evm: Evm) -> None:
3535

3636
exp_start = U256(96) + base_length
3737

38-
exp_head = Uint.from_be_bytes(
38+
exp_head = U256.from_be_bytes(
3939
buffer_read(data, exp_start, min(U256(32), exp_length))
4040
)
4141

@@ -89,7 +89,7 @@ def complexity(base_length: U256, modulus_length: U256) -> Uint:
8989
return words ** Uint(2)
9090

9191

92-
def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
92+
def iterations(exponent_length: U256, exponent_head: U256) -> Uint:
9393
"""
9494
Calculate the number of iterations required to perform a modular
9595
exponentiation.
@@ -102,7 +102,7 @@ def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
102102
103103
exponent_head :
104104
First 32 bytes of the exponent (with leading zero padding if it is
105-
shorter than 32 bytes), as an unsigned integer.
105+
shorter than 32 bytes), as a U256.
106106
107107
Returns
108108
-------
@@ -113,15 +113,15 @@ def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
113113
if exponent_length <= U256(32) and exponent_head == U256(0):
114114
count = Uint(0)
115115
elif exponent_length <= U256(32):
116-
bit_length = Uint(exponent_head.bit_length())
116+
bit_length = exponent_head.bit_length()
117117

118118
if bit_length > Uint(0):
119119
bit_length -= Uint(1)
120120

121121
count = bit_length
122122
else:
123123
length_part = Uint(8) * (Uint(exponent_length) - Uint(32))
124-
bits_part = Uint(exponent_head.bit_length())
124+
bits_part = exponent_head.bit_length()
125125

126126
if bits_part > Uint(0):
127127
bits_part -= Uint(1)
@@ -135,7 +135,7 @@ def gas_cost(
135135
base_length: U256,
136136
modulus_length: U256,
137137
exponent_length: U256,
138-
exponent_head: Uint,
138+
exponent_head: U256,
139139
) -> Uint:
140140
"""
141141
Calculate the gas cost of performing a modular exponentiation.
@@ -154,7 +154,7 @@ def gas_cost(
154154
155155
exponent_head :
156156
First 32 bytes of the exponent (with leading zero padding if it is
157-
shorter than 32 bytes), as an unsigned integer.
157+
shorter than 32 bytes), as a U256.
158158
159159
Returns
160160
-------

src/ethereum/constantinople/vm/precompiled_contracts/modexp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def modexp(evm: Evm) -> None:
3535

3636
exp_start = U256(96) + base_length
3737

38-
exp_head = Uint.from_be_bytes(
38+
exp_head = U256.from_be_bytes(
3939
buffer_read(data, exp_start, min(U256(32), exp_length))
4040
)
4141

@@ -101,7 +101,7 @@ def complexity(base_length: U256, modulus_length: U256) -> Uint:
101101
)
102102

103103

104-
def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
104+
def iterations(exponent_length: U256, exponent_head: U256) -> Uint:
105105
"""
106106
Calculate the number of iterations required to perform a modular
107107
exponentiation.
@@ -114,7 +114,7 @@ def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
114114
115115
exponent_head :
116116
First 32 bytes of the exponent (with leading zero padding if it is
117-
shorter than 32 bytes), as an unsigned integer.
117+
shorter than 32 bytes), as a U256.
118118
119119
Returns
120120
-------
@@ -137,7 +137,7 @@ def gas_cost(
137137
base_length: U256,
138138
modulus_length: U256,
139139
exponent_length: U256,
140-
exponent_head: Uint,
140+
exponent_head: U256,
141141
) -> Uint:
142142
"""
143143
Calculate the gas cost of performing a modular exponentiation.
@@ -156,7 +156,7 @@ def gas_cost(
156156
157157
exponent_head :
158158
First 32 bytes of the exponent (with leading zero padding if it is
159-
shorter than 32 bytes), as an unsigned integer.
159+
shorter than 32 bytes), as a U256.
160160
161161
Returns
162162
-------

src/ethereum/gray_glacier/vm/precompiled_contracts/modexp.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def modexp(evm: Evm) -> None:
3535

3636
exp_start = U256(96) + base_length
3737

38-
exp_head = Uint.from_be_bytes(
38+
exp_head = U256.from_be_bytes(
3939
buffer_read(data, exp_start, min(U256(32), exp_length))
4040
)
4141

@@ -89,7 +89,7 @@ def complexity(base_length: U256, modulus_length: U256) -> Uint:
8989
return words ** Uint(2)
9090

9191

92-
def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
92+
def iterations(exponent_length: U256, exponent_head: U256) -> Uint:
9393
"""
9494
Calculate the number of iterations required to perform a modular
9595
exponentiation.
@@ -102,7 +102,7 @@ def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
102102
103103
exponent_head :
104104
First 32 bytes of the exponent (with leading zero padding if it is
105-
shorter than 32 bytes), as an unsigned integer.
105+
shorter than 32 bytes), as a U256.
106106
107107
Returns
108108
-------
@@ -113,15 +113,15 @@ def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
113113
if exponent_length <= U256(32) and exponent_head == U256(0):
114114
count = Uint(0)
115115
elif exponent_length <= U256(32):
116-
bit_length = Uint(exponent_head.bit_length())
116+
bit_length = exponent_head.bit_length()
117117

118118
if bit_length > Uint(0):
119119
bit_length -= Uint(1)
120120

121121
count = bit_length
122122
else:
123123
length_part = Uint(8) * (Uint(exponent_length) - Uint(32))
124-
bits_part = Uint(exponent_head.bit_length())
124+
bits_part = exponent_head.bit_length()
125125

126126
if bits_part > Uint(0):
127127
bits_part -= Uint(1)
@@ -135,7 +135,7 @@ def gas_cost(
135135
base_length: U256,
136136
modulus_length: U256,
137137
exponent_length: U256,
138-
exponent_head: Uint,
138+
exponent_head: U256,
139139
) -> Uint:
140140
"""
141141
Calculate the gas cost of performing a modular exponentiation.
@@ -154,7 +154,7 @@ def gas_cost(
154154
155155
exponent_head :
156156
First 32 bytes of the exponent (with leading zero padding if it is
157-
shorter than 32 bytes), as an unsigned integer.
157+
shorter than 32 bytes), as a U256.
158158
159159
Returns
160160
-------

src/ethereum/istanbul/vm/precompiled_contracts/modexp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def modexp(evm: Evm) -> None:
3535

3636
exp_start = U256(96) + base_length
3737

38-
exp_head = Uint.from_be_bytes(
38+
exp_head = U256.from_be_bytes(
3939
buffer_read(data, exp_start, min(U256(32), exp_length))
4040
)
4141

@@ -101,7 +101,7 @@ def complexity(base_length: U256, modulus_length: U256) -> Uint:
101101
)
102102

103103

104-
def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
104+
def iterations(exponent_length: U256, exponent_head: U256) -> Uint:
105105
"""
106106
Calculate the number of iterations required to perform a modular
107107
exponentiation.
@@ -114,7 +114,7 @@ def iterations(exponent_length: U256, exponent_head: Uint) -> Uint:
114114
115115
exponent_head :
116116
First 32 bytes of the exponent (with leading zero padding if it is
117-
shorter than 32 bytes), as an unsigned integer.
117+
shorter than 32 bytes), as a U256.
118118
119119
Returns
120120
-------
@@ -137,7 +137,7 @@ def gas_cost(
137137
base_length: U256,
138138
modulus_length: U256,
139139
exponent_length: U256,
140-
exponent_head: Uint,
140+
exponent_head: U256,
141141
) -> Uint:
142142
"""
143143
Calculate the gas cost of performing a modular exponentiation.
@@ -156,7 +156,7 @@ def gas_cost(
156156
157157
exponent_head :
158158
First 32 bytes of the exponent (with leading zero padding if it is
159-
shorter than 32 bytes), as an unsigned integer.
159+
shorter than 32 bytes), as a U256.
160160
161161
Returns
162162
-------

0 commit comments

Comments
 (0)