Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Possible issue in ModExpGadget  #842

Open
@kunxian-xia

Description

@kunxian-xia

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.

cb.require_equal(
"input acc bytes with padding must equal",
input_bytes_acc.expr(),
padding_zero.expr() * input.bytes_rlc()
+ rlc_rev(&garbage_bytes_holder, cb.challenges().keccak_input()),
);

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 set input[93] to any byte that we want.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions