Skip to content

Commit

Permalink
Add checkpoint root
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare committed Aug 22, 2024
1 parent 798931b commit be8d20a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion evm_arithmetization/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ pub struct FinalPublicValues {
pub state_trie_root_before: H256,
/// State trie root after the execution of this global state transition.
pub state_trie_root_after: H256,
/// The state trie digest of the checkpoint block.
pub checkpoint_state_trie_root: H256,
}

impl FinalPublicValues {
Expand All @@ -135,10 +137,13 @@ impl FinalPublicValues {
let state_trie_root_before = get_h256(&pis[offset..offset + TARGET_HASH_SIZE]);
offset += TARGET_HASH_SIZE;
let state_trie_root_after = get_h256(&pis[offset..offset + TARGET_HASH_SIZE]);
offset += TARGET_HASH_SIZE;
let checkpoint_state_trie_root = get_h256(&pis[offset..offset + TARGET_HASH_SIZE]);

Self {
state_trie_root_before,
state_trie_root_after,
checkpoint_state_trie_root,
}
}
}
Expand All @@ -148,6 +153,7 @@ impl From<PublicValues> for FinalPublicValues {
Self {
state_trie_root_before: value.trie_roots_before.state_root,
state_trie_root_after: value.trie_roots_after.state_root,
checkpoint_state_trie_root: value.extra_block_data.checkpoint_state_trie_root,
}
}
}
Expand All @@ -161,15 +167,18 @@ pub struct FinalPublicValuesTarget {
pub state_trie_root_before: [Target; TARGET_HASH_SIZE],
/// State trie root after the execution of this global state transition.
pub state_trie_root_after: [Target; TARGET_HASH_SIZE],
/// The state trie digest of the checkpoint block.
pub checkpoint_state_trie_root: [Target; TARGET_HASH_SIZE],
}

impl FinalPublicValuesTarget {
pub(crate) const SIZE: usize = TARGET_HASH_SIZE * 2;
pub(crate) const SIZE: usize = TARGET_HASH_SIZE * 3;

/// Serializes public value targets.
pub(crate) fn to_buffer(&self, buffer: &mut Vec<u8>) -> IoResult<()> {
buffer.write_target_array(&self.state_trie_root_before)?;
buffer.write_target_array(&self.state_trie_root_after)?;
buffer.write_target_array(&self.checkpoint_state_trie_root)?;

Ok(())
}
Expand All @@ -178,10 +187,12 @@ impl FinalPublicValuesTarget {
pub(crate) fn from_buffer(buffer: &mut Buffer) -> IoResult<Self> {
let state_trie_root_before = buffer.read_target_array()?;
let state_trie_root_after = buffer.read_target_array()?;
let checkpoint_state_trie_root = buffer.read_target_array()?;

Ok(Self {
state_trie_root_before,
state_trie_root_after,
checkpoint_state_trie_root,
})
}

Expand All @@ -201,6 +212,10 @@ impl FinalPublicValuesTarget {
self.state_trie_root_after[i],
pv1.trie_roots_after.state_root[i],
);
builder.connect(
self.checkpoint_state_trie_root[i],
pv1.extra_block_data.checkpoint_state_trie_root[i],
);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions evm_arithmetization/src/recursive_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,12 @@ pub(crate) fn add_virtual_final_public_values_public_input<
) -> FinalPublicValuesTarget {
let state_trie_root_before = builder.add_virtual_public_input_arr();
let state_trie_root_after = builder.add_virtual_public_input_arr();
let checkpoint_state_trie_root = builder.add_virtual_public_input_arr();

FinalPublicValuesTarget {
state_trie_root_before,
state_trie_root_after,
checkpoint_state_trie_root,
}
}

Expand Down

0 comments on commit be8d20a

Please sign in to comment.