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

refactor(blocks tree): remove historic roots trees #1355

Merged
merged 72 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
8553fa0
feat: add blocks tree data to l2 block
Maddiaa0 Jul 25, 2023
4580093
feat: use constants to represent offsets
Maddiaa0 Jul 25, 2023
1991a57
chore: forge fmt
Maddiaa0 Jul 25, 2023
e0808b8
fix: linter
Maddiaa0 Jul 25, 2023
98692dd
fix: stub circuit output for the meantime
Maddiaa0 Jul 26, 2023
2942f95
feat: add naive block hash calculations to root rollup circuit
Maddiaa0 Jul 26, 2023
e8f9fbc
Merge branch 'master' into md/blocks-tree-circuits
Maddiaa0 Jul 27, 2023
376e71a
temp
Maddiaa0 Jul 27, 2023
9403830
Merge branch 'master' into md/blocks-tree-circuits
Maddiaa0 Jul 31, 2023
7520217
fix: update snapshot
Maddiaa0 Jul 31, 2023
3c9422c
feat: include block hash calcs in sequencer
Maddiaa0 Jul 31, 2023
de68edd
fix: make calculate block hash a cbind
Maddiaa0 Jul 31, 2023
520b9a6
Merge branch 'master' into md/blocks-tree-circuits
Maddiaa0 Jul 31, 2023
55fbd5f
feat: add block tree checking in ts
Maddiaa0 Aug 1, 2023
f1d9fc7
clean
Maddiaa0 Aug 1, 2023
3ae5a4d
lint
Maddiaa0 Aug 1, 2023
011a150
review comments
Maddiaa0 Aug 1, 2023
830721f
Merge branch 'master' into md/blocks-tree-circuits
Maddiaa0 Aug 1, 2023
035c41f
fix: include generator indices
Maddiaa0 Aug 1, 2023
5340a79
lint
Maddiaa0 Aug 1, 2023
d9bda7b
update snapshot
Maddiaa0 Aug 1, 2023
455058a
fix: remove references to block num in factories
Maddiaa0 Aug 2, 2023
515bb60
Merge branch 'master' into md/blocks-tree-circuits
Maddiaa0 Aug 2, 2023
03cc42e
feat: read trees against historic block root
Maddiaa0 Aug 1, 2023
3670fac
feat: remove other checks from the base rollup
Maddiaa0 Aug 1, 2023
e0129f8
feat: update ts and snapshot
Maddiaa0 Aug 1, 2023
acd2413
feat: remove old tree checks in base rollup
Maddiaa0 Aug 1, 2023
2bc675f
fix
Maddiaa0 Aug 2, 2023
1b8be8c
fix: get previous globals in transactions
Maddiaa0 Aug 2, 2023
c464ec2
feat: remove old historic trees from the smart contract
Maddiaa0 Aug 2, 2023
1357179
fix: update decoder test
Maddiaa0 Aug 2, 2023
2167ae9
fix: lint
Maddiaa0 Aug 2, 2023
727fec6
Merge branch 'master' into md/blocks-tree-use-blocks-tree
Maddiaa0 Aug 2, 2023
9ee98d5
feat: I have become death, destroyer of worlds
Maddiaa0 Aug 2, 2023
2885d55
i have become lint, hater of self
Maddiaa0 Aug 2, 2023
ce67250
ive only gone n done it again
Maddiaa0 Aug 2, 2023
0195792
fix: update snappyshootys
Maddiaa0 Aug 2, 2023
3a268e2
Merge branch 'master' into md/blocks-tree-use-blocks-tree
Maddiaa0 Aug 2, 2023
9f66593
tune
Maddiaa0 Aug 3, 2023
468bac0
clean: fix cbind naming, remove unused constants
Maddiaa0 Aug 3, 2023
99adca0
Merge branch 'master' into md/blocks-tree-use-blocks-tree
Maddiaa0 Aug 3, 2023
77ec737
post merge constants gen
Maddiaa0 Aug 3, 2023
e769526
fix: cleanup pass 1
Maddiaa0 Aug 4, 2023
acf17be
refactor: historic roots -> block hash data
Maddiaa0 Aug 4, 2023
f072420
refactor: update snapshots
Maddiaa0 Aug 4, 2023
956bfdd
refactor: trees
Maddiaa0 Aug 4, 2023
96ba6de
refactor: block hash data
Maddiaa0 Aug 4, 2023
4f124e3
hmmm, lint so good... gang gang, hmmm, lint so good
Maddiaa0 Aug 4, 2023
8edb2d9
Merge branch 'master' into md/blocks-tree-use-blocks-tree
Maddiaa0 Aug 4, 2023
85b6b01
minor fix
Maddiaa0 Aug 4, 2023
751d6df
we snapshot, we are a good boy mama
Maddiaa0 Aug 4, 2023
ce5a6be
lint so good, hmmm, lint so gooood
Maddiaa0 Aug 4, 2023
b3fcccc
refactor: processor && fix public tests
Maddiaa0 Aug 4, 2023
f065629
fix: serialise
Maddiaa0 Aug 4, 2023
8034c95
fix: missed test updates
Maddiaa0 Aug 7, 2023
f8ce11e
fix: reinstate circuits test
Maddiaa0 Aug 7, 2023
50ff634
Merge branch 'master' into md/blocks-tree-use-blocks-tree
Maddiaa0 Aug 7, 2023
cb3f80c
fix: recompile aztec js account contracts
Maddiaa0 Aug 7, 2023
a681273
refactor: rename historic block hash data and remove nested private t…
Maddiaa0 Aug 7, 2023
ae967ae
refactor: rename in ts
Maddiaa0 Aug 7, 2023
4a0f15a
cleanup
Maddiaa0 Aug 7, 2023
862a553
Merge branch 'master' into md/blocks-tree-use-blocks-tree
Maddiaa0 Aug 7, 2023
c0c5526
chore: update snapshot
Maddiaa0 Aug 7, 2023
1f102a5
minor rename
Maddiaa0 Aug 8, 2023
02d4e85
review fixes
Maddiaa0 Aug 8, 2023
8468b2e
Merge branch 'master' into md/blocks-tree-use-blocks-tree
Maddiaa0 Aug 8, 2023
deefe17
fmt
Maddiaa0 Aug 8, 2023
9210bf9
chore(fmt): formatting 2; electric boogaloo
Maddiaa0 Aug 8, 2023
5882121
Merge branch 'master' into md/blocks-tree-use-blocks-tree
Maddiaa0 Aug 8, 2023
2cfa1eb
fix: final review comments
Maddiaa0 Aug 9, 2023
f4f22e3
Merge branch 'master' into md/blocks-tree-use-blocks-tree
Maddiaa0 Aug 9, 2023
81dd1f3
merge fix
Maddiaa0 Aug 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,21 @@ CBIND(abis__silo_nullifier, aztec3::circuits::silo_nullifier<NT>);

/**
* @brief Computes the block hash from the block information.
* Globals is provided as a hash in this instance.
*/
CBIND(abis__compute_block_hash, aztec3::circuits::compute_block_hash<NT>);

/**
* @brief Computes the block hash from the block information.
* The entire globals object is provided in this instance, rather than a hash as in above.
*/
CBIND(abis__compute_block_hash_with_globals, aztec3::circuits::compute_block_hash_with_globals<NT>);

/**
* @brief Computes the hash of the global variables
*/
CBIND(abis__compute_globals_hash, aztec3::circuits::compute_globals_hash<NT>);

/**
* @brief Generates a signed tx request hash from it's pre-image
* This is a WASM-export that can be called from Typescript.
Expand Down
2 changes: 2 additions & 0 deletions circuits/cpp/src/aztec3/circuits/abis/c_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ CBIND_DECL(abis__compute_unique_commitment);
CBIND_DECL(abis__silo_commitment);
CBIND_DECL(abis__silo_nullifier);
CBIND_DECL(abis__compute_block_hash);
CBIND_DECL(abis__compute_block_hash_with_globals);
CBIND_DECL(abis__compute_globals_hash);

WASM_EXPORT void abis__compute_message_secret_hash(uint8_t const* secret, uint8_t* output);
WASM_EXPORT void abis__compute_contract_leaf(uint8_t const* contract_leaf_preimage_buf, uint8_t* output);
Expand Down
18 changes: 9 additions & 9 deletions circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "tx_context.hpp"

#include "aztec3/circuits/abis/combined_historic_tree_roots.hpp"
#include "aztec3/circuits/abis/constant_historic_block_data.hpp"
#include "aztec3/utils/types/circuit_types.hpp"
#include "aztec3/utils/types/convert.hpp"
#include "aztec3/utils/types/native_types.hpp"
Expand All @@ -11,7 +11,7 @@

namespace aztec3::circuits::abis {

using aztec3::circuits::abis::CombinedHistoricTreeRoots;
using aztec3::circuits::abis::ConstantHistoricBlockData;
using aztec3::utils::types::CircuitTypes;
using aztec3::utils::types::NativeTypes;
using std::is_same;
Expand All @@ -20,22 +20,22 @@ template <typename NCT> struct CombinedConstantData {
using fr = typename NCT::fr;
using boolean = typename NCT::boolean;

CombinedHistoricTreeRoots<NCT> historic_tree_roots{};
ConstantHistoricBlockData<NCT> block_data{};
TxContext<NCT> tx_context{};

// for serialization: update up with new fields
MSGPACK_FIELDS(historic_tree_roots, tx_context);
MSGPACK_FIELDS(block_data, tx_context);
boolean operator==(CombinedConstantData<NCT> const& other) const
{
return historic_tree_roots == other.historic_tree_roots && tx_context == other.tx_context;
return block_data == other.block_data && tx_context == other.tx_context;
}

template <typename Builder> CombinedConstantData<CircuitTypes<Builder>> to_circuit_type(Builder& builder) const
{
static_assert((std::is_same<NativeTypes, NCT>::value));

CombinedConstantData<CircuitTypes<Builder>> constant_data = {
historic_tree_roots.to_circuit_type(builder),
block_data.to_circuit_type(builder),
tx_context.to_circuit_type(builder),
};

Expand All @@ -49,7 +49,7 @@ template <typename NCT> struct CombinedConstantData {
auto to_native_type = []<typename T>(T& e) { return e.template to_native_type<Builder>(); };

CombinedConstantData<NativeTypes> constant_data = {
to_native_type(historic_tree_roots),
to_native_type(block_data),
to_native_type(tx_context),
};

Expand All @@ -60,14 +60,14 @@ template <typename NCT> struct CombinedConstantData {
{
static_assert(!(std::is_same<NativeTypes, NCT>::value));

historic_tree_roots.set_public();
block_data.set_public();
tx_context.set_public();
}
};

template <typename NCT> std::ostream& operator<<(std::ostream& os, CombinedConstantData<NCT> const& constant_data)
{
return os << "historic_tree_roots: " << constant_data.historic_tree_roots << "\n"
return os << "block_data: " << constant_data.block_data << "\n"
<< "tx_context: " << constant_data.tx_context << "\n";
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#pragma once

#include "aztec3/circuits/abis/append_only_tree_snapshot.hpp"
#include "aztec3/circuits/abis/global_variables.hpp"
#include "aztec3/circuits/hash.hpp"
#include "aztec3/utils/types/circuit_types.hpp"
#include "aztec3/utils/types/convert.hpp"
#include "aztec3/utils/types/native_types.hpp"
Expand All @@ -12,57 +15,68 @@ using aztec3::utils::types::CircuitTypes;
using aztec3::utils::types::NativeTypes;
using std::is_same;

template <typename NCT> struct PrivateHistoricTreeRoots {
template <typename NCT> struct ConstantHistoricBlockData {
using fr = typename NCT::fr;
using boolean = typename NCT::boolean;

// Private data
fr private_data_tree_root = 0;
fr nullifier_tree_root = 0;
fr contract_tree_root = 0;
fr l1_to_l2_messages_tree_root = 0;
fr blocks_tree_root = 0;
fr private_kernel_vk_tree_root = 0; // TODO: future enhancement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbanks12 or @iAmMichaelConnor I guess the todo here is one of yours? Can one of you create an issue for it?


// for serialization: update up with new fields
// Public data
fr public_data_tree_root = 0;
fr prev_global_variables_hash = 0;

// for serialization, update with new fields
MSGPACK_FIELDS(private_data_tree_root,
nullifier_tree_root,
contract_tree_root,
l1_to_l2_messages_tree_root,
blocks_tree_root,
private_kernel_vk_tree_root);
private_kernel_vk_tree_root,
public_data_tree_root,
prev_global_variables_hash);

boolean operator==(PrivateHistoricTreeRoots<NCT> const& other) const
boolean operator==(ConstantHistoricBlockData<NCT> const& other) const
{
return private_data_tree_root == other.private_data_tree_root &&
nullifier_tree_root == other.nullifier_tree_root && contract_tree_root == other.contract_tree_root &&
l1_to_l2_messages_tree_root == other.l1_to_l2_messages_tree_root &&
blocks_tree_root == other.historic_block_root &&
private_kernel_vk_tree_root == other.private_kernel_vk_tree_root;
private_kernel_vk_tree_root == other.private_kernel_vk_tree_root &&
public_data_tree_root == other.public_data_tree_root &&
prev_global_variables_hash == other.prev_global_variables_hash;
};

template <typename Builder> PrivateHistoricTreeRoots<CircuitTypes<Builder>> to_circuit_type(Builder& builder) const
template <typename Builder> ConstantHistoricBlockData<CircuitTypes<Builder>> to_circuit_type(Builder& builder) const
{
static_assert((std::is_same<NativeTypes, NCT>::value));

// Capture the circuit builder:
auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); };

PrivateHistoricTreeRoots<CircuitTypes<Builder>> data = {
to_ct(private_data_tree_root), to_ct(nullifier_tree_root), to_ct(contract_tree_root),
to_ct(l1_to_l2_messages_tree_root), to_ct(blocks_tree_root), to_ct(private_kernel_vk_tree_root),
ConstantHistoricBlockData<CircuitTypes<Builder>> data = {
to_ct(private_data_tree_root), to_ct(nullifier_tree_root), to_ct(contract_tree_root),
to_ct(l1_to_l2_messages_tree_root), to_ct(blocks_tree_root), to_ct(private_kernel_vk_tree_root),
to_ct(public_data_tree_root), to_ct(prev_global_variables_hash),
};

return data;
};

template <typename Builder> PrivateHistoricTreeRoots<NativeTypes> to_native_type() const
template <typename Builder> ConstantHistoricBlockData<NativeTypes> to_native_type() const
{
static_assert(std::is_same<CircuitTypes<Builder>, NCT>::value);
auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt<Builder>(e); };

PrivateHistoricTreeRoots<NativeTypes> data = {
to_nt(private_data_tree_root), to_nt(nullifier_tree_root), to_nt(contract_tree_root),
to_nt(l1_to_l2_messages_tree_root), to_nt(blocks_tree_root), to_nt(private_kernel_vk_tree_root),
ConstantHistoricBlockData<NativeTypes> data = {
to_nt(private_data_tree_root), to_nt(nullifier_tree_root), to_nt(contract_tree_root),
to_nt(l1_to_l2_messages_tree_root), to_nt(blocks_tree_root), to_nt(private_kernel_vk_tree_root),
to_nt(public_data_tree_root), to_nt(prev_global_variables_hash),
};

return data;
Expand All @@ -78,18 +92,33 @@ template <typename NCT> struct PrivateHistoricTreeRoots {
l1_to_l2_messages_tree_root.set_public();
blocks_tree_root.set_public();
private_kernel_vk_tree_root.set_public();
public_data_tree_root.set_public();
prev_global_variables_hash.set_public();
}


fr hash()
{
return compute_block_hash(prev_global_variables_hash,
private_data_tree_root,
nullifier_tree_root,
contract_tree_root,
l1_to_l2_messages_tree_root,
public_data_tree_root);
}
};

template <typename NCT>
std::ostream& operator<<(std::ostream& os, PrivateHistoricTreeRoots<NCT> const& historic_tree_roots)
std::ostream& operator<<(std::ostream& os, ConstantHistoricBlockData<NCT> const& historic_tree_roots)
{
return os << "private_data_tree_root: " << historic_tree_roots.private_data_tree_root << "\n"
<< "nullifier_tree_root: " << historic_tree_roots.nullifier_tree_root << "\n"
<< "contract_tree_root: " << historic_tree_roots.contract_tree_root << "\n"
<< "l1_to_l2_messages_tree_root: " << historic_tree_roots.l1_to_l2_messages_tree_root << "\n"
<< "blocks_tree_root: " << historic_tree_roots.blocks_tree_root << "\n"
<< "private_kernel_vk_tree_root: " << historic_tree_roots.private_kernel_vk_tree_root << "\n";
<< "private_kernel_vk_tree_root: " << historic_tree_roots.private_kernel_vk_tree_root << "\n"
<< "public_data_tree_root: " << historic_tree_roots.public_data_tree_root << "\n"
<< "prev_global_variables_hash: " << historic_tree_roots.prev_global_variables_hash << "\n";
}

} // namespace aztec3::circuits::abis
24 changes: 23 additions & 1 deletion circuits/cpp/src/aztec3/circuits/abis/global_variables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ template <typename NCT> struct GlobalVariables {
timestamp == other.timestamp;
};

/**
* @brief Returns an object containing all global variables set to zero.
*
* @return GlobalVariables<NCT>
*/
static GlobalVariables<NCT> empty()
{
GlobalVariables<NCT> globals = { 0, 0, 0, 0 };
return globals;
}

template <typename Builder> GlobalVariables<CircuitTypes<Builder>> to_circuit_type(Builder& builder) const
{
static_assert((std::is_same<NativeTypes, NCT>::value));
Expand All @@ -50,6 +61,7 @@ template <typename NCT> struct GlobalVariables {
return globals;
};


fr hash() const
{
std::vector<fr> inputs;
Expand All @@ -60,7 +72,17 @@ template <typename NCT> struct GlobalVariables {

return NCT::compress(inputs, GeneratorIndex::GLOBAL_VARIABLES);
}
};

void set_public()
{
static_assert(!(std::is_same<NativeTypes, NCT>::value));

chain_id.set_public();
version.set_public();
block_number.set_public();
timestamp.set_public();
}
}; // namespace aztec3::circuits::abis

template <typename NCT> void read(uint8_t const*& it, GlobalVariables<NCT>& globals)
{
Expand Down
21 changes: 9 additions & 12 deletions circuits/cpp/src/aztec3/circuits/abis/packers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,16 @@ struct ConstantsPacker {
PUBLIC_DATA_TREE_HEIGHT,
NULLIFIER_TREE_HEIGHT,
L1_TO_L2_MSG_TREE_HEIGHT,
PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT,
CONTRACT_TREE_ROOTS_TREE_HEIGHT,
L1_TO_L2_MSG_TREE_ROOTS_TREE_HEIGHT,
ROLLUP_VK_TREE_HEIGHT,
CONTRACT_SUBTREE_HEIGHT,
CONTRACT_SUBTREE_SIBLING_PATH_LENGTH,
PRIVATE_DATA_SUBTREE_HEIGHT,
PRIVATE_DATA_SUBTREE_SIBLING_PATH_LENGTH,
NULLIFIER_SUBTREE_HEIGHT),
NVP(HISTORIC_BLOCKS_TREE_HEIGHT,
NULLIFIER_SUBTREE_HEIGHT,
HISTORIC_BLOCKS_TREE_HEIGHT,
NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH,
L1_TO_L2_MSG_SUBTREE_HEIGHT,
L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
L1_TO_L2_MSG_SUBTREE_HEIGHT),
NVP(L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
FUNCTION_SELECTOR_NUM_BYTES,
MAPPING_SLOT_PEDERSEN_SEPARATOR,
NUM_FIELDS_PER_SHA256,
Expand All @@ -71,16 +68,16 @@ struct ConstantsPacker {
MAX_NOTES_PER_PAGE,
VIEW_NOTE_ORACLE_RETURN_LENGTH,
CALL_CONTEXT_LENGTH,
COMMITMENT_TREES_ROOTS_LENGTH,
BLOCK_HASH_DATA_LENGTH,
FUNCTION_DATA_LENGTH,
CONTRACT_DEPLOYMENT_DATA_LENGTH,
PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH,
CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH,
CONTRACT_STORAGE_READ_LENGTH),
NVP(PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH,
CONTRACT_STORAGE_READ_LENGTH,
PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH,
GET_NOTES_ORACLE_RETURN_LENGTH,
EMPTY_NULLIFIED_COMMITMENT,
CALL_PRIVATE_FUNCTION_RETURN_SIZE,
EMPTY_NULLIFIED_COMMITMENT),
NVP(CALL_PRIVATE_FUNCTION_RETURN_SIZE,
PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH,
PRIVATE_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH,
KERNELS_PER_BASE_ROLLUP,
Expand Down
Loading