-
Notifications
You must be signed in to change notification settings - Fork 387
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 ecrecover input rlc comparison (right-padding zeroes) #585
Conversation
@@ -57,22 +91,22 @@ impl<F: Field> PrecompileGadget<F> { | |||
}; | |||
cb.require_equal( | |||
"input bytes (RLC) = [msg_hash | sig_v | sig_r | sig_s]", | |||
input_bytes_rlc.expr(), | |||
padding_gadget.padded_rlc(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a bit concern. when cb.condition(pad_right.expr()
is false, i think the constraints inside PaddingGadget is all disabled. so there are no constraints to enforce relationship between padding_gadget.padded_rlc and input_bytes_rlc/cd_length/input_len when pad_right == false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very good catch. I will handle input_bytes_rlc == padded_rlc
if pad_right == false
i think cb.pow_of_rand_lookup(0, 0) is valid (of course it is not part of the first 128 rows we assigned but following rows, default value there is all 0, so pow_of_rand_lookup(0, 0) is valid). Will this behavior be ok for soundness? if ok, then we can add some comments above the pow_of_rand_table definition, if not ok, we can add the "fixed" q_enable col. |
* feat: preliminary work * wip * finish assignment to ecrecover * fix: input length may be different than call data length (for precompiles) * fix: input bytes to ecrecover * minor edits * Fix ecrecover input rlc comparison (right-padding zeroes) (#585) * potential approach (pow of rand lookup) * add lookup for pow of rand * fix: right pad only if needed * fix: missing constraint on padded_rlc * constrain pow of rand table * Update step.rs * fix: sig_v sanity check (remove assertions to allow garbage input) * fix: calldata length == 0 handled * chore: renaming precompile_* and parallel iter for tests --------- Co-authored-by: Zhang Zhuo <mycinbrin@gmail.com>
Description
Input RLC comparison in precompiles
ecrecover
,ecAdd
, ecMul` can fail as inputs are right-padded with zeroes. Since those zeroes were not accounted for in the copy circuit, the RLC value was incorrect.Type of change
Rationale
We add a lookup table
PowOfRand
which represents the below table:where
r
represents the keccak randomness (which is used as the randomness to calculate RLC of input bytes in the copy circuit).The precompiles
ecrecover
,ecAdd
andecMul
expect 128, 128 and 96 input bytes respectively, but if the calldata does not have sufficient number of bytes, zero bytes are padded to the right before running the precompile computation.We use the following approach: