mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-11 02:03:07 +00:00
stubs
This commit is contained in:
parent
ea0e37480d
commit
b6326c56b2
@ -1,8 +1,8 @@
|
||||
use std::ops::Mul;
|
||||
use std::str::FromStr;
|
||||
|
||||
use ethereum_types::{U256, U512};
|
||||
use num::BigUint;
|
||||
use ethereum_types::U256;
|
||||
|
||||
use crate::util::{addmod, mulmod, submod};
|
||||
|
||||
mod add;
|
||||
mod compare;
|
||||
|
||||
@ -42,144 +42,6 @@ impl<F: Field> GenerationState<F> {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove dead code below.
|
||||
|
||||
// /// 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 {
|
||||
// self.logic_op(logic::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 {
|
||||
// self.logic_op(logic::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 {
|
||||
// self.logic_op(logic::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: logic::Op, input0: U256, input1: U256) -> U256 {
|
||||
// let operation = logic::Operation::new(op, input0, input1);
|
||||
// let result = operation.result;
|
||||
// self.logic_ops.push(operation);
|
||||
// result
|
||||
// }
|
||||
|
||||
// /// Like `get_mem_cpu`, but reads from the current context specifically.
|
||||
// #[allow(unused)] // TODO: Should be used soon.
|
||||
// pub(crate) fn get_mem_cpu_current(
|
||||
// &mut self,
|
||||
// channel_index: usize,
|
||||
// segment: Segment,
|
||||
// virt: usize,
|
||||
// ) -> U256 {
|
||||
// let context = self.current_context;
|
||||
// self.get_mem_cpu(channel_index, context, segment, virt)
|
||||
// }
|
||||
|
||||
// /// Simulates the CPU reading some memory through the given channel. Besides logging the memory
|
||||
// /// operation, this also generates the associated registers in the current CPU row.
|
||||
// pub(crate) fn get_mem_cpu(
|
||||
// &mut self,
|
||||
// channel_index: usize,
|
||||
// context: usize,
|
||||
// segment: Segment,
|
||||
// virt: usize,
|
||||
// ) -> U256 {
|
||||
// let timestamp = self.cpu_rows.len() * NUM_CHANNELS + channel_index;
|
||||
// let value = self.get_mem(context, segment, virt, timestamp);
|
||||
//
|
||||
// let channel = &mut self.current_cpu_row.mem_channels[channel_index];
|
||||
// channel.used = F::ONE;
|
||||
// channel.is_read = F::ONE;
|
||||
// channel.addr_context = F::from_canonical_usize(context);
|
||||
// channel.addr_segment = F::from_canonical_usize(segment as usize);
|
||||
// channel.addr_virtual = F::from_canonical_usize(virt);
|
||||
// channel.value = u256_limbs(value);
|
||||
//
|
||||
// value
|
||||
// }
|
||||
|
||||
// /// Read some memory, and log the operation.
|
||||
// pub(crate) fn get_mem(
|
||||
// &mut self,
|
||||
// context: usize,
|
||||
// segment: Segment,
|
||||
// virt: usize,
|
||||
// timestamp: usize,
|
||||
// ) -> U256 {
|
||||
// let value = self.memory.contexts[context].segments[segment as usize].get(virt);
|
||||
// self.memory.log.push(MemoryOp {
|
||||
// filter: true,
|
||||
// timestamp,
|
||||
// is_read: true,
|
||||
// context,
|
||||
// segment,
|
||||
// virt,
|
||||
// value,
|
||||
// });
|
||||
// value
|
||||
// }
|
||||
|
||||
// /// Write some memory within the current execution context, and log the operation.
|
||||
// pub(crate) fn set_mem_cpu_current(
|
||||
// &mut self,
|
||||
// channel_index: usize,
|
||||
// segment: Segment,
|
||||
// virt: usize,
|
||||
// value: U256,
|
||||
// ) {
|
||||
// let context = self.current_context;
|
||||
// self.set_mem_cpu(channel_index, context, segment, virt, value);
|
||||
// }
|
||||
|
||||
// /// Write some memory, and log the operation.
|
||||
// pub(crate) fn set_mem_cpu(
|
||||
// &mut self,
|
||||
// channel_index: usize,
|
||||
// context: usize,
|
||||
// segment: Segment,
|
||||
// virt: usize,
|
||||
// value: U256,
|
||||
// ) {
|
||||
// let timestamp = self.cpu_rows.len() * NUM_CHANNELS + channel_index;
|
||||
// self.set_mem(context, segment, virt, value, timestamp);
|
||||
//
|
||||
// let channel = &mut self.current_cpu_row.mem_channels[channel_index];
|
||||
// channel.used = F::ONE;
|
||||
// channel.is_read = F::ZERO; // For clarity; should already be 0.
|
||||
// channel.addr_context = F::from_canonical_usize(context);
|
||||
// channel.addr_segment = F::from_canonical_usize(segment as usize);
|
||||
// channel.addr_virtual = F::from_canonical_usize(virt);
|
||||
// channel.value = u256_limbs(value);
|
||||
// }
|
||||
|
||||
// /// Write some memory, and log the operation.
|
||||
// pub(crate) fn set_mem(
|
||||
// &mut self,
|
||||
// context: usize,
|
||||
// segment: Segment,
|
||||
// virt: usize,
|
||||
// value: U256,
|
||||
// timestamp: usize,
|
||||
// ) {
|
||||
// self.memory.log.push(MemoryOp {
|
||||
// filter: true,
|
||||
// timestamp,
|
||||
// is_read: false,
|
||||
// context,
|
||||
// segment,
|
||||
// virt,
|
||||
// value,
|
||||
// });
|
||||
// self.memory.contexts[context].segments[segment as usize].set(virt, value)
|
||||
// }
|
||||
|
||||
// /// Evaluate the Keccak-f permutation in-place on some data in memory, and record the operations
|
||||
// /// for the purpose of witness generation.
|
||||
// #[allow(unused)] // TODO: Should be used soon.
|
||||
@ -227,10 +89,4 @@ impl<F: Field> GenerationState<F> {
|
||||
// keccakf(&mut input);
|
||||
// input
|
||||
// }
|
||||
|
||||
// pub(crate) fn commit_cpu_row(&mut self) {
|
||||
// let mut swapped_row = [F::ZERO; NUM_CPU_COLUMNS].into();
|
||||
// mem::swap(&mut self.current_cpu_row, &mut swapped_row);
|
||||
// self.cpu_rows.push(swapped_row.into());
|
||||
// }
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ pub(crate) unsafe fn transmute_no_compile_time_size_checks<T, U>(value: T) -> U
|
||||
transmute_copy(&value)
|
||||
}
|
||||
|
||||
fn addmod(x: U256, y: U256, m: U256) -> U256 {
|
||||
pub(crate) fn addmod(x: U256, y: U256, m: U256) -> U256 {
|
||||
if m.is_zero() {
|
||||
return m;
|
||||
}
|
||||
@ -110,7 +110,7 @@ fn addmod(x: U256, y: U256, m: U256) -> U256 {
|
||||
biguint_to_u256((x + y) % m)
|
||||
}
|
||||
|
||||
fn mulmod(x: U256, y: U256, m: U256) -> U256 {
|
||||
pub(crate) fn mulmod(x: U256, y: U256, m: U256) -> U256 {
|
||||
if m.is_zero() {
|
||||
return m;
|
||||
}
|
||||
@ -120,7 +120,7 @@ fn mulmod(x: U256, y: U256, m: U256) -> U256 {
|
||||
biguint_to_u256(x * y % m)
|
||||
}
|
||||
|
||||
fn submod(x: U256, y: U256, m: U256) -> U256 {
|
||||
pub(crate) fn submod(x: U256, y: U256, m: U256) -> U256 {
|
||||
if m.is_zero() {
|
||||
return m;
|
||||
}
|
||||
@ -133,18 +133,18 @@ fn submod(x: U256, y: U256, m: U256) -> U256 {
|
||||
biguint_to_u256((x - y) % m)
|
||||
}
|
||||
|
||||
fn u256_to_biguint(x: U256) -> BigUint {
|
||||
pub(crate) fn u256_to_biguint(x: U256) -> BigUint {
|
||||
let mut bytes = [0u8; 32];
|
||||
x.to_little_endian(&mut bytes);
|
||||
BigUint::from_bytes_le(&bytes)
|
||||
}
|
||||
|
||||
fn biguint_to_u256(x: BigUint) -> U256 {
|
||||
pub(crate) fn biguint_to_u256(x: BigUint) -> U256 {
|
||||
let bytes = x.to_bytes_le();
|
||||
U256::from_little_endian(&bytes)
|
||||
}
|
||||
|
||||
fn u256_saturating_cast_usize(x: U256) -> usize {
|
||||
pub(crate) fn u256_saturating_cast_usize(x: U256) -> usize {
|
||||
if x > usize::MAX.into() {
|
||||
usize::MAX
|
||||
} else {
|
||||
|
||||
@ -7,6 +7,7 @@ use crate::cpu::kernel::aggregator::KERNEL;
|
||||
use crate::cpu::membus::NUM_GP_CHANNELS;
|
||||
use crate::cpu::simple_logic::eq_iszero::generate_pinv_diff;
|
||||
use crate::memory::segments::Segment;
|
||||
use crate::util::u256_saturating_cast_usize;
|
||||
use crate::witness::errors::ProgramError;
|
||||
use crate::witness::memory::{MemoryAddress, MemoryState};
|
||||
use crate::witness::state::RegistersState;
|
||||
@ -110,6 +111,24 @@ pub(crate) fn generate_ternary_arithmetic_op<F: Field>(
|
||||
Ok(registers_state)
|
||||
}
|
||||
|
||||
pub(crate) fn generate_prover_input<F: Field>(
|
||||
mut registers_state: RegistersState,
|
||||
memory_state: &MemoryState,
|
||||
traces: &mut Traces<F>,
|
||||
mut row: CpuColumnsView<F>,
|
||||
) -> Result<RegistersState, ProgramError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub(crate) fn generate_pop<F: Field>(
|
||||
mut registers_state: RegistersState,
|
||||
memory_state: &MemoryState,
|
||||
traces: &mut Traces<F>,
|
||||
mut row: CpuColumnsView<F>,
|
||||
) -> Result<RegistersState, ProgramError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub(crate) fn generate_jump<F: Field>(
|
||||
mut registers_state: RegistersState,
|
||||
memory_state: &MemoryState,
|
||||
|
||||
@ -214,8 +214,10 @@ fn perform_op<F: Field>(
|
||||
generate_ternary_arithmetic_op(op, registers_state, memory_state, traces, row)?
|
||||
}
|
||||
Operation::KeccakGeneral => todo!(),
|
||||
Operation::ProverInput => todo!(),
|
||||
Operation::Pop => todo!(),
|
||||
Operation::ProverInput => {
|
||||
generate_prover_input(registers_state, memory_state, traces, row)?
|
||||
}
|
||||
Operation::Pop => generate_pop(registers_state, memory_state, traces, row)?,
|
||||
Operation::Jump => generate_jump(registers_state, memory_state, traces, row)?,
|
||||
Operation::Jumpi => generate_jumpi(registers_state, memory_state, traces, row)?,
|
||||
Operation::Pc => todo!(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user