Skip to content

Commit 50e778a

Browse files
authored
feat: merge-train/avm (#20567)
BEGIN_COMMIT_OVERRIDE docs: fix avm docs - l2 gas is not the same as mana (#20565) docs: simulator readme typos (#19701) fix(avm): alu gadget fuzzer serialisation (#19115) END_COMMIT_OVERRIDE
2 parents a178034 + 6fcc86e commit 50e778a

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

barretenberg/cpp/src/barretenberg/avm_fuzzer/harness/alu.fuzzer.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ struct AluFuzzerInput {
4242
MemoryValue a;
4343
MemoryValue b;
4444
MemoryValue c = MemoryValue::from_tag(MemoryTag::FF, 0); // Placeholder for result
45-
int op_id = 0; // For execution trace alu_op_id
46-
45+
uint16_t op_id = 0; // For execution trace alu_op_id
46+
// We serialise MemoryValues as FF + 1 byte for tag to save 31 bytes per value:
47+
static const size_t size = (3 * (sizeof(FF) + 1)) + sizeof(uint16_t);
4748
// Serialize to buffer
4849
void to_buffer(uint8_t* buffer) const
4950
{
@@ -58,7 +59,7 @@ struct AluFuzzerInput {
5859
buffer += sizeof(FF) + 1;
5960
write_mem_value(buffer, c);
6061
buffer += sizeof(FF) + 1;
61-
serialize::write(buffer, static_cast<uint16_t>(op_id));
62+
serialize::write(buffer, op_id);
6263
}
6364

6465
static AluFuzzerInput from_buffer(const uint8_t* buffer)
@@ -88,11 +89,11 @@ struct AluFuzzerInput {
8889

8990
extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size, size_t max_size, unsigned int seed)
9091
{
91-
if (size < sizeof(AluFuzzerInput)) {
92+
if (size < AluFuzzerInput::size) {
9293
// Initialize with default input
9394
AluFuzzerInput input;
9495
input.to_buffer(data);
95-
return sizeof(AluFuzzerInput);
96+
return AluFuzzerInput::size;
9697
}
9798

9899
std::mt19937_64 rng(seed);
@@ -119,7 +120,6 @@ extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size, size_t max
119120

120121
auto random_mem_value_from_tag = [&rng](MemoryTag tag) -> MemoryValue {
121122
std::uniform_int_distribution<uint64_t> dist(0, std::numeric_limits<uint64_t>::max());
122-
// TODO(MW): Use array?
123123
FF value = FF(dist(rng), dist(rng), dist(rng), dist(rng));
124124
// Do we want the option of making "invalid tag" values, where the value is out of range for the tag?
125125
// 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
135135
// Deserialize current input
136136
AluFuzzerInput input = AluFuzzerInput::from_buffer(data);
137137

138-
// Choose random ALU operation
138+
// Choose random ALU operation (11 possible operations with op_id = 2^index)
139139
std::uniform_int_distribution<int> dist(0, 11);
140-
input.op_id = 1 << dist(rng);
140+
input.op_id = static_cast<uint16_t>(1 << dist(rng));
141141

142142
// Choose test case (TODO(MW): what else do we want here?)
143143
dist = std::uniform_int_distribution<int>(0, 4);
@@ -187,18 +187,18 @@ extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size, size_t max
187187
// Serialize mutated input back to buffer
188188
input.to_buffer(data);
189189

190-
if (max_size > sizeof(AluFuzzerInput)) {
191-
return sizeof(AluFuzzerInput);
190+
if (max_size > AluFuzzerInput::size) {
191+
return AluFuzzerInput::size;
192192
}
193193

194-
return sizeof(AluFuzzerInput);
194+
return AluFuzzerInput::size;
195195
}
196196

197197
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
198198
{
199199
using bb::avm2::MemoryValue;
200200

201-
if (size < sizeof(AluFuzzerInput)) {
201+
if (size < AluFuzzerInput::size) {
202202
info("Input size too small");
203203
return 0;
204204
}

yarn-project/simulator/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ It's able to simulate three different types of functions:
1212

1313
Private functions are simulated and proved client-side, and verified client-side in the private kernel circuit.
1414

15-
The public inputs of private functions is defined [here](../stdlib/src/structs/private_circuit_public_inputs.ts).
15+
The public inputs of private functions are defined [here](../stdlib/src/structs/private_circuit_public_inputs.ts).
1616

1717
They are run with the assistance of a DB oracle that provides any private data requested by the function.
1818

@@ -22,17 +22,17 @@ Private functions can call another private function, and can request to call a p
2222

2323
Public functions are simulated and proved on the sequencer side, and verified by the public kernel circuit.
2424

25-
The public inputs of public functions is defined [here](../stdlib/src/structs/avm/avm_circuit_public_inputs.ts).
25+
The public inputs of public functions are defined [here](../stdlib/src/structs/avm/avm_circuit_public_inputs.ts).
2626

2727
They are run with the assistance of an oracle that provides any value read from the public state tree.
2828

29-
Public functions can call other public function, but no private functions.
29+
Public functions can call other public functions, but cannot call private functions.
3030

3131
See the specifications of the [Aztec Virtual Machine (AVM) for public execution](./docs/avm/index.md).
3232

3333
### Unconstrained Functions
3434

35-
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
35+
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.
3636
They are not proved, and are simulated client-side.
3737

3838
They are run with the assistance of a DB oracle that provides any private data requested by the function.

yarn-project/simulator/docs/avm/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public execution requests.
3939
The AVM:
4040
* Executes specified public bytecode, instruction by instruction, given some arguments.
4141
* Meters execution by tracking gas costs per-executed-instruction.
42-
* Tracks both "mana" (aka L2 gas) and "data availability" gas.
42+
* Tracks both L2 gas (computation) and DA gas (data availability).
4343
* Supports nested contract calls and conditional error recovery.
4444
* Manages access to public state, L1↔L2 messages, public logs, and some limited private state.
4545
* Finalizes state updates initiated during private execution.

yarn-project/simulator/docs/avm/gas.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Gas Metering
22

3-
The AVM tracks gas consumption across two dimensions: **L2 gas** (execution costs, also called **mana**) and **DA gas** (data availability costs).
3+
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.
44

55
## Gas Dimensions
66

7-
* **L2 Gas** (mana): roughly represents the computational cost of executing (and especially proving) operations.
7+
* **L2 Gas**: roughly represents the computational cost of executing (and especially proving) operations.
88
* **DA Gas**: represents the cost of publishing data to Layer 1 for data availability. This includes:
99
- State updates that must be published to L1
1010
- Emitting logs

0 commit comments

Comments
 (0)