Skip to content

Commit

Permalink
minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
roynalnaruto committed Jun 26, 2023
1 parent 2176c44 commit 6ab87ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct EcrecoverGadget<F> {
sig_v: Cell<F>,
sig_r_rlc: Cell<F>,
sig_s_rlc: Cell<F>,
recovered_addr: RandomLinearCombination<F, N_BYTES_ACCOUNT_ADDRESS>,
recovered_addr_rlc: RandomLinearCombination<F, N_BYTES_ACCOUNT_ADDRESS>,

is_success: Cell<F>,
callee_address: Cell<F>,
Expand All @@ -42,7 +42,7 @@ impl<F: Field> ExecutionGadget<F> for EcrecoverGadget<F> {
const NAME: &'static str = "ECRECOVER";

fn configure(cb: &mut EVMConstraintBuilder<F>) -> Self {
let (recovered, msg_hash_rlc, sig_v, sig_r_rlc, sig_s_rlc, recovered_addr) = (
let (recovered, msg_hash_rlc, sig_v, sig_r_rlc, sig_s_rlc, recovered_addr_rlc) = (
cb.query_bool(),
cb.query_cell_phase2(),
cb.query_byte(),
Expand All @@ -59,7 +59,7 @@ impl<F: Field> ExecutionGadget<F> for EcrecoverGadget<F> {
sig_v.expr(),
sig_r_rlc.expr(),
sig_s_rlc.expr(),
from_bytes::expr(&recovered_addr.cells),
from_bytes::expr(&recovered_addr_rlc.cells),
);
});

Expand Down Expand Up @@ -97,7 +97,7 @@ impl<F: Field> ExecutionGadget<F> for EcrecoverGadget<F> {
sig_v,
sig_r_rlc,
sig_s_rlc,
recovered_addr,
recovered_addr_rlc,
is_success,
callee_address,
caller_id,
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<F: Field> ExecutionGadget<F> for EcrecoverGadget<F> {
.keccak_input()
.map(|r| rlc::value(&aux_data.sig_s.to_le_bytes(), r)),
)?;
self.recovered_addr.assign(
self.recovered_addr_rlc.assign(
region,
offset,
Some({
Expand Down
26 changes: 16 additions & 10 deletions zkevm-circuits/src/evm_circuit/util/precompile_gadget.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bus_mapping::precompile::PrecompileCalls;
use eth_types::Field;
use gadgets::util::Expr;
use gadgets::util::{not, Expr};
use halo2_proofs::plonk::Expression;

use crate::evm_circuit::{param::N_BYTES_ACCOUNT_ADDRESS, step::ExecutionState};
Expand Down Expand Up @@ -39,7 +39,7 @@ impl<F: Field> PrecompileGadget<F> {

cb.condition(address.value_equals(PrecompileCalls::Ecrecover), |cb| {
cb.constrain_next_step(ExecutionState::PrecompileEcrecover, None, |cb| {
let (_recovered, msg_hash, sig_v, sig_r, sig_s, recovered_addr) = (
let (recovered, msg_hash_rlc, sig_v, sig_r_rlc, sig_s_rlc, recovered_addr_rlc) = (
cb.query_bool(),
cb.query_cell_phase2(),
cb.query_byte(),
Expand All @@ -58,16 +58,22 @@ impl<F: Field> PrecompileGadget<F> {
cb.require_equal(
"input bytes (RLC) = [msg_hash | sig_v | sig_r | sig_s]",
input_bytes_rlc.expr(),
(msg_hash.expr() * r_pow_96)
(msg_hash_rlc.expr() * r_pow_96)
+ ((sig_v.expr() + 27.expr()) * r_pow_64)
+ (sig_r.expr() * r_pow_32)
+ sig_s.expr(),
);
cb.require_equal(
"output bytes (RLC) = recovered address",
output_bytes_rlc.expr(),
recovered_addr.expr(),
+ (sig_r_rlc.expr() * r_pow_32)
+ sig_s_rlc.expr(),
);
cb.condition(recovered.expr(), |cb| {
cb.require_equal(
"output bytes (RLC) = recovered address",
output_bytes_rlc.expr(),
recovered_addr_rlc.expr(),
);
});
cb.condition(not::expr(recovered.expr()), |cb| {
cb.require_zero("output bytes == 0", output_bytes_rlc.expr());
cb.require_zero("recovered addr == 0", recovered_addr_rlc.expr());
});
});
});

Expand Down

0 comments on commit 6ab87ea

Please sign in to comment.