Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix modexp type mismatch #414

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/halmos/sevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2165,14 +2165,30 @@ def call_unknown() -> None:
# modexp
elif eq(to, con_addr(5)):
exit_code = con(1)
modulus_size = ex.int_of(extract_bytes(arg, 64, 32))

# lengths in bytes
base_len = ex.int_of(arg.get_word(0))
exponent_len = ex.int_of(arg.get_word(32))
modulus_len = ex.int_of(arg.get_word(64))
input_len = base_len + exponent_len + modulus_len

# The rest of the input is discarded.
# Whenever the input is too short,
# the missing bytes are considered to be zero.
modexp_input = arg.slice(96, 96 + input_len)

# lengths in bits
input_bitsize = input_len * 8
modulus_bitsize = modulus_len * 8

f_modexp = Function(
f"f_modexp_{arg_size}_{modulus_size}",
BitVecSorts[arg_size],
BitVecSorts[modulus_size],
f"f_modexp_{input_bitsize}_{modulus_bitsize}",
BitVecSorts[input_bitsize],
BitVecSorts[modulus_bitsize],
)

# TODO: empty returndata in error
ret = ByteVec(f_modexp(arg))
ret = ByteVec(f_modexp(modexp_input.unwrap()))

# ecadd
elif eq(to, con_addr(6)):
Expand Down
Loading