Skip to content

Commit

Permalink
blocks_tree_roots --> blocks_tree
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Nov 30, 2023
1 parent c06ddf2 commit 8c9ae59
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ template <typename NCT> struct ConstantRollupData {
using fr = typename NCT::fr;

// The very latest roots as at the very beginning of the entire rollup:
AppendOnlyTreeSnapshot<NCT> start_blocks_tree_roots_snapshot{};
AppendOnlyTreeSnapshot<NCT> start_blocks_tree_snapshot{};

// Some members of this struct tbd:
fr private_kernel_vk_tree_root = 0;
Expand All @@ -21,7 +21,7 @@ template <typename NCT> struct ConstantRollupData {

GlobalVariables<NCT> global_variables{};

MSGPACK_FIELDS(start_blocks_tree_roots_snapshot,
MSGPACK_FIELDS(start_blocks_tree_snapshot,
private_kernel_vk_tree_root,
public_kernel_vk_tree_root,
base_rollup_vk_hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void perform_blocks_tree_membership_checks(DummyBuilder& builder, BaseRollupInpu
{
// For each of the historical_note_hash_tree_membership_checks, we need to do an inclusion proof
// against the historical root provided in the rollup constants
auto historical_root = baseRollupInputs.constants.start_blocks_tree_roots_snapshot.root;
auto historical_root = baseRollupInputs.constants.start_blocks_tree_snapshot.root;

for (size_t i = 0; i < 2; i++) {
// Rebuild the block hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ BaseRollupInputs base_rollup_inputs_from_kernels(std::array<KernelData, 2> kerne
public_data_tree.root());
blocks_tree.update_element(0, block_hash);

ConstantRollupData const constantRollupData = { .start_blocks_tree_roots_snapshot = {
ConstantRollupData const constantRollupData = { .start_blocks_tree_snapshot = {
.root = blocks_tree.root(),
.next_available_leaf_index = 1,
} };
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/structs/rollup/base_rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class ConstantRollupData {
/**
* Snapshot of the historical blocks roots tree at the start of the rollup.
*/
public startBlocksTreeRootsSnapshot: AppendOnlyTreeSnapshot,
public startBlocksTreeSnapshot: AppendOnlyTreeSnapshot,

/**
* Root of the private kernel verification key tree.
Expand Down Expand Up @@ -100,7 +100,7 @@ export class ConstantRollupData {

static getFields(fields: FieldsOf<ConstantRollupData>) {
return [
fields.startBlocksTreeRootsSnapshot,
fields.startBlocksTreeSnapshot,
fields.privateKernelVkTreeRoot,
fields.publicKernelVkTreeRoot,
fields.baseRollupVkHash,
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/tests/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ export function makeConstantBaseRollupData(
globalVariables: GlobalVariables | undefined = undefined,
): ConstantRollupData {
return ConstantRollupData.from({
startBlocksTreeRootsSnapshot: makeAppendOnlyTreeSnapshot(seed + 0x300),
startBlocksTreeSnapshot: makeAppendOnlyTreeSnapshot(seed + 0x300),
privateKernelVkTreeRoot: fr(seed + 0x401),
publicKernelVkTreeRoot: fr(seed + 0x402),
baseRollupVkHash: fr(seed + 0x403),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot;

struct ConstantRollupData {
// The very latest roots as at the very beginning of the entire rollup:
start_blocks_tree_roots_snapshot : AppendOnlyTreeSnapshot,
start_blocks_tree_snapshot : AppendOnlyTreeSnapshot,

// TODO(Sean): Some members of this struct tbd
private_kernel_vk_tree_root : Field,
Expand All @@ -16,7 +16,7 @@ struct ConstantRollupData {

impl ConstantRollupData {
pub fn eq(self, other : ConstantRollupData) -> bool {
self.start_blocks_tree_roots_snapshot.eq(other.start_blocks_tree_roots_snapshot) &
self.start_blocks_tree_snapshot.eq(other.start_blocks_tree_snapshot) &
self.global_variables.eq(other.global_variables) &
(self.private_kernel_vk_tree_root == other.private_kernel_vk_tree_root) &
(self.public_kernel_vk_tree_root == other.public_kernel_vk_tree_root) &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,24 +477,26 @@ impl BaseRollupInputs {
U256::from_bytes32(sha_digest).to_u128_limbs()
}

// Check all of the provided commitments against the historical tree roots
// Check that the block header used by each kernel is a member of the blocks tree --> since the block header
// contains roots of all the trees this is sufficient to verify that the tree roots used by kernels are correct
fn perform_blocks_tree_membership_checks(self) {
// For each of the historical_note_hash_tree_membership_checks, we need to do an inclusion proof
// against the historical root provided in the rollup constants
let historical_root = self.constants.start_blocks_tree_roots_snapshot.root;
// For each of the block header (their block hashes), we need to do an inclusion proof
// against the blocks tree root from the beginning of a rollup provided in the rollup constants
let blocks_treee_root = self.constants.start_blocks_tree_snapshot.root;

for i in 0..KERNELS_PER_BASE_ROLLUP {
// Rebuild the block hash
let block_header = self.kernel_data[i].public_inputs.constants.block_header;
let previous_block_hash = block_header.block.hash();

let historical_root_witness = self.blocks_tree_root_membership_witnesses[i];
let previous_block_hash_witness = self.blocks_tree_root_membership_witnesses[i];

// Now check that the previous block hash is in the blocks tree from the beginning of the rollup
components::assert_check_membership(
previous_block_hash,
historical_root_witness.leaf_index,
historical_root_witness.sibling_path,
historical_root
previous_block_hash_witness.leaf_index,
previous_block_hash_witness.sibling_path,
blocks_treee_root
);
}
}
Expand Down Expand Up @@ -758,7 +760,7 @@ mod tests {
next_available_leaf_index: start_blocks_tree.get_next_available_index() as u32,
};

self.constants.start_blocks_tree_roots_snapshot = start_blocks_tree_snapshot;
self.constants.start_blocks_tree_snapshot = start_blocks_tree_snapshot;

let mut new_public_data_reads_sibling_paths: [[Field; PUBLIC_DATA_TREE_HEIGHT]; MAX_PUBLIC_DATA_READS_PER_BASE_ROLLUP] = dep::std::unsafe::zeroed();

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/noir-protocol-circuits/src/type_conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ export function mapGlobalVariablesFromNoir(globalVariables: GlobalVariablesNoir)
*/
export function mapConstantRollupDataToNoir(constantRollupData: ConstantRollupData): ConstantRollupDataNoir {
return {
start_blocks_tree_roots_snapshot: mapAppendOnlyTreeSnapshotToNoir(constantRollupData.startBlocksTreeRootsSnapshot),
start_blocks_tree_snapshot: mapAppendOnlyTreeSnapshotToNoir(constantRollupData.startBlocksTreeSnapshot),
private_kernel_vk_tree_root: mapFieldToNoir(constantRollupData.privateKernelVkTreeRoot),
public_kernel_vk_tree_root: mapFieldToNoir(constantRollupData.publicKernelVkTreeRoot),
base_rollup_vk_hash: mapFieldToNoir(constantRollupData.baseRollupVkHash),
Expand Down Expand Up @@ -1113,7 +1113,7 @@ export function mapPublicCircuitPublicInputsToNoir(
*/
export function mapConstantRollupDataFromNoir(constantRollupData: ConstantRollupDataNoir): ConstantRollupData {
return new ConstantRollupData(
mapAppendOnlyTreeSnapshotFromNoir(constantRollupData.start_blocks_tree_roots_snapshot),
mapAppendOnlyTreeSnapshotFromNoir(constantRollupData.start_blocks_tree_snapshot),
mapFieldFromNoir(constantRollupData.private_kernel_vk_tree_root),
mapFieldFromNoir(constantRollupData.public_kernel_vk_tree_root),
mapFieldFromNoir(constantRollupData.base_rollup_vk_hash),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export interface GlobalVariables {
}

export interface ConstantRollupData {
start_blocks_tree_roots_snapshot: AppendOnlyTreeSnapshot;
start_blocks_tree_snapshot: AppendOnlyTreeSnapshot;
private_kernel_vk_tree_root: Field;
public_kernel_vk_tree_root: Field;
base_rollup_vk_hash: Field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface GlobalVariables {
}

export interface ConstantRollupData {
start_blocks_tree_roots_snapshot: AppendOnlyTreeSnapshot;
start_blocks_tree_snapshot: AppendOnlyTreeSnapshot;
private_kernel_vk_tree_root: Field;
public_kernel_vk_tree_root: Field;
base_rollup_vk_hash: Field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface GlobalVariables {
}

export interface ConstantRollupData {
start_blocks_tree_roots_snapshot: AppendOnlyTreeSnapshot;
start_blocks_tree_snapshot: AppendOnlyTreeSnapshot;
private_kernel_vk_tree_root: Field;
public_kernel_vk_tree_root: Field;
base_rollup_vk_hash: Field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ export class SoloBlockBuilder implements BlockBuilder {
mergeRollupVkHash: DELETE_FR,
privateKernelVkTreeRoot: FUTURE_FR,
publicKernelVkTreeRoot: FUTURE_FR,
startBlocksTreeRootsSnapshot: await this.getTreeSnapshot(MerkleTreeId.BLOCKS_TREE),
startBlocksTreeSnapshot: await this.getTreeSnapshot(MerkleTreeId.BLOCKS_TREE),
globalVariables,
});
}
Expand Down

0 comments on commit 8c9ae59

Please sign in to comment.