This commit is contained in:
Daniel Lubarov 2022-07-12 14:33:10 -07:00
parent a3deefd891
commit 10c31b7036
4 changed files with 38 additions and 36 deletions

View File

@ -178,17 +178,13 @@ mod tests {
logic_stark: &LogicStark<F, D>,
rng: &mut R,
) -> Vec<PolynomialValues<F>> {
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)

View File

@ -12,7 +12,10 @@ use crate::util::trace_rows_to_poly_values;
mod memory;
pub(crate) mod state;
pub type RlpMerkleProof = Vec<Vec<u8>>;
pub type RlpBlob = Vec<u8>;
/// Merkle proofs are encoded using an RLP blob for each node in the path.
pub type RlpMerkleProof = Vec<RlpBlob>;
#[allow(unused)] // TODO: Should be used soon.
pub struct TransactionData {

View File

@ -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<F: Field> GenerationState<F> {
/// 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
}

View File

@ -68,7 +68,7 @@ pub struct LogicStark<F, const D: usize> {
pub f: PhantomData<F>,
}
#[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<F: RichField, const D: usize> LogicStark<F, D> {
pub(crate) fn generate_trace(&self, operations: Vec<Operation>) -> Vec<PolynomialValues<F>> {
let len = operations.len();