diff --git a/barretenberg/cpp/src/barretenberg/avm_fuzzer/harness/alu.fuzzer.cpp b/barretenberg/cpp/src/barretenberg/avm_fuzzer/harness/alu.fuzzer.cpp index 37da5d8454f6..50852f90432e 100644 --- a/barretenberg/cpp/src/barretenberg/avm_fuzzer/harness/alu.fuzzer.cpp +++ b/barretenberg/cpp/src/barretenberg/avm_fuzzer/harness/alu.fuzzer.cpp @@ -42,8 +42,9 @@ struct AluFuzzerInput { MemoryValue a; MemoryValue b; MemoryValue c = MemoryValue::from_tag(MemoryTag::FF, 0); // Placeholder for result - int op_id = 0; // For execution trace alu_op_id - + uint16_t op_id = 0; // For execution trace alu_op_id + // We serialise MemoryValues as FF + 1 byte for tag to save 31 bytes per value: + static const size_t size = (3 * (sizeof(FF) + 1)) + sizeof(uint16_t); // Serialize to buffer void to_buffer(uint8_t* buffer) const { @@ -58,7 +59,7 @@ struct AluFuzzerInput { buffer += sizeof(FF) + 1; write_mem_value(buffer, c); buffer += sizeof(FF) + 1; - serialize::write(buffer, static_cast(op_id)); + serialize::write(buffer, op_id); } static AluFuzzerInput from_buffer(const uint8_t* buffer) @@ -88,11 +89,11 @@ struct AluFuzzerInput { extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size, size_t max_size, unsigned int seed) { - if (size < sizeof(AluFuzzerInput)) { + if (size < AluFuzzerInput::size) { // Initialize with default input AluFuzzerInput input; input.to_buffer(data); - return sizeof(AluFuzzerInput); + return AluFuzzerInput::size; } std::mt19937_64 rng(seed); @@ -119,7 +120,6 @@ extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size, size_t max auto random_mem_value_from_tag = [&rng](MemoryTag tag) -> MemoryValue { std::uniform_int_distribution dist(0, std::numeric_limits::max()); - // TODO(MW): Use array? FF value = FF(dist(rng), dist(rng), dist(rng), dist(rng)); // Do we want the option of making "invalid tag" values, where the value is out of range for the tag? // These aren't currently possible with this function since MemoryValue::from_tag will throw in that case. @@ -135,9 +135,9 @@ extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size, size_t max // Deserialize current input AluFuzzerInput input = AluFuzzerInput::from_buffer(data); - // Choose random ALU operation + // Choose random ALU operation (11 possible operations with op_id = 2^index) std::uniform_int_distribution dist(0, 11); - input.op_id = 1 << dist(rng); + input.op_id = static_cast(1 << dist(rng)); // Choose test case (TODO(MW): what else do we want here?) dist = std::uniform_int_distribution(0, 4); @@ -187,18 +187,18 @@ extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size, size_t max // Serialize mutated input back to buffer input.to_buffer(data); - if (max_size > sizeof(AluFuzzerInput)) { - return sizeof(AluFuzzerInput); + if (max_size > AluFuzzerInput::size) { + return AluFuzzerInput::size; } - return sizeof(AluFuzzerInput); + return AluFuzzerInput::size; } extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { using bb::avm2::MemoryValue; - if (size < sizeof(AluFuzzerInput)) { + if (size < AluFuzzerInput::size) { info("Input size too small"); return 0; } diff --git a/yarn-project/simulator/README.md b/yarn-project/simulator/README.md index 3533c59d89b9..19b9612d8a35 100644 --- a/yarn-project/simulator/README.md +++ b/yarn-project/simulator/README.md @@ -12,7 +12,7 @@ It's able to simulate three different types of functions: Private functions are simulated and proved client-side, and verified client-side in the private kernel circuit. -The public inputs of private functions is defined [here](../stdlib/src/structs/private_circuit_public_inputs.ts). +The public inputs of private functions are defined [here](../stdlib/src/structs/private_circuit_public_inputs.ts). They are run with the assistance of a DB oracle that provides any private data requested by the function. @@ -22,17 +22,17 @@ Private functions can call another private function, and can request to call a p Public functions are simulated and proved on the sequencer side, and verified by the public kernel circuit. -The public inputs of public functions is defined [here](../stdlib/src/structs/avm/avm_circuit_public_inputs.ts). +The public inputs of public functions are defined [here](../stdlib/src/structs/avm/avm_circuit_public_inputs.ts). They are run with the assistance of an oracle that provides any value read from the public state tree. -Public functions can call other public function, but no private functions. +Public functions can call other public functions, but cannot call private functions. See the specifications of the [Aztec Virtual Machine (AVM) for public execution](./docs/avm/index.md). ### Unconstrained Functions -Unconstrained functions are useful to extract useful data for users that could produce very large execution traces - such as the summed balance of all a users notes +Unconstrained functions are useful to extract data for users that could produce very large execution traces - such as the summed balance of all of a user's notes. They are not proved, and are simulated client-side. They are run with the assistance of a DB oracle that provides any private data requested by the function. diff --git a/yarn-project/simulator/docs/avm/README.md b/yarn-project/simulator/docs/avm/README.md index 1ffbc967b4e0..4eef71fbaf2a 100644 --- a/yarn-project/simulator/docs/avm/README.md +++ b/yarn-project/simulator/docs/avm/README.md @@ -39,7 +39,7 @@ public execution requests. The AVM: * Executes specified public bytecode, instruction by instruction, given some arguments. * Meters execution by tracking gas costs per-executed-instruction. -* Tracks both "mana" (aka L2 gas) and "data availability" gas. +* Tracks both L2 gas (computation) and DA gas (data availability). * Supports nested contract calls and conditional error recovery. * Manages access to public state, L1↔L2 messages, public logs, and some limited private state. * Finalizes state updates initiated during private execution. diff --git a/yarn-project/simulator/docs/avm/gas.md b/yarn-project/simulator/docs/avm/gas.md index 43171a8f5f7a..b93d75454a1a 100644 --- a/yarn-project/simulator/docs/avm/gas.md +++ b/yarn-project/simulator/docs/avm/gas.md @@ -1,10 +1,10 @@ # Gas Metering -The AVM tracks gas consumption across two dimensions: **L2 gas** (execution costs, also called **mana**) and **DA gas** (data availability costs). +The AVM tracks gas consumption across two dimensions: **L2 gas** (execution costs) and **DA gas** (data availability costs). Note that L2 gas is _not_ the same as mana: mana is the higher-level unit of account that incorporates L2 gas, DA gas, and L1 gas costs together. ## Gas Dimensions -* **L2 Gas** (mana): roughly represents the computational cost of executing (and especially proving) operations. +* **L2 Gas**: roughly represents the computational cost of executing (and especially proving) operations. * **DA Gas**: represents the cost of publishing data to Layer 1 for data availability. This includes: - State updates that must be published to L1 - Emitting logs