mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-03 06:13:07 +00:00
Fix kernel codehash discrepancy (#1400)
This commit is contained in:
parent
5572da30d7
commit
32d009671a
@ -67,20 +67,20 @@ remaining_bytes:
|
||||
SWAP1 SUB DUP1
|
||||
// stack: num_nibbles - parity, num_nibbles - parity, U256_MAX, packed_nibbles, rlp_pos, ret_dest
|
||||
%div_const(2)
|
||||
// stack: remaining_bytes, num_nibbles - parity, U256_MAX, packed_nibbles, rlp_pos, ret_dest
|
||||
// stack: rem_bytes, num_nibbles - parity, U256_MAX, packed_nibbles, rlp_pos, ret_dest
|
||||
SWAP2 SWAP1
|
||||
// stack: num_nibbles - parity, U256_MAX, remaining_bytes, packed_nibbles, rlp_pos, ret_dest
|
||||
// stack: num_nibbles - parity, U256_MAX, rem_bytes, packed_nibbles, rlp_pos, ret_dest
|
||||
%mul_const(4)
|
||||
// stack: 4*(num_nibbles - parity), U256_MAX, remaining_bytes, packed_nibbles, rlp_pos, ret_dest
|
||||
// stack: 4*(num_nibbles - parity), U256_MAX, rem_bytes, packed_nibbles, rlp_pos, ret_dest
|
||||
PUSH 256 SUB
|
||||
// stack: 256 - 4*(num_nibbles - parity), U256_MAX, remaining_bytes, packed_nibbles, rlp_pos, ret_dest
|
||||
// stack: 256 - 4*(num_nibbles - parity), U256_MAX, rem_bytes, packed_nibbles, rlp_pos, ret_dest
|
||||
SHR
|
||||
// stack: mask, remaining_bytes, packed_nibbles, rlp_pos, ret_dest
|
||||
// stack: mask, rem_bytes, packed_nibbles, rlp_pos, ret_dest
|
||||
SWAP1 SWAP2
|
||||
AND
|
||||
%stack
|
||||
(remaining_nibbles, remaining_bytes, rlp_pos) ->
|
||||
(rlp_pos, remaining_nibbles, remaining_bytes)
|
||||
(remaining_nibbles, rem_bytes, rlp_pos) ->
|
||||
(rlp_pos, remaining_nibbles, rem_bytes)
|
||||
%mstore_unpacking_rlp
|
||||
SWAP1
|
||||
JUMP
|
||||
@ -95,9 +95,13 @@ rlp_header_medium:
|
||||
// rlp_pos += 1
|
||||
%increment
|
||||
|
||||
%stack
|
||||
(rlp_pos, num_nibbles, packed_nibbles, terminated, retdest) ->
|
||||
(rlp_pos, num_nibbles, packed_nibbles, terminated, remaining_bytes, num_nibbles, packed_nibbles, retdest)
|
||||
// stack: rlp_pos, num_nibbles, packed_nibbles, terminated, retdest
|
||||
SWAP3 DUP3 DUP3
|
||||
// stack: num_nibbles, packed_nibbles, terminated, num_nibbles, packed_nibbles, rlp_pos, retdest
|
||||
PUSH remaining_bytes
|
||||
// stack: remaining_bytes, num_nibbles, packed_nibbles, terminated, num_nibbles, packed_nibbles, rlp_pos, retdest
|
||||
SWAP4 SWAP5 SWAP6
|
||||
// stack: rlp_pos, num_nibbles, packed_nibbles, terminated, remaining_bytes, num_nibbles, packed_nibbles, retdest
|
||||
|
||||
%jump(first_byte)
|
||||
|
||||
@ -118,9 +122,12 @@ rlp_header_large:
|
||||
// rlp_pos += 2
|
||||
%add_const(2)
|
||||
|
||||
%stack
|
||||
(rlp_pos, num_nibbles, packed_nibbles, terminated, retdest) ->
|
||||
(rlp_pos, num_nibbles, packed_nibbles, terminated, remaining_bytes, num_nibbles, packed_nibbles, retdest)
|
||||
// stack: rlp_pos, num_nibbles, packed_nibbles, terminated, retdest
|
||||
SWAP3 DUP3 DUP3
|
||||
// stack: num_nibbles, packed_nibbles, terminated, num_nibbles, packed_nibbles, rlp_pos, retdest
|
||||
PUSH remaining_bytes
|
||||
// stack: remaining_bytes, num_nibbles, packed_nibbles, terminated, num_nibbles, packed_nibbles, rlp_pos, retdest
|
||||
SWAP4 SWAP5 SWAP6
|
||||
// stack: rlp_pos, num_nibbles, packed_nibbles, terminated, remaining_bytes, num_nibbles, packed_nibbles, retdest
|
||||
|
||||
%jump(first_byte)
|
||||
|
||||
|
||||
16
evm/src/cpu/kernel/tests/kernel_consistency.rs
Normal file
16
evm/src/cpu/kernel/tests/kernel_consistency.rs
Normal file
@ -0,0 +1,16 @@
|
||||
use anyhow::Result;
|
||||
use ethereum_types::U256;
|
||||
|
||||
use crate::cpu::kernel::aggregator::{combined_kernel, KERNEL};
|
||||
use crate::cpu::kernel::interpreter::Interpreter;
|
||||
use crate::memory::segments::Segment;
|
||||
|
||||
#[test]
|
||||
fn test_kernel_code_hash_consistency() -> Result<()> {
|
||||
for _ in 0..10 {
|
||||
let kernel2 = combined_kernel();
|
||||
assert_eq!(kernel2.code_hash, KERNEL.code_hash);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -10,6 +10,7 @@ mod core;
|
||||
mod ecc;
|
||||
mod exp;
|
||||
mod hash;
|
||||
mod kernel_consistency;
|
||||
mod log;
|
||||
mod mpt;
|
||||
mod packing;
|
||||
|
||||
@ -191,19 +191,6 @@ fn apply_metadata_and_tries_memops<F: RichField + Extendable<D>, const D: usize>
|
||||
state.traces.memory_ops.extend(ops);
|
||||
}
|
||||
|
||||
fn initialize_kernel_code<F: RichField + Extendable<D>, const D: usize>(
|
||||
state: &mut GenerationState<F>,
|
||||
) {
|
||||
for (i, &byte) in enumerate(KERNEL.code.iter()) {
|
||||
let address = MemoryAddress {
|
||||
context: 0,
|
||||
segment: Segment::Code as usize,
|
||||
virt: i,
|
||||
};
|
||||
state.memory.set(address, byte.into());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_traces<F: RichField + Extendable<D>, const D: usize>(
|
||||
all_stark: &AllStark<F, D>,
|
||||
inputs: GenerationInputs,
|
||||
@ -219,8 +206,6 @@ pub fn generate_traces<F: RichField + Extendable<D>, const D: usize>(
|
||||
|
||||
apply_metadata_and_tries_memops(&mut state, &inputs);
|
||||
|
||||
initialize_kernel_code(&mut state);
|
||||
|
||||
timed!(timing, "simulate CPU", simulate_cpu(&mut state)?);
|
||||
|
||||
assert!(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user