Skip to content

Commit

Permalink
9131: Addressing review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmon committed Nov 19, 2024
1 parent 66d0f63 commit 79b2573
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 146 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "barretenberg/vm/avm/trace/common.hpp"
#include "barretenberg/vm/avm/trace/errors.hpp"
#include "barretenberg/vm/avm/trace/mem_trace.hpp"
#include <cstdint>

Expand Down
12 changes: 0 additions & 12 deletions barretenberg/cpp/src/barretenberg/vm/avm/trace/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ enum class AvmMemoryTag : uint32_t {

static const uint32_t MAX_MEM_TAG = MEM_TAG_U128;

enum class AvmError : uint32_t {
NO_ERROR,
TAG_ERROR,
ADDR_RES_TAG_ERROR,
REL_ADDR_OUT_OF_RANGE,
DIV_ZERO,
PARSING_ERROR,
ENV_VAR_UNKNOWN,
CONTRACT_INST_MEM_UNKNOWN,
RADIX_OUT_OF_BOUNDS,
};

static const size_t NUM_MEM_SPACES = 256;
static const uint8_t INTERNAL_CALL_SPACE_ID = 255;
static const uint32_t MAX_SIZE_INTERNAL_STACK = 1 << 16;
Expand Down
19 changes: 19 additions & 0 deletions barretenberg/cpp/src/barretenberg/vm/avm/trace/errors.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <cstdint>

namespace bb::avm_trace {

enum class AvmError : uint32_t {
NO_ERROR,
TAG_ERROR,
ADDR_RES_TAG_ERROR,
REL_ADDR_OUT_OF_RANGE,
DIV_ZERO,
PARSING_ERROR,
ENV_VAR_UNKNOWN,
CONTRACT_INST_MEM_UNKNOWN,
RADIX_OUT_OF_BOUNDS,
};

} // namespace bb::avm_trace
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ std::string to_name(AvmError error)
}
}

bool is_valid(AvmError error)
bool is_ok(AvmError error)
{
return error == AvmError::NO_ERROR;
}
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/vm/avm/trace/helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ std::string to_hex(bb::avm_trace::AvmMemoryTag tag);
std::string to_name(bb::avm_trace::AvmMemoryTag tag);

std::string to_name(AvmError error);
bool is_valid(AvmError error);
bool is_ok(AvmError error);

// Mutate the inputs
void inject_end_gas_values(VmPublicInputs& public_inputs, std::vector<Row>& trace);
Expand Down
258 changes: 129 additions & 129 deletions barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions yarn-project/simulator/src/avm/avm_memory_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ export class TaggedMemory implements TaggedMemoryInterface {
this._mem = [];
}

public getMaxMemorySize(): number {
return TaggedMemory.MAX_MEMORY_SIZE;
}

/** Returns a MeteredTaggedMemory instance to track the number of reads and writes if TRACK_MEMORY_ACCESSES is set. */
public track(type: string = 'instruction'): TaggedMemoryInterface {
return TaggedMemory.TRACK_MEMORY_ACCESSES ? new MeteredTaggedMemory(this, type) : this;
Expand Down Expand Up @@ -475,6 +479,10 @@ export class MeteredTaggedMemory implements TaggedMemoryInterface {
}
}

public getMaxMemorySize(): number {
return this.wrapped.getMaxMemorySize();
}

public track(type: string = 'instruction'): MeteredTaggedMemory {
return new MeteredTaggedMemory(this.wrapped, type);
}
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/simulator/src/avm/opcodes/addressing_mode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { strict as assert } from 'assert';
import { maxUint32 } from 'viem';

import { type TaggedMemoryInterface } from '../avm_memory_types.js';
import { AddressOutOfRangeError } from '../errors.js';
Expand Down Expand Up @@ -67,7 +66,7 @@ export class Addressing {
mem.checkIsValidMemoryOffsetTag(0);
const baseAddr = Number(mem.get(0).toBigInt());
resolved[i] += baseAddr;
if (resolved[i] > maxUint32) {
if (resolved[i] >= mem.getMaxMemorySize()) {
throw new AddressOutOfRangeError(baseAddr, offset);
}
}
Expand Down

0 comments on commit 79b2573

Please sign in to comment.