This commit is contained in:
Daniel Lubarov 2022-12-02 14:49:32 -08:00
parent 1f92d73177
commit 7293054062
5 changed files with 54 additions and 42 deletions

View File

@ -77,6 +77,7 @@ impl TernaryOperator {
}
#[derive(Debug)]
#[allow(unused)] // TODO: Should be used soon.
pub(crate) enum Operation {
BinaryOperation {
operator: BinaryOperator,

View File

@ -136,26 +136,27 @@ impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for CpuStark<F, D
fn eval_packed_generic<FE, P, const D2: usize>(
&self,
vars: StarkEvaluationVars<FE, P, { Self::COLUMNS }>,
yield_constr: &mut ConstraintConsumer<P>,
_yield_constr: &mut ConstraintConsumer<P>,
) where
FE: FieldExtension<D2, BaseField = F>,
P: PackedField<Scalar = FE>,
{
// TODO: Some failing constraints temporarily disabled.
// let local_values = vars.local_values.borrow();
// let next_values = vars.next_values.borrow();
// bootstrap_kernel::eval_bootstrap_kernel(vars, yield_constr);
// control_flow::eval_packed_generic(local_values, next_values, yield_constr);
// decode::eval_packed_generic(local_values, yield_constr);
// dup_swap::eval_packed(local_values, yield_constr);
// jumps::eval_packed(local_values, next_values, yield_constr);
// membus::eval_packed(local_values, yield_constr);
// modfp254::eval_packed(local_values, yield_constr);
// shift::eval_packed(local_values, yield_constr);
// simple_logic::eval_packed(local_values, yield_constr);
// stack::eval_packed(local_values, yield_constr);
// stack_bounds::eval_packed(local_values, yield_constr);
// syscalls::eval_packed(local_values, next_values, yield_constr);
let local_values = vars.local_values.borrow();
let next_values = vars.next_values.borrow();
// TODO: Some failing constraints temporarily disabled by using this dummy consumer.
let mut dummy_yield_constr = ConstraintConsumer::new(vec![], P::ZEROS, P::ZEROS, P::ZEROS);
bootstrap_kernel::eval_bootstrap_kernel(vars, &mut dummy_yield_constr);
control_flow::eval_packed_generic(local_values, next_values, &mut dummy_yield_constr);
decode::eval_packed_generic(local_values, &mut dummy_yield_constr);
dup_swap::eval_packed(local_values, &mut dummy_yield_constr);
jumps::eval_packed(local_values, next_values, &mut dummy_yield_constr);
membus::eval_packed(local_values, &mut dummy_yield_constr);
modfp254::eval_packed(local_values, &mut dummy_yield_constr);
shift::eval_packed(local_values, &mut dummy_yield_constr);
simple_logic::eval_packed(local_values, &mut dummy_yield_constr);
stack::eval_packed(local_values, &mut dummy_yield_constr);
stack_bounds::eval_packed(local_values, &mut dummy_yield_constr);
syscalls::eval_packed(local_values, next_values, &mut dummy_yield_constr);
}
fn eval_ext_circuit(

View File

@ -5,6 +5,7 @@ use ethereum_types::{Address, BigEndianHash, H256};
use plonky2::field::extension::Extendable;
use plonky2::field::polynomial::PolynomialValues;
use plonky2::hash::hash_types::RichField;
use plonky2::timed;
use plonky2::util::timing::TimingTree;
use serde::{Deserialize, Serialize};
use GlobalMetadata::{
@ -71,25 +72,7 @@ pub(crate) fn generate_traces<F: RichField + Extendable<D>, const D: usize>(
generate_bootstrap_kernel::<F>(&mut state);
let halt_pc0 = KERNEL.global_labels["halt_pc0"];
let halt_pc1 = KERNEL.global_labels["halt_pc1"];
let mut already_in_halt_loop = false;
loop {
// If we've reached the kernel's halt routine, and our trace length is a power of 2, stop.
let pc = state.registers.program_counter;
let in_halt_loop = pc == halt_pc0 || pc == halt_pc1;
if in_halt_loop && !already_in_halt_loop {
log::info!("CPU halted after {} cycles", state.traces.clock());
}
already_in_halt_loop |= in_halt_loop;
if already_in_halt_loop && state.traces.clock().is_power_of_two() {
log::info!("CPU trace padded to {} cycles", state.traces.clock());
break;
}
transition(&mut state);
}
timed!(timing, "simulate CPU", simulate_cpu(&mut state));
let read_metadata = |field| {
state.memory.get(MemoryAddress::new(
@ -116,8 +99,32 @@ pub(crate) fn generate_traces<F: RichField + Extendable<D>, const D: usize>(
block_metadata: inputs.block_metadata,
};
(
state.traces.to_tables(all_stark, config, timing),
public_values,
)
let tables = timed!(
timing,
"convert trace data to tables",
state.traces.to_tables(all_stark, config, timing)
);
(tables, public_values)
}
fn simulate_cpu<F: RichField + Extendable<D>, const D: usize>(state: &mut GenerationState<F>) {
let halt_pc0 = KERNEL.global_labels["halt_pc0"];
let halt_pc1 = KERNEL.global_labels["halt_pc1"];
let mut already_in_halt_loop = false;
loop {
// If we've reached the kernel's halt routine, and our trace length is a power of 2, stop.
let pc = state.registers.program_counter;
let in_halt_loop = pc == halt_pc0 || pc == halt_pc1;
if in_halt_loop && !already_in_halt_loop {
log::info!("CPU halted after {} cycles", state.traces.clock());
}
already_in_halt_loop |= in_halt_loop;
if already_in_halt_loop && state.traces.clock().is_power_of_two() {
log::info!("CPU trace padded to {} cycles", state.traces.clock());
break;
}
transition(state);
}
}

View File

@ -121,11 +121,11 @@ impl<T: Copy> Traces<T> {
let Traces {
cpu,
logic_ops,
arithmetic,
arithmetic: _, // TODO
memory_ops,
keccak_inputs,
keccak_memory_inputs,
keccak_sponge_ops,
keccak_sponge_ops: _, // TODO
} = self;
let cpu_rows = cpu.into_iter().map(|x| x.into()).collect();

View File

@ -55,7 +55,10 @@ fn test_empty_txn_list() -> anyhow::Result<()> {
block_metadata,
};
let proof = prove::<F, C, D>(&all_stark, &config, inputs, &mut TimingTree::default())?;
let mut timing = TimingTree::new("prove", log::Level::Debug);
let proof = prove::<F, C, D>(&all_stark, &config, inputs, &mut timing)?;
timing.print();
assert_eq!(
proof.public_values.trie_roots_before.state_root,
state_trie_root