Possible issue in ModExpGadget #842
Description
An example case:
base_len = 1, exp_len = 1, mod_len = 1
base = 0x21, exp_len = 0x23, mod_len = 0x57
I.e. the input bytes are as follows (note that we always right-pad the real input with 0 to have length 192)
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000001
2123570000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
That is, we have call_data_length = 96 + 3 = 99.
zkevm-circuits/zkevm-circuits/src/evm_circuit/execution/precompiles/modexp.rs
Lines 787 to 792 in 517127f
The code above can be translated to the following constraints:
// kr is short for challenges.keccak_input()
// padding_zero = kr^93
if i < 93: input_bytes_acc[i] = garbage_bytes[i];
if 93 <= i < 96: input_bytes_acc[i] = garbage_bytes[i] + input[i] // vulnerability here
if i >= 96: input_bytes_acc[i] = input[i]
In the example, it means
0x21 = garbage_bytes[93] + input[93]
: we can setinput[93]
to any byte that we want.