Skip to content

Commit e5cf81f

Browse files
committed
Ensure modexp returns empty byte for mod length 0
1 parent 2640caa commit e5cf81f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

eth/precompiles/modexp.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ def modexp(computation):
122122
result = _modexp(computation.msg.data)
123123

124124
_, _, modulus_length = _extract_lengths(computation.msg.data)
125-
result_bytes = zpad_left(int_to_big_endian(result), to_size=modulus_length)
125+
126+
# Modulo 0 is undefined, return zero
127+
# https://math.stackexchange.com/questions/516251/why-is-n-mod-0-undefined
128+
result_bytes = b'' if modulus_length == 0 else zpad_left(
129+
int_to_big_endian(result),
130+
to_size=modulus_length
131+
)
126132

127133
computation.output = result_bytes
128134
return computation

0 commit comments

Comments
 (0)