Skip to content

Commit 1dd6225

Browse files
authoredAug 14, 2023
fix(synchroniser): Store most recent globals hash in the synchroniser, rather than fetching from the latest block (#1539)
fixes: #1537 Stores the most recent global variables hash within the synchroniser rather than fetching it from the most recent block. This created a race condition where the globals hash requested from the block was ahead of the tree roots requested from the node. As the tree roots were being requested from the node the synchroniser was also behind.
1 parent e9d0e6b commit 1dd6225

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+401
-296
lines changed
 

‎circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "tx_context.hpp"
44

5-
#include "aztec3/circuits/abis/constant_historic_block_data.hpp"
5+
#include "aztec3/circuits/abis/historic_block_data.hpp"
66
#include "aztec3/utils/types/circuit_types.hpp"
77
#include "aztec3/utils/types/convert.hpp"
88
#include "aztec3/utils/types/native_types.hpp"
@@ -11,7 +11,7 @@
1111

1212
namespace aztec3::circuits::abis {
1313

14-
using aztec3::circuits::abis::ConstantHistoricBlockData;
14+
using aztec3::circuits::abis::HistoricBlockData;
1515
using aztec3::utils::types::CircuitTypes;
1616
using aztec3::utils::types::NativeTypes;
1717
using std::is_same;
@@ -20,7 +20,7 @@ template <typename NCT> struct CombinedConstantData {
2020
using fr = typename NCT::fr;
2121
using boolean = typename NCT::boolean;
2222

23-
ConstantHistoricBlockData<NCT> block_data{};
23+
HistoricBlockData<NCT> block_data{};
2424
TxContext<NCT> tx_context{};
2525

2626
// for serialization: update up with new fields

‎circuits/cpp/src/aztec3/circuits/abis/constant_historic_block_data.hpp ‎circuits/cpp/src/aztec3/circuits/abis/historic_block_data.hpp

+19-20
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using aztec3::utils::types::CircuitTypes;
1515
using aztec3::utils::types::NativeTypes;
1616
using std::is_same;
1717

18-
template <typename NCT> struct ConstantHistoricBlockData {
18+
template <typename NCT> struct HistoricBlockData {
1919
using fr = typename NCT::fr;
2020
using boolean = typename NCT::boolean;
2121

@@ -29,7 +29,7 @@ template <typename NCT> struct ConstantHistoricBlockData {
2929

3030
// Public data
3131
fr public_data_tree_root = 0;
32-
fr prev_global_variables_hash = 0;
32+
fr global_variables_hash = 0;
3333

3434
// for serialization, update with new fields
3535
MSGPACK_FIELDS(private_data_tree_root,
@@ -39,44 +39,44 @@ template <typename NCT> struct ConstantHistoricBlockData {
3939
blocks_tree_root,
4040
private_kernel_vk_tree_root,
4141
public_data_tree_root,
42-
prev_global_variables_hash);
42+
global_variables_hash);
4343

44-
boolean operator==(ConstantHistoricBlockData<NCT> const& other) const
44+
boolean operator==(HistoricBlockData<NCT> const& other) const
4545
{
4646
return private_data_tree_root == other.private_data_tree_root &&
4747
nullifier_tree_root == other.nullifier_tree_root && contract_tree_root == other.contract_tree_root &&
4848
l1_to_l2_messages_tree_root == other.l1_to_l2_messages_tree_root &&
4949
blocks_tree_root == other.historic_block_root &&
5050
private_kernel_vk_tree_root == other.private_kernel_vk_tree_root &&
5151
public_data_tree_root == other.public_data_tree_root &&
52-
prev_global_variables_hash == other.prev_global_variables_hash;
52+
global_variables_hash == other.global_variables_hash;
5353
};
5454

55-
template <typename Builder> ConstantHistoricBlockData<CircuitTypes<Builder>> to_circuit_type(Builder& builder) const
55+
template <typename Builder> HistoricBlockData<CircuitTypes<Builder>> to_circuit_type(Builder& builder) const
5656
{
5757
static_assert((std::is_same<NativeTypes, NCT>::value));
5858

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

62-
ConstantHistoricBlockData<CircuitTypes<Builder>> data = {
63-
to_ct(private_data_tree_root), to_ct(nullifier_tree_root), to_ct(contract_tree_root),
64-
to_ct(l1_to_l2_messages_tree_root), to_ct(blocks_tree_root), to_ct(private_kernel_vk_tree_root),
65-
to_ct(public_data_tree_root), to_ct(prev_global_variables_hash),
62+
HistoricBlockData<CircuitTypes<Builder>> data = {
63+
to_ct(private_data_tree_root), to_ct(nullifier_tree_root), to_ct(contract_tree_root),
64+
to_ct(l1_to_l2_messages_tree_root), to_ct(blocks_tree_root), to_ct(private_kernel_vk_tree_root),
65+
to_ct(public_data_tree_root), to_ct(global_variables_hash),
6666
};
6767

6868
return data;
6969
};
7070

71-
template <typename Builder> ConstantHistoricBlockData<NativeTypes> to_native_type() const
71+
template <typename Builder> HistoricBlockData<NativeTypes> to_native_type() const
7272
{
7373
static_assert(std::is_same<CircuitTypes<Builder>, NCT>::value);
7474
auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt<Builder>(e); };
7575

76-
ConstantHistoricBlockData<NativeTypes> data = {
77-
to_nt(private_data_tree_root), to_nt(nullifier_tree_root), to_nt(contract_tree_root),
78-
to_nt(l1_to_l2_messages_tree_root), to_nt(blocks_tree_root), to_nt(private_kernel_vk_tree_root),
79-
to_nt(public_data_tree_root), to_nt(prev_global_variables_hash),
76+
HistoricBlockData<NativeTypes> data = {
77+
to_nt(private_data_tree_root), to_nt(nullifier_tree_root), to_nt(contract_tree_root),
78+
to_nt(l1_to_l2_messages_tree_root), to_nt(blocks_tree_root), to_nt(private_kernel_vk_tree_root),
79+
to_nt(public_data_tree_root), to_nt(global_variables_hash),
8080
};
8181

8282
return data;
@@ -93,13 +93,13 @@ template <typename NCT> struct ConstantHistoricBlockData {
9393
blocks_tree_root.set_public();
9494
private_kernel_vk_tree_root.set_public();
9595
public_data_tree_root.set_public();
96-
prev_global_variables_hash.set_public();
96+
global_variables_hash.set_public();
9797
}
9898

9999

100100
fr hash()
101101
{
102-
return compute_block_hash(prev_global_variables_hash,
102+
return compute_block_hash(global_variables_hash,
103103
private_data_tree_root,
104104
nullifier_tree_root,
105105
contract_tree_root,
@@ -108,8 +108,7 @@ template <typename NCT> struct ConstantHistoricBlockData {
108108
}
109109
};
110110

111-
template <typename NCT>
112-
std::ostream& operator<<(std::ostream& os, ConstantHistoricBlockData<NCT> const& historic_tree_roots)
111+
template <typename NCT> std::ostream& operator<<(std::ostream& os, HistoricBlockData<NCT> const& historic_tree_roots)
113112
{
114113
return os << "private_data_tree_root: " << historic_tree_roots.private_data_tree_root << "\n"
115114
<< "nullifier_tree_root: " << historic_tree_roots.nullifier_tree_root << "\n"
@@ -118,7 +117,7 @@ std::ostream& operator<<(std::ostream& os, ConstantHistoricBlockData<NCT> const&
118117
<< "blocks_tree_root: " << historic_tree_roots.blocks_tree_root << "\n"
119118
<< "private_kernel_vk_tree_root: " << historic_tree_roots.private_kernel_vk_tree_root << "\n"
120119
<< "public_data_tree_root: " << historic_tree_roots.public_data_tree_root << "\n"
121-
<< "prev_global_variables_hash: " << historic_tree_roots.prev_global_variables_hash << "\n";
120+
<< "prev_global_variables_hash: " << historic_tree_roots.global_variables_hash << "\n";
122121
}
123122

124123
} // namespace aztec3::circuits::abis

0 commit comments

Comments
 (0)
Please sign in to comment.