Skip to content

Commit

Permalink
Move random_linear_combine fn to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ed255 committed May 24, 2022
1 parent 654f48b commit 78fa6cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
14 changes: 5 additions & 9 deletions zkevm-circuits/src/tx_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

mod sign_verify;

use crate::util::Expr;
use crate::util::{random_linear_combine_word as rlc, Expr};
use eth_types::{
geth_types::Transaction, Address, Field, ToBigEndian, ToLittleEndian, ToScalar, Word,
};
Expand Down Expand Up @@ -42,10 +42,6 @@ lazy_static! {
]);
}

fn random_linear_combine<F: Field>(bytes: [u8; 32], randomness: F) -> F {
crate::evm_circuit::util::Word::random_linear_combine(bytes, randomness)
}

fn recover_pk(v: u8, r: &Word, s: &Word, msg_hash: &[u8; 32]) -> Result<Secp256k1Affine, Error> {
let r_be = r.to_be_bytes();
let s_be = s.to_be_bytes();
Expand Down Expand Up @@ -325,15 +321,15 @@ impl<F: Field, const MAX_TXS: usize, const MAX_CALLDATA: usize> Circuit<F>
for (tag, value) in &[
(
TxFieldTag::Nonce,
random_linear_combine(tx.nonce.to_le_bytes(), self.randomness),
rlc(tx.nonce.to_le_bytes(), self.randomness),
),
(
TxFieldTag::Gas,
random_linear_combine(tx.gas_limit.to_le_bytes(), self.randomness),
rlc(tx.gas_limit.to_le_bytes(), self.randomness),
),
(
TxFieldTag::GasPrice,
random_linear_combine(tx.gas_price.to_le_bytes(), self.randomness),
rlc(tx.gas_price.to_le_bytes(), self.randomness),
),
(
TxFieldTag::CallerAddress,
Expand All @@ -349,7 +345,7 @@ impl<F: Field, const MAX_TXS: usize, const MAX_CALLDATA: usize> Circuit<F>
(TxFieldTag::IsCreate, F::from(tx.to.is_none() as u64)),
(
TxFieldTag::Value,
random_linear_combine(tx.value.to_le_bytes(), self.randomness),
rlc(tx.value.to_le_bytes(), self.randomness),
),
(
TxFieldTag::CallDataLength,
Expand Down
9 changes: 8 additions & 1 deletion zkevm-circuits/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Common utility traits and functions.
use bus_mapping::operation::Target;
use eth_types::evm_types::{GasCost, OpcodeId};
use eth_types::{
evm_types::{GasCost, OpcodeId},
Field,
};
use halo2_proofs::{arithmetic::FieldExt, plonk::Expression};

pub(crate) trait Expr<F: FieldExt> {
Expand Down Expand Up @@ -63,3 +66,7 @@ impl<F: FieldExt> Expr<F> for i32 {
)
}
}

pub(crate) fn random_linear_combine_word<F: Field>(bytes: [u8; 32], randomness: F) -> F {
crate::evm_circuit::util::Word::random_linear_combine(bytes, randomness)
}

0 comments on commit 78fa6cf

Please sign in to comment.