diff --git a/evm/src/all_stark.rs b/evm/src/all_stark.rs index f2103df2..f02e0202 100644 --- a/evm/src/all_stark.rs +++ b/evm/src/all_stark.rs @@ -178,17 +178,13 @@ mod tests { logic_stark: &LogicStark, rng: &mut R, ) -> Vec> { + let all_ops = [logic::Op::And, logic::Op::Or, logic::Op::Xor]; let ops = (0..num_rows) .map(|_| { + let op = all_ops[rng.gen_range(0..all_ops.len())]; let input0 = U256(rng.gen()); let input1 = U256(rng.gen()); - let result = input0 ^ input1; - Operation { - operator: logic::Op::Xor, - input0, - input1, - result, - } + Operation::new(op, input0, input1) }) .collect(); logic_stark.generate_trace(ops) diff --git a/evm/src/generation/mod.rs b/evm/src/generation/mod.rs index 3550b829..4eb3cbbf 100644 --- a/evm/src/generation/mod.rs +++ b/evm/src/generation/mod.rs @@ -12,7 +12,10 @@ use crate::util::trace_rows_to_poly_values; mod memory; pub(crate) mod state; -pub type RlpMerkleProof = Vec>; +pub type RlpBlob = Vec; + +/// Merkle proofs are encoded using an RLP blob for each node in the path. +pub type RlpMerkleProof = Vec; #[allow(unused)] // TODO: Should be used soon. pub struct TransactionData { diff --git a/evm/src/generation/state.rs b/evm/src/generation/state.rs index 8f690df0..4dbd90fe 100644 --- a/evm/src/generation/state.rs +++ b/evm/src/generation/state.rs @@ -5,7 +5,7 @@ use crate::cpu::columns::NUM_CPU_COLUMNS; use crate::cpu::kernel::aggregator::combined_kernel; use crate::cpu::kernel::assembler::Kernel; use crate::generation::memory::MemoryState; -use crate::logic::Operation; +use crate::logic::{Op, Operation}; use crate::memory::memory_stark::MemoryOp; use crate::{keccak, logic}; @@ -27,39 +27,26 @@ impl GenerationState { /// Compute logical AND, and record the operation to be added in the logic table later. #[allow(unused)] // TODO: Should be used soon. pub(crate) fn and(&mut self, input0: U256, input1: U256) -> U256 { - let result = input0 & input1; - self.logic_ops.push(Operation { - operator: logic::Op::And, - input0, - input1, - result, - }); - result + self.logic_op(Op::And, input0, input1) } /// Compute logical OR, and record the operation to be added in the logic table later. #[allow(unused)] // TODO: Should be used soon. pub(crate) fn or(&mut self, input0: U256, input1: U256) -> U256 { - let result = input0 | input1; - self.logic_ops.push(Operation { - operator: logic::Op::Or, - input0, - input1, - result, - }); - result + self.logic_op(Op::Or, input0, input1) } /// Compute logical XOR, and record the operation to be added in the logic table later. #[allow(unused)] // TODO: Should be used soon. pub(crate) fn xor(&mut self, input0: U256, input1: U256) -> U256 { - let result = input0 ^ input1; - self.logic_ops.push(Operation { - operator: logic::Op::Xor, - input0, - input1, - result, - }); + self.logic_op(Op::Xor, input0, input1) + } + + /// Compute logical AND, and record the operation to be added in the logic table later. + pub(crate) fn logic_op(&mut self, op: Op, input0: U256, input1: U256) -> U256 { + let operation = Operation::new(op, input0, input1); + let result = operation.result; + self.logic_ops.push(operation); result } diff --git a/evm/src/logic.rs b/evm/src/logic.rs index 708ddf13..bde5d645 100644 --- a/evm/src/logic.rs +++ b/evm/src/logic.rs @@ -68,7 +68,7 @@ pub struct LogicStark { pub f: PhantomData, } -#[derive(Debug)] +#[derive(Copy, Clone, Debug)] pub(crate) enum Op { And, Or, @@ -77,12 +77,28 @@ pub(crate) enum Op { #[derive(Debug)] pub(crate) struct Operation { - pub(crate) operator: Op, - pub(crate) input0: U256, - pub(crate) input1: U256, + operator: Op, + input0: U256, + input1: U256, pub(crate) result: U256, } +impl Operation { + pub(crate) fn new(operator: Op, input0: U256, input1: U256) -> Self { + let result = match operator { + Op::And => input0 & input1, + Op::Or => input0 | input1, + Op::Xor => input0 ^ input1, + }; + Operation { + operator, + input0, + input1, + result, + } + } +} + impl LogicStark { pub(crate) fn generate_trace(&self, operations: Vec) -> Vec> { let len = operations.len();