Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: more boiler plate code for merge rollup #3182

Merged
merged 10 commits into from
Nov 2, 2023
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
struct AppendOnlyTreeSnapshot {
root : Field,
next_available_leaf_index : u32
}

impl AppendOnlyTreeSnapshot{
pub fn eq(self, other : AppendOnlyTreeSnapshot) -> bool {
(self.root == other.root) & (self.next_available_leaf_index == other.next_available_leaf_index)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ struct BaseOrMergeRollupPublicInputs {

start_public_data_tree_root : Field,
end_public_data_tree_root : Field,
// // We hash public inputs to make them constant-sized (to then be unpacked on-chain)

// We hash public inputs to make them constant-sized (to then be unpacked on-chain)
// TODO(Kev): Want to make this a U128, but Re-export bug 3384

// We hash public inputs to make them constant-sized (to then be unpacked on-chain)
calldata_hash : [Field; 2],
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,15 @@ struct ConstantRollupData {
merge_rollup_vk_hash : Field,

global_variables : GlobalVariables,
}

impl ConstantRollupData {
pub fn eq(self, other : ConstantRollupData) -> bool {
self.start_historic_blocks_tree_roots_snapshot.eq(other.start_historic_blocks_tree_roots_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) &
(self.base_rollup_vk_hash == other.base_rollup_vk_hash) &
(self.merge_rollup_vk_hash == other.merge_rollup_vk_hash)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ impl GlobalVariables {
)
}

pub fn eq(self, other : GlobalVariables) -> bool {
(self.chain_id == other.chain_id) &
(self.version == other.version) &
(self.block_number == other.block_number) &
(self.timestamp == other.timestamp)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use crate::abis::base_or_merge_rollup_public_inputs::{BaseOrMergeRollupPublicInputs, AggregationObject};
use dep::private_kernel_lib::hash::accumulate_sha256;
use dep::private_kernel_lib::utils::uint128::U128;
use dep::aztec::constants_gen::NUM_FIELDS_PER_SHA256;
use crate::abis::previous_rollup_data::PreviousRollupData;

/**
* Create an aggregation object for the proofs that are provided
* - We add points P0 for each of our proofs
* - We add points P1 for each of our proofs
* - We concat our public inputs
* TODO(Kev): This seems similar to the aggregate_proof method in the private-kernel-lib
*/
pub fn aggregate_proofs(left : BaseOrMergeRollupPublicInputs, right : BaseOrMergeRollupPublicInputs) -> AggregationObject {
// TODO: Similar to cpp code this does not do anything.
left.end_aggregation_object
}

/**
* Asserts that the rollup types are the same.
* Either both merge or both base
*/
pub fn assert_both_input_proofs_of_same_rollup_type(left : BaseOrMergeRollupPublicInputs, right : BaseOrMergeRollupPublicInputs)
{
assert(left.rollup_type == right.rollup_type, "input proofs are of different rollup types");
}

/**
* Asserts that the rollup subtree heights are the same and returns the height
* Returns the height of the rollup subtrees
*/
pub fn assert_both_input_proofs_of_same_height_and_return(left : BaseOrMergeRollupPublicInputs, right : BaseOrMergeRollupPublicInputs) -> Field{
assert(left.rollup_subtree_height == right.rollup_subtree_height, "input proofs are of different rollup heights");
left.rollup_subtree_height
}

/**
* Asserts that the constants used in the left and right child are identical
*
*/
pub fn assert_equal_constants(left : BaseOrMergeRollupPublicInputs, right : BaseOrMergeRollupPublicInputs) {
assert(left.constants.eq(right.constants), "input proofs have different constants");
}

// asserts that the end snapshot of previous_rollup 0 equals the start snapshot of previous_rollup 1 (i.e. ensure they
// follow on from one-another). Ensures that right uses the tres that was updated by left.
pub fn assert_prev_rollups_follow_on_from_each_other(left : BaseOrMergeRollupPublicInputs, right : BaseOrMergeRollupPublicInputs)
{
assert(left.end_note_hash_tree_snapshot.eq(right.start_note_hash_tree_snapshot), "input proofs have different note hash tree snapshots");
assert(left.end_nullifier_tree_snapshot.eq(right.start_nullifier_tree_snapshot),"input proofs have different nullifier tree snapshots");
assert(left.end_contract_tree_snapshot.eq(right.start_contract_tree_snapshot), "input proofs have different contract tree snapshots");
assert(left.end_public_data_tree_root == right.start_public_data_tree_root, "input proofs have different public data tree snapshots");
}

/**
* @brief From two previous rollup data, compute a single calldata hash
*
* @param previous_rollup_data
* @return calldata hash stored in 2 fields
*/
pub fn compute_calldata_hash(previous_rollup_data : [PreviousRollupData ; 2]) -> [Field; NUM_FIELDS_PER_SHA256]{
accumulate_sha256([
U128::from_field(previous_rollup_data[0].base_or_merge_rollup_public_inputs.calldata_hash[0]),
U128::from_field(previous_rollup_data[0].base_or_merge_rollup_public_inputs.calldata_hash[1]),
U128::from_field(previous_rollup_data[1].base_or_merge_rollup_public_inputs.calldata_hash[0]),
U128::from_field(previous_rollup_data[1].base_or_merge_rollup_public_inputs.calldata_hash[1])
])
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ mod base;
mod merge;

// Root rollup
mod root;
mod root;

mod components;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::abis::previous_rollup_data::PreviousRollupData;
use crate::abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs;
use crate::abis::base_or_merge_rollup_public_inputs::{BaseOrMergeRollupPublicInputs, MERGE_ROLLUP_TYPE};
use crate::components;

struct MergeRollupInputs{
// TODO(Kev): Why is this 2?
Expand All @@ -8,7 +9,41 @@ struct MergeRollupInputs{

impl MergeRollupInputs {
pub fn merge_rollup_circuit(self) -> BaseOrMergeRollupPublicInputs {
let zeroed = dep::std::unsafe::zeroed();
zeroed

// TODO(Lasse): Verify the previous rollup proofs
// TODO(Lasse): Check both previous rollup vks (in previous_rollup_data) against the permitted set of kernel vks.
// we don't have a set of permitted kernel vks yet.

let left = self.previous_rollup_data[0].base_or_merge_rollup_public_inputs;
let right = self.previous_rollup_data[1].base_or_merge_rollup_public_inputs;

// check that both input proofs are either both "BASE" or "MERGE" and not a mix!
// this prevents having wonky commitment, nullifier and contract subtrees.
let aggregation_object = components::aggregate_proofs(left, right);
components::assert_both_input_proofs_of_same_rollup_type(left, right);
let current_height = components::assert_both_input_proofs_of_same_height_and_return(left, right);
components::assert_equal_constants(left, right);
components::assert_prev_rollups_follow_on_from_each_other(left, right);

// compute calldata hash:
let new_calldata_hash = components::compute_calldata_hash(self.previous_rollup_data);

let public_inputs = BaseOrMergeRollupPublicInputs {
rollup_type : MERGE_ROLLUP_TYPE,
rollup_subtree_height : current_height + 1,
end_aggregation_object : aggregation_object,
constants : left.constants,
start_note_hash_tree_snapshot : left.start_note_hash_tree_snapshot,
end_note_hash_tree_snapshot : right.end_note_hash_tree_snapshot,
start_nullifier_tree_snapshot : left.start_nullifier_tree_snapshot,
end_nullifier_tree_snapshot : right.end_nullifier_tree_snapshot,
start_contract_tree_snapshot : left.start_contract_tree_snapshot,
end_contract_tree_snapshot : right.end_contract_tree_snapshot,
start_public_data_tree_root : left.start_public_data_tree_root,
end_public_data_tree_root : right.end_public_data_tree_root,
calldata_hash : new_calldata_hash,
};

public_inputs
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.