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(avm): Zero initialization in avm public inputs and execution test fixes #10238

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class AvmExecutionTests : public ::testing::Test {
srs::init_crs_factory("../srs_db/ignition");
public_inputs.gas_settings.gas_limits.l2_gas = DEFAULT_INITIAL_L2_GAS;
public_inputs.gas_settings.gas_limits.da_gas = DEFAULT_INITIAL_DA_GAS;
public_inputs.start_gas_used.l2_gas = 0;
public_inputs.start_gas_used.da_gas = 0;

// These values are magic because of how some tests work! Don't change them
PublicCallRequest dummy_request = {
/* msg_sender */ FF::one(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ void AvmGasTraceBuilder::set_initial_gas(uint32_t l2_gas, uint32_t da_gas)

uint32_t AvmGasTraceBuilder::get_l2_gas_left() const
{
if (gas_trace.size() == 0) {
if (gas_trace.empty()) {
return initial_l2_gas;
}
return gas_trace.back().remaining_l2_gas;
}

uint32_t AvmGasTraceBuilder::get_da_gas_left() const
{
if (gas_trace.empty()) {
return initial_da_gas;
}
return gas_trace.back().remaining_da_gas;
}

Expand Down
72 changes: 36 additions & 36 deletions barretenberg/cpp/src/barretenberg/vm/avm/trace/public_inputs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
using FF = bb::AvmFlavorSettings::FF;

struct EthAddress {
std::array<uint8_t, 20> value;
std::array<uint8_t, 20> value{};
};

struct Gas {
uint32_t l2_gas;
uint32_t da_gas;
uint32_t l2_gas{};
uint32_t da_gas{};
};

inline void read(uint8_t const*& it, Gas& gas)
Expand All @@ -23,8 +23,8 @@ inline void read(uint8_t const*& it, Gas& gas)
}

struct GasFees {
FF fee_per_da_gas;
FF fee_per_l2_gas;
FF fee_per_da_gas{};
FF fee_per_l2_gas{};
};

inline void read(uint8_t const*& it, GasFees& gas_fees)
Expand All @@ -50,20 +50,20 @@ inline void read(uint8_t const*& it, GasSettings& gas_settings)

struct GlobalVariables {
/** ChainId for the L2 block. */
FF chain_id;
FF chain_id{};
/** Version for the L2 block. */
FF version;
FF version{};
/** Block number of the L2 block. */
FF block_number;
FF block_number{};
/** Slot number of the L2 block */
FF slot_number;
FF slot_number{};
/** Timestamp of the L2 block. */
FF timestamp;
FF timestamp{};
/** Recipient of block reward */
// This is an eth address so it's actually only 20 bytes
FF coinbase;
FF coinbase{};
/** Address to receive fees. */
FF fee_recipient;
FF fee_recipient{};
/** Global gas prices for this block. */
GasFees gas_fees;
};
Expand All @@ -85,8 +85,8 @@ inline void read(uint8_t const*& it, GlobalVariables& global_variables)
}

struct AppendOnlyTreeSnapshot {
FF root;
uint32_t size;
FF root{};
uint32_t size{};
};

inline void read(uint8_t const*& it, AppendOnlyTreeSnapshot& tree_snapshot)
Expand Down Expand Up @@ -116,20 +116,20 @@ struct PublicCallRequest {
/**
* Address of the account which represents the entity who invoked the call.
*/
FF msg_sender;
FF msg_sender{};
/**
* The contract address being called.
*/
FF contract_address;
FF contract_address{};
/**
* Function selector of the function being called.
*/
uint32_t function_selector;
uint32_t function_selector{};
/**
* Determines whether the call is modifying state.
*/
bool is_static_call;
FF args_hash;
bool is_static_call = false;
FF args_hash{};
};

inline void read(uint8_t const*& it, PublicCallRequest& public_call_request)
Expand All @@ -143,9 +143,9 @@ inline void read(uint8_t const*& it, PublicCallRequest& public_call_request)
}

struct PrivateToAvmAccumulatedDataArrayLengths {
uint32_t note_hashes;
uint32_t nullifiers;
uint32_t l2_to_l1_msgs;
uint32_t note_hashes{};
uint32_t nullifiers{};
uint32_t l2_to_l1_msgs{};
};

inline void read(uint8_t const*& it, PrivateToAvmAccumulatedDataArrayLengths& lengths)
Expand All @@ -157,8 +157,8 @@ inline void read(uint8_t const*& it, PrivateToAvmAccumulatedDataArrayLengths& le
}

struct ScopedL2ToL1Message {
FF l2_to_l1_message;
FF contract_address;
FF l2_to_l1_message{};
FF contract_address{};
};

inline void read(uint8_t const*& it, ScopedL2ToL1Message& l2_to_l1_message)
Expand All @@ -169,8 +169,8 @@ inline void read(uint8_t const*& it, ScopedL2ToL1Message& l2_to_l1_message)
}

struct PrivateToAvmAccumulatedData {
std::array<FF, MAX_NOTE_HASHES_PER_TX> note_hashes;
std::array<FF, MAX_NULLIFIERS_PER_CALL> nullifiers;
std::array<FF, MAX_NOTE_HASHES_PER_TX> note_hashes{};
std::array<FF, MAX_NULLIFIERS_PER_CALL> nullifiers{};
std::array<ScopedL2ToL1Message, MAX_L2_TO_L1_MSGS_PER_CALL> l2_to_l1_msgs;
};

Expand All @@ -189,9 +189,9 @@ inline void read(uint8_t const*& it, PrivateToAvmAccumulatedData& accumulated_da
}

struct LogHash {
FF value;
FF counter;
FF length;
FF value{};
FF counter{};
FF length{};
};

inline void read(uint8_t const*& it, LogHash& log_hash)
Expand All @@ -204,7 +204,7 @@ inline void read(uint8_t const*& it, LogHash& log_hash)

struct ScopedLogHash {
LogHash log_hash;
FF contract_address;
FF contract_address{};
};

inline void read(uint8_t const*& it, ScopedLogHash& scoped_log_hash)
Expand All @@ -215,8 +215,8 @@ inline void read(uint8_t const*& it, ScopedLogHash& scoped_log_hash)
}

struct PublicDataWrite {
FF leaf_slot;
FF value;
FF leaf_slot{};
FF value{};
};

inline void read(uint8_t const*& it, PublicDataWrite& public_data_write)
Expand All @@ -230,11 +230,11 @@ struct AvmAccumulatedData {
/**
* The note hashes from private combining with those made in the AVM execution.
*/
std::array<FF, MAX_NOTE_HASHES_PER_TX> note_hashes;
std::array<FF, MAX_NOTE_HASHES_PER_TX> note_hashes{};
/**
* The nullifiers from private combining with those made in the AVM execution.
*/
std::array<FF, MAX_NULLIFIERS_PER_CALL> nullifiers;
std::array<FF, MAX_NULLIFIERS_PER_CALL> nullifiers{};
/**
* The L2 to L1 messages from private combining with those made in the AVM execution.
*/
Expand Down Expand Up @@ -285,8 +285,8 @@ class AvmPublicInputs {
TreeSnapshots end_tree_snapshots;
Gas end_gas_used;
AvmAccumulatedData accumulated_data;
FF transaction_fee;
bool reverted;
FF transaction_fee{};
bool reverted = false;

AvmPublicInputs() = default;
static AvmPublicInputs from(const std::vector<uint8_t>& data)
Expand Down
Loading