Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
test: pass first basic testing
Browse files Browse the repository at this point in the history
  • Loading branch information
KimiWu123 committed Jan 4, 2024
1 parent c5b107f commit ef70191
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 68 deletions.
1 change: 0 additions & 1 deletion bus-mapping/src/evm/opcodes/precompiles/ecrecover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub(crate) fn opt_data(
sig_v,
),
pk: recovered_pk,
// msg: Bytes::default(),
msg_hash: {
let msg_hash = BigUint::from_bytes_be(&aux_data.msg_hash.to_be_bytes());
let msg_hash = msg_hash.mod_floor(&*SECP256K1_Q);
Expand Down
8 changes: 8 additions & 0 deletions bus-mapping/src/evm/opcodes/precompiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ pub fn gen_associated_ops(

let (opt_event, aux_data) = match precompile {
PrecompileCalls::Ecrecover => opt_data_ecrecover(input_bytes, output_bytes, return_bytes),
PrecompileCalls::Identity => (
None,
Some(PrecompileAuxData::Base {
input_bytes: input_bytes.to_vec(),
output_bytes: output_bytes.to_vec(),
return_bytes: return_bytes.to_vec(),
}),
),
_ => {
log::warn!("precompile {:?} unsupported in circuits", precompile);
(
Expand Down
19 changes: 7 additions & 12 deletions eth-types/src/sign_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn sign(
randomness: secp256k1::Fq,
sk: secp256k1::Fq,
msg_hash: secp256k1::Fq,
) -> (secp256k1::Fq, secp256k1::Fq) {
) -> (secp256k1::Fq, secp256k1::Fq, u8) {
let randomness_inv =
Option::<secp256k1::Fq>::from(randomness.invert()).expect("cannot invert randomness");
let generator = Secp256k1Affine::generator();
Expand All @@ -37,7 +37,8 @@ pub fn sign(

let sig_r = secp256k1::Fq::from_uniform_bytes(&x_bytes); // get x coordinate (E::Base) on E::Scalar
let sig_s = randomness_inv * (msg_hash + sig_r * sk);
(sig_r, sig_s)
let sig_v = sig_point.to_affine().y.is_odd().unwrap_u8();
(sig_r, sig_s, sig_v)
}

/// Signature data required by the SignVerify Chip as input to verify a
Expand All @@ -49,8 +50,6 @@ pub struct SignData {
pub signature: (secp256k1::Fq, secp256k1::Fq, u8),
/// Secp256k1 public key
pub pk: Secp256k1Affine,
/// Message being hashed before signing.
// pub msg: Bytes,
/// Hash of the message that is being signed
pub msg_hash: secp256k1::Fq,
}
Expand All @@ -61,12 +60,8 @@ impl SignData {
if self.pk == Secp256k1Affine::identity() {
return Address::zero();
}
let pk_le = pk_bytes_le(&self.pk);
let pk_be = pk_bytes_swap_endianness(&pk_le);
let pk_hash = keccak256(pk_be);
let mut addr_bytes = [0u8; 20];
addr_bytes.copy_from_slice(&pk_hash[12..]);
Address::from_slice(&addr_bytes)
let pk_hash = keccak256(pk_bytes_swap_endianness(&pk_bytes_le(&self.pk)));
Address::from_slice(&pk_hash[12..])
}
}

Expand All @@ -78,10 +73,10 @@ lazy_static! {
let pk = pk.to_affine();
let msg_hash = secp256k1::Fq::ONE;
let randomness = secp256k1::Fq::ONE;
let (sig_r, sig_s) = sign(randomness, sk, msg_hash);
let (sig_r, sig_s, sig_v) = sign(randomness, sk, msg_hash);

SignData {
signature: (sig_r, sig_s, 28),
signature: (sig_r, sig_s, sig_v),
pk,
msg_hash,
}
Expand Down
1 change: 1 addition & 0 deletions zkevm-circuits/src/evm_circuit/execution/callop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ impl<F: Field> ExecutionGadget<F> for CallOpGadget<F> {
// whether the call is to a precompiled contract.
// precompile contracts are stored from address 0x01 to 0x09.
let is_code_address_zero = IsZeroGadget::construct(cb, call_gadget.callee_address.expr());
// FIXME try to remove 0x0A
let is_precompile_lt =
LtGadget::construct(cb, call_gadget.callee_address.expr(), 0x0A.expr());
let is_precompile = and::expr([
Expand Down
Loading

0 comments on commit ef70191

Please sign in to comment.