Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
296088f
Enforce fee payer in protocol circuits.
LeilaWang Jan 11, 2025
329dc58
Remove empty fee payer assumption in avm trace.
LeilaWang Jan 13, 2025
e334f25
Allow to prefill public data tree in the world state.
LeilaWang Jan 18, 2025
eca81fc
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Jan 18, 2025
171bd7b
Enforce fees.
LeilaWang Jan 24, 2025
4e72de9
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Jan 24, 2025
3d0ba29
Fix tests.
LeilaWang Jan 31, 2025
bb75c62
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Jan 31, 2025
86da24f
Fixes.
LeilaWang Feb 3, 2025
26df235
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 3, 2025
c6e859a
Fix.
LeilaWang Feb 4, 2025
bcf9460
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 4, 2025
59b088f
Fix.
LeilaWang Feb 4, 2025
0b3950c
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 5, 2025
670c113
Fix.
LeilaWang Feb 5, 2025
86da1fb
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 5, 2025
96d50df
Fix.
LeilaWang Feb 6, 2025
16d19bf
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 6, 2025
b03d89d
Add testAccounts option.
LeilaWang Feb 7, 2025
7448c22
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 7, 2025
385c4f3
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 7, 2025
fed55a0
Fix dependencies.
LeilaWang Feb 7, 2025
632c482
Fix.
LeilaWang Feb 7, 2025
bca2541
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 7, 2025
6f926a7
Deploy fpc to sandbox.
LeilaWang Feb 8, 2025
a7010ca
Use test account in bot.
LeilaWang Feb 8, 2025
2f4cb12
Deploy test accounts for e2e native network.
LeilaWang Feb 10, 2025
7a8faee
Fix.
LeilaWang Feb 10, 2025
8b8e8a9
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 10, 2025
e22a9dc
Formatting.
LeilaWang Feb 10, 2025
0ecc38f
Fix tests.
LeilaWang Feb 10, 2025
bdf2076
Fix tests.
LeilaWang Feb 10, 2025
f92be8f
Fix tests.
LeilaWang Feb 11, 2025
190f64b
Formatting.
LeilaWang Feb 11, 2025
c548e0f
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 11, 2025
ebcdd8a
Fix.
LeilaWang Feb 11, 2025
d7fc10a
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 11, 2025
5434274
Formatting.
LeilaWang Feb 11, 2025
ec1bdeb
Allow to skip fee when checking if a tx is valid.
LeilaWang Feb 11, 2025
8aa9d5a
Allow bot to bridge fee juice from L1.
LeilaWang Feb 12, 2025
99438a5
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 12, 2025
3065588
Fix tests.
LeilaWang Feb 12, 2025
6f8dde1
Progress l2 blocks for claiming fee juice from L1.
LeilaWang Feb 12, 2025
ef02acd
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 12, 2025
aa24a6f
Formatting.
LeilaWang Feb 12, 2025
f881a99
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 12, 2025
2e44da5
Bridge fee juice in network tests.
LeilaWang Feb 12, 2025
31e64f7
Port forward.
LeilaWang Feb 13, 2025
a7cbf1f
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 13, 2025
e4a0931
Fix.
LeilaWang Feb 13, 2025
7edd511
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 13, 2025
137c836
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 13, 2025
c47cd35
Update configs.
LeilaWang Feb 13, 2025
90d561a
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 13, 2025
8c2a786
Add migration note.
LeilaWang Feb 14, 2025
6cbb9ec
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 14, 2025
fa5be6a
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 14, 2025
68ad441
Merge remote-tracking branch 'origin/master' into lw/fee_payer
ludamad Feb 14, 2025
bc61fc3
Merge remote-tracking branch 'origin/lw/fee_payer' into lw/fee_payer
ludamad Feb 14, 2025
3a2e105
Fix.
LeilaWang Feb 14, 2025
a695163
Merge remote-tracking branch 'origin/master' into lw/fee_payer
LeilaWang Feb 14, 2025
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
4 changes: 4 additions & 0 deletions .github/workflows/network-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ jobs:
-var="AZTEC_DOCKER_IMAGE=${{ env.AZTEC_DOCKER_IMAGE }}" \
-var="L1_DEPLOYMENT_PRIVATE_KEY=${{ secrets.SEPOLIA_L1_DEPLOYMENT_PRIVATE_KEY }}" \
-var="L1_DEPLOYMENT_MNEMONIC=$L1_DEPLOYMENT_MNEMONIC" \
-var="BOT_L1_MNEMONIC=$L1_DEPLOYMENT_MNEMONIC" \
-var="EXTERNAL_ETHEREUM_HOST=${{ env.EXTERNAL_ETHEREUM_HOST }}" \
-var="EXTERNAL_ETHEREUM_CONSENSUS_HOST=${{ env.EXTERNAL_ETHEREUM_CONSENSUS_HOST }}" \
-var="EXTERNAL_ETHEREUM_CONSENSUS_HOST_API_KEY=${{ secrets.SEPOLIA_API_KEY }}" \
Expand All @@ -207,6 +208,7 @@ jobs:
-var="GKE_CLUSTER_CONTEXT=${{ env.GKE_CLUSTER_CONTEXT }}" \
-var="AZTEC_DOCKER_IMAGE=${{ env.AZTEC_DOCKER_IMAGE }}" \
-var="L1_DEPLOYMENT_MNEMONIC=${{ steps.get-mnemonic.outputs.mnemonic }}" \
-var="BOT_L1_MNEMONIC=$L1_DEPLOYMENT_MNEMONIC" \
-lock=${{ inputs.respect_tf_lock }}
fi

Expand All @@ -222,6 +224,7 @@ jobs:
-var="AZTEC_DOCKER_IMAGE=${{ env.AZTEC_DOCKER_IMAGE }}" \
-var="L1_DEPLOYMENT_PRIVATE_KEY=${{ secrets.SEPOLIA_L1_DEPLOYMENT_PRIVATE_KEY }}" \
-var="L1_DEPLOYMENT_MNEMONIC=$L1_DEPLOYMENT_MNEMONIC" \
-var="BOT_L1_MNEMONIC=$L1_DEPLOYMENT_MNEMONIC" \
-var="L1_DEPLOYMENT_SALT=${DEPLOYMENT_SALT:-$RANDOM}" \
-var="EXTERNAL_ETHEREUM_HOST=${{ env.EXTERNAL_ETHEREUM_HOST }}" \
-var="EXTERNAL_ETHEREUM_CONSENSUS_HOST=${{ env.EXTERNAL_ETHEREUM_CONSENSUS_HOST }}" \
Expand All @@ -237,6 +240,7 @@ jobs:
-var="AZTEC_DOCKER_IMAGE=${{ env.AZTEC_DOCKER_IMAGE }}" \
-var="L1_DEPLOYMENT_MNEMONIC=${{ steps.get-mnemonic.outputs.mnemonic }}" \
-var="L1_DEPLOYMENT_SALT=${DEPLOYMENT_SALT:-$RANDOM}" \
-var="BOT_L1_MNEMONIC=$L1_DEPLOYMENT_MNEMONIC" \
-out=tfplan \
-lock=${{ inputs.respect_tf_lock }}
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ class ContentAddressedIndexedTree : public ContentAddressedAppendOnlyTree<Store,

ContentAddressedIndexedTree(std::unique_ptr<Store> store,
std::shared_ptr<ThreadPool> workers,
const index_t& initial_size);
const index_t& initial_size,
const std::vector<LeafValueType>& prefilled_values);
ContentAddressedIndexedTree(std::unique_ptr<Store> store,
std::shared_ptr<ThreadPool> workers,
const index_t& initial_size)
: ContentAddressedIndexedTree(std::move(store), workers, initial_size, std::vector<LeafValueType>()){};
ContentAddressedIndexedTree(ContentAddressedIndexedTree const& other) = delete;
ContentAddressedIndexedTree(ContentAddressedIndexedTree&& other) = delete;
~ContentAddressedIndexedTree() = default;
Expand Down Expand Up @@ -265,14 +270,19 @@ class ContentAddressedIndexedTree : public ContentAddressedAppendOnlyTree<Store,
};

template <typename Store, typename HashingPolicy>
ContentAddressedIndexedTree<Store, HashingPolicy>::ContentAddressedIndexedTree(std::unique_ptr<Store> store,
std::shared_ptr<ThreadPool> workers,
const index_t& initial_size)
ContentAddressedIndexedTree<Store, HashingPolicy>::ContentAddressedIndexedTree(
std::unique_ptr<Store> store,
std::shared_ptr<ThreadPool> workers,
const index_t& initial_size,
const std::vector<LeafValueType>& prefilled_values)
: ContentAddressedAppendOnlyTree<Store, HashingPolicy>(std::move(store), workers, {}, false)
{
if (initial_size < 2) {
throw std::runtime_error("Indexed trees must have initial size > 1");
}
if (prefilled_values.size() > initial_size) {
throw std::runtime_error("Number of prefilled values can't be more than initial size");
}
zero_hashes_.resize(depth_ + 1);

// Create the zero hashes for the tree
Expand All @@ -293,12 +303,23 @@ ContentAddressedIndexedTree<Store, HashingPolicy>::ContentAddressedIndexedTree(s

std::vector<IndexedLeafValueType> appended_leaves;
std::vector<bb::fr> appended_hashes;
std::vector<LeafValueType> initial_set;
auto num_default_values = static_cast<uint32_t>(initial_size - prefilled_values.size());
for (uint32_t i = 0; i < num_default_values; ++i) {
initial_set.push_back(LeafValueType::padding(i));
}
initial_set.insert(initial_set.end(), prefilled_values.begin(), prefilled_values.end());
for (uint32_t i = num_default_values; i < initial_size; ++i) {
if (i > 0 && (uint256_t(initial_set[i].get_key()) <= uint256_t(initial_set[i - 1].get_key()))) {
const auto* msg = i == num_default_values ? "Prefilled values must not be the same as the default values"
: "Prefilled values must be unique and sorted";
throw std::runtime_error(msg);
}
}
// Inserts the initial set of leaves as a chain in incrementing value order
for (uint32_t i = 0; i < initial_size; ++i) {
// Insert the zero leaf to the `leaves` and also to the tree at index 0.
bool last = i == (initial_size - 1);
IndexedLeafValueType initial_leaf =
IndexedLeafValueType(LeafValueType::padding(i), last ? 0 : i + 1, last ? 0 : i + 1);
uint32_t next_index = i == (initial_size - 1) ? 0 : i + 1;
auto initial_leaf = IndexedLeafValueType(initial_set[i], next_index, initial_set[next_index].get_key());
fr leaf_hash = HashingPolicy::hash(initial_leaf.get_hash_inputs());
appended_leaves.push_back(initial_leaf);
appended_hashes.push_back(leaf_hash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ using HashPolicy = Poseidon2HashPolicy;
using Store = ContentAddressedCachedTreeStore<NullifierLeafValue>;
using TreeType = ContentAddressedIndexedTree<Store, HashPolicy>;

using PublicDataStore = ContentAddressedCachedTreeStore<PublicDataLeafValue>;
using PublicDataTreeType = ContentAddressedIndexedTree<PublicDataStore, Poseidon2HashPolicy>;

using CompletionCallback = TreeType::AddCompletionCallbackWithWitness;
using SequentialCompletionCallback = TreeType::AddSequentiallyCompletionCallbackWithWitness;

Expand Down Expand Up @@ -2775,6 +2778,102 @@ TEST_F(PersistedContentAddressedIndexedTreeTest, can_sync_and_unwind_empty_block
}
}

TEST_F(PersistedContentAddressedIndexedTreeTest, test_prefilled_public_data)
{
ThreadPoolPtr workers = make_thread_pool(1);
constexpr size_t depth = 3;
std::string name = random_string();
LMDBTreeStore::SharedPtr db = std::make_shared<LMDBTreeStore>(_directory, name, _mapSize, _maxReaders);
std::unique_ptr<PublicDataStore> store = std::make_unique<PublicDataStore>(name, depth, db);

index_t initial_size = 4;
std::vector<PublicDataLeafValue> prefilled_values = { PublicDataLeafValue(3, 9), PublicDataLeafValue(5, 7) };
auto tree = PublicDataTreeType(std::move(store), workers, initial_size, prefilled_values);

/**
* Intial state:
*
* index 0 1 2 3 4 5 6 7
* ---------------------------------------------------------------------
* slot 0 1 3 5 0 0 0 0
* val 0 0 9 7 0 0 0 0
* nextIdx 1 2 3 0 0 0 0 0
* nextVal 1 3 5 0 0 0 0 0
*/
IndexedPublicDataLeafType leaf_0 = create_indexed_public_data_leaf(0, 0, 1, 1);
IndexedPublicDataLeafType leaf_1 = create_indexed_public_data_leaf(1, 0, 2, 3);
IndexedPublicDataLeafType leaf_2 = create_indexed_public_data_leaf(3, 9, 3, 5);
IndexedPublicDataLeafType leaf_3 = create_indexed_public_data_leaf(5, 7, 0, 0);
check_size(tree, initial_size);
EXPECT_EQ(get_leaf<PublicDataLeafValue>(tree, 0), leaf_0);
EXPECT_EQ(get_leaf<PublicDataLeafValue>(tree, 1), leaf_1);
EXPECT_EQ(get_leaf<PublicDataLeafValue>(tree, 2), leaf_2);
EXPECT_EQ(get_leaf<PublicDataLeafValue>(tree, 3), leaf_3);
}

TEST_F(PersistedContentAddressedIndexedTreeTest, test_full_prefilled_public_data)
{
ThreadPoolPtr workers = make_thread_pool(1);
constexpr size_t depth = 3;
std::string name = random_string();
LMDBTreeStore::SharedPtr db = std::make_shared<LMDBTreeStore>(_directory, name, _mapSize, _maxReaders);
std::unique_ptr<PublicDataStore> store = std::make_unique<PublicDataStore>(name, depth, db);

index_t initial_size = 4;
std::vector<PublicDataLeafValue> prefilled_values = {
PublicDataLeafValue(1, 2), PublicDataLeafValue(3, 4), PublicDataLeafValue(5, 6), PublicDataLeafValue(7, 8)
};
auto tree = PublicDataTreeType(std::move(store), workers, initial_size, prefilled_values);

/**
* Intial state:
*
* index 0 1 2 3 4 5 6 7
* ---------------------------------------------------------------------
* slot 0 1 3 5 0 0 0 0
* val 0 0 9 7 0 0 0 0
* nextIdx 1 2 3 0 0 0 0 0
* nextVal 1 3 5 0 0 0 0 0
*/
IndexedPublicDataLeafType leaf_0 = create_indexed_public_data_leaf(1, 2, 1, 3);
IndexedPublicDataLeafType leaf_1 = create_indexed_public_data_leaf(3, 4, 2, 5);
IndexedPublicDataLeafType leaf_2 = create_indexed_public_data_leaf(5, 6, 3, 7);
IndexedPublicDataLeafType leaf_3 = create_indexed_public_data_leaf(7, 8, 0, 1);
check_size(tree, initial_size);
EXPECT_EQ(get_leaf<PublicDataLeafValue>(tree, 0), leaf_0);
EXPECT_EQ(get_leaf<PublicDataLeafValue>(tree, 1), leaf_1);
EXPECT_EQ(get_leaf<PublicDataLeafValue>(tree, 2), leaf_2);
EXPECT_EQ(get_leaf<PublicDataLeafValue>(tree, 3), leaf_3);
}

TEST_F(PersistedContentAddressedIndexedTreeTest, test_prefilled_unsorted_public_data_should_fail)
{
ThreadPoolPtr workers = make_thread_pool(1);
constexpr size_t depth = 3;
std::string name = random_string();
LMDBTreeStore::SharedPtr db = std::make_shared<LMDBTreeStore>(_directory, name, _mapSize, _maxReaders);
std::unique_ptr<PublicDataStore> store = std::make_unique<PublicDataStore>(name, depth, db);

index_t initial_size = 4;
// The prefilled values are not sorted: 5 > 3.
std::vector<PublicDataLeafValue> prefilled_values = { PublicDataLeafValue(5, 7), PublicDataLeafValue(3, 9) };
EXPECT_THROW(PublicDataTreeType(std::move(store), workers, initial_size, prefilled_values), std::runtime_error);
}

TEST_F(PersistedContentAddressedIndexedTreeTest, test_prefilled_default_public_data_should_fail)
{
ThreadPoolPtr workers = make_thread_pool(1);
constexpr size_t depth = 3;
std::string name = random_string();
LMDBTreeStore::SharedPtr db = std::make_shared<LMDBTreeStore>(_directory, name, _mapSize, _maxReaders);
std::unique_ptr<PublicDataStore> store = std::make_unique<PublicDataStore>(name, depth, db);

index_t initial_size = 4;
// The first prefilled value is the same as one of the default values (1).
std::vector<PublicDataLeafValue> prefilled_values = { PublicDataLeafValue(1, 9), PublicDataLeafValue(5, 7) };
EXPECT_THROW(PublicDataTreeType(std::move(store), workers, initial_size, prefilled_values), std::runtime_error);
}

TEST_F(PersistedContentAddressedIndexedTreeTest, test_can_commit_and_revert_checkpoints)
{
index_t initial_size = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ WorldStateWrapper::WorldStateWrapper(const Napi::CallbackInfo& info)
};
std::unordered_map<MerkleTreeId, uint32_t> tree_height;
std::unordered_map<MerkleTreeId, index_t> tree_prefill;
std::vector<PublicDataLeafValue> prefilled_public_data;
std::vector<MerkleTreeId> tree_ids{
MerkleTreeId::NULLIFIER_TREE, MerkleTreeId::NOTE_HASH_TREE, MerkleTreeId::PUBLIC_DATA_TREE,
MerkleTreeId::L1_TO_L2_MESSAGE_TREE, MerkleTreeId::ARCHIVE,
Expand Down Expand Up @@ -87,15 +88,38 @@ WorldStateWrapper::WorldStateWrapper(const Napi::CallbackInfo& info)
throw Napi::TypeError::New(env, "Tree prefill must be a map");
}

size_t initial_header_generator_point_index = 3;
size_t prefilled_public_data_index = 3;
if (info.Length() > prefilled_public_data_index && info[prefilled_public_data_index].IsArray()) {
Napi::Array arr = info[prefilled_public_data_index].As<Napi::Array>();
for (uint32_t i = 0; i < arr.Length(); ++i) {
Napi::Array deserialized = arr.Get(i).As<Napi::Array>();
if (deserialized.Length() != 2 || !deserialized.Get(uint32_t(0)).IsBuffer() ||
!deserialized.Get(uint32_t(1)).IsBuffer()) {
throw Napi::TypeError::New(env, "Prefilled public data value must be a buffer array of size 2");
}
Napi::Buffer<uint8_t> slot_buf = deserialized.Get(uint32_t(0)).As<Napi::Buffer<uint8_t>>();
Napi::Buffer<uint8_t> value_buf = deserialized.Get(uint32_t(1)).As<Napi::Buffer<uint8_t>>();
uint256_t slot = 0;
uint256_t value = 0;
for (size_t j = 0; j < 32; ++j) {
slot = (slot << 8) | slot_buf[j];
value = (value << 8) | value_buf[j];
}
prefilled_public_data.push_back(PublicDataLeafValue(slot, value));
}
} else {
throw Napi::TypeError::New(env, "Prefilled public data must be an array");
}

size_t initial_header_generator_point_index = 4;
if (info.Length() > initial_header_generator_point_index && info[initial_header_generator_point_index].IsNumber()) {
initial_header_generator_point = info[initial_header_generator_point_index].As<Napi::Number>().Uint32Value();
} else {
throw Napi::TypeError::New(env, "Header generator point needs to be a number");
}

// optional parameters
size_t map_size_index = 4;
size_t map_size_index = 5;
if (info.Length() > map_size_index) {
if (info[4].IsObject()) {
Napi::Object obj = info[map_size_index].As<Napi::Object>();
Expand All @@ -115,7 +139,7 @@ WorldStateWrapper::WorldStateWrapper(const Napi::CallbackInfo& info)
}
}

size_t thread_pool_size_index = 5;
size_t thread_pool_size_index = 6;
if (info.Length() > thread_pool_size_index) {
if (!info[thread_pool_size_index].IsNumber()) {
throw Napi::TypeError::New(env, "Thread pool size must be a number");
Expand All @@ -124,8 +148,13 @@ WorldStateWrapper::WorldStateWrapper(const Napi::CallbackInfo& info)
thread_pool_size = info[thread_pool_size_index].As<Napi::Number>().Uint32Value();
}

_ws = std::make_unique<WorldState>(
thread_pool_size, data_dir, map_size, tree_height, tree_prefill, initial_header_generator_point);
_ws = std::make_unique<WorldState>(thread_pool_size,
data_dir,
map_size,
tree_height,
tree_prefill,
prefilled_public_data,
initial_header_generator_point);

_dispatcher.registerTarget(
WorldStateMessageType::GET_TREE_INFO,
Expand Down
5 changes: 0 additions & 5 deletions barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,6 @@ void AvmTraceBuilder::pay_fee()
auto tx_fee = (total_fee_per_da_gas * public_inputs.end_gas_used.da_gas) +
(total_fee_per_l2_gas * public_inputs.end_gas_used.l2_gas);

if (public_inputs.fee_payer == 0) {
vinfo("No one is paying the fee of ", tx_fee);
return;
}

// ** Compute the storage slot **
// using the base slot of the balances map and the fee payer address (map key)
// TS equivalent:
Expand Down
Loading