Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -43,14 +43,14 @@ struct BytecodeRetrievalEvent {

struct InstructionFetchingEvent {
BytecodeId bytecode_id;
uint32_t pc;
PC pc;
// TODO: Do we want to have a dep on Instruction here or do we redefine what we need?
Instruction instruction;
std::shared_ptr<std::vector<uint8_t>> bytecode;
std::optional<InstrDeserializationEventError> error;

// To be used with deduplicating event emitters.
using Key = std::tuple<BytecodeId, uint32_t>;
using Key = std::tuple<BytecodeId, PC>;
Key get_key() const { return { bytecode_id, pc }; }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct ContextEvent {
uint32_t last_child_id = 0;

// State
uint32_t pc = 0;
PC pc = 0;
AztecAddress msg_sender = 0;
AztecAddress contract_addr = 0;
BytecodeId bytecode_id = 0;
Expand Down Expand Up @@ -59,7 +59,7 @@ struct ContextStackEvent {
uint32_t entered_context_id = 0;

// State
uint32_t next_pc = 0;
PC next_pc = 0;
AztecAddress msg_sender = 0;
AztecAddress contract_addr = 0;
BytecodeId bytecode_id = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ BytecodeId TxBytecodeManager::get_bytecode(const AztecAddress& address)
return bytecode_id;
}

Instruction TxBytecodeManager::read_instruction(const BytecodeId& bytecode_id, uint32_t pc)
Instruction TxBytecodeManager::read_instruction(const BytecodeId& bytecode_id, PC pc)
{
return read_instruction(bytecode_id, get_bytecode_data(bytecode_id), pc);
}

Instruction TxBytecodeManager::read_instruction(const BytecodeId& bytecode_id,
std::shared_ptr<std::vector<uint8_t>> bytecode_ptr,
uint32_t pc)
PC pc)
{
BB_BENCH_NAME("TxBytecodeManager::read_instruction");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class TxBytecodeManager : public TxBytecodeManagerInterface {

BytecodeId get_bytecode(const AztecAddress& address) override;
std::shared_ptr<std::vector<uint8_t>> get_bytecode_data(const BytecodeId& bytecode_id) override;
Instruction read_instruction(const BytecodeId& bytecode_id, uint32_t pc) override;
Instruction read_instruction(const BytecodeId& bytecode_id, PC pc) override;
Instruction read_instruction(const BytecodeId& bytecode_id,
std::shared_ptr<std::vector<uint8_t>> bytecode_ptr,
uint32_t pc) override;
PC pc) override;

private:
ContractDBInterface& contract_db;
Expand All @@ -76,7 +76,7 @@ class BytecodeManager : public BytecodeManagerInterface {
, tx_bytecode_manager(tx_bytecode_manager)
{}

Instruction read_instruction(uint32_t pc) override
Instruction read_instruction(PC pc) override
{
// We only assert in debug mode because this is in the hot path of the execution.
BB_ASSERT_DEBUG(bytecode_id.has_value(), "Bytecode not retrieved before call to read_instruction");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ class BaseContext : public ContextInterface {
return *internal_call_stack_manager;
}

uint32_t get_pc() const override { return pc; }
void set_pc(uint32_t new_pc) override { pc = new_pc; }
uint32_t get_next_pc() const override { return next_pc; }
void set_next_pc(uint32_t new_next_pc) override { next_pc = new_next_pc; }
PC get_pc() const override { return pc; }
void set_pc(PC new_pc) override { pc = new_pc; }
PC get_next_pc() const override { return next_pc; }
void set_next_pc(PC new_next_pc) override { next_pc = new_next_pc; }
bool halted() const override { return has_halted; }
void halt() override { has_halted = true; }

Expand Down Expand Up @@ -142,8 +142,8 @@ class BaseContext : public ContextInterface {
uint32_t context_id;

// Machine state.
uint32_t pc = 0;
uint32_t next_pc = 0;
PC pc = 0;
PC next_pc = 0;
bool has_halted = false;
Gas gas_used;
Gas gas_limit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1771,7 +1771,7 @@ EnqueuedCallResult Execution::execute(std::unique_ptr<ContextInterface> enqueued
instruction = context.get_bytecode_manager().read_instruction(pc);

debug("@", pc, " ", instruction.to_string());
context.set_next_pc(pc + static_cast<uint32_t>(instruction.size_in_bytes()));
context.set_next_pc(pc + static_cast<PC>(instruction.size_in_bytes()));
// next_pc is overwritten in dispatch_opcode() for JUMP, JUMPI, INTERNALCALL, and INTERNALRETURN.

// Resolve the operands.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class Execution : public ExecutionInterface {
MemoryAddress rd_size;
Gas gas_used;
bool success;
uint32_t halting_pc = 0; // PC at which the context halted.
PC halting_pc = 0; // PC at which the context halted.
std::optional<std::string> halting_message; // If reverted.
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@ TEST_F(ExecutionSimulationTest, ExternalCallStaticnessPropagation)

TEST_F(ExecutionSimulationTest, InternalCall)
{
uint32_t pc = 100; // This is the pc of the current call.
uint32_t return_pc = 500; // This is next pc that we should return to after the internal call.
uint32_t pc_loc = 11; // This is the pc of the internal call
PC pc = 100; // This is the pc of the current call.
PC return_pc = 500; // This is next pc that we should return to after the internal call.
PC pc_loc = 11; // This is the pc of the internal call

NiceMock<MockInternalCallStackManager> internal_call_stack_manager;
ON_CALL(context, get_internal_call_stack_manager).WillByDefault(ReturnRef(internal_call_stack_manager));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class TxBytecodeManagerInterface {
virtual std::shared_ptr<std::vector<uint8_t>> get_bytecode_data(const BytecodeId& bytecode_id) = 0;
// Retrieves an instruction and decomposes it if needed.
// This version of read_instruction might retrieve the bytecode (and generate an event) if not already done.
virtual Instruction read_instruction(const BytecodeId& bytecode_id, uint32_t pc) = 0;
virtual Instruction read_instruction(const BytecodeId& bytecode_id, PC pc) = 0;
// This version of read_instruction does not retrieve the bytecode.
virtual Instruction read_instruction(const BytecodeId& bytecode_id,
std::shared_ptr<std::vector<uint8_t>> bytecode_ptr,
uint32_t pc) = 0;
PC pc) = 0;
};

// Manages the bytecode of a single nested call. Therefore always the same bytecode.
Expand All @@ -35,7 +35,7 @@ class BytecodeManagerInterface {
public:
virtual ~BytecodeManagerInterface() = default;

virtual Instruction read_instruction(uint32_t pc) = 0;
virtual Instruction read_instruction(PC pc) = 0;

// Returns the id of the current bytecode. Tries to fetch it if not already done.
// Throws BytecodeNotFoundError if contract does not exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class CallStackMetadataCollectorInterface {

virtual void set_phase(CoarseTransactionPhase phase) = 0;
virtual void notify_enter_call(const AztecAddress& contract_address,
uint32_t caller_pc,
PC caller_pc,
const CalldataProvider& calldata_provider,
bool is_static_call,
const Gas& gas_limit) = 0;
virtual void notify_exit_call(bool success,
uint32_t pc,
PC pc,
const std::optional<std::string>& halting_message,
const ReturnDataProvider& return_data_provider,
const InternalCallStackProvider& internal_call_stack_provider) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class ContextInterface {
virtual const MemoryInterface& get_memory() const = 0;
virtual BytecodeManagerInterface& get_bytecode_manager() = 0;
virtual InternalCallStackManagerInterface& get_internal_call_stack_manager() = 0;
virtual uint32_t get_pc() const = 0;
virtual void set_pc(uint32_t new_pc) = 0;
virtual uint32_t get_next_pc() const = 0;
virtual void set_next_pc(uint32_t new_next_pc) = 0;
virtual PC get_pc() const = 0;
virtual void set_pc(PC new_pc) = 0;
virtual PC get_next_pc() const = 0;
virtual void set_next_pc(PC new_next_pc) = 0;
virtual bool halted() const = 0;
virtual void halt() = 0;
virtual uint32_t get_context_id() const = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bool CallStackMetadataCollector::should_skip_collection() const
}

void CallStackMetadataCollector::notify_enter_call(const AztecAddress& contract_address,
uint32_t caller_pc,
PC caller_pc,
const CalldataProvider& calldata_provider,
bool is_static_call,
const Gas& gas_limit)
Expand Down Expand Up @@ -60,7 +60,7 @@ void CallStackMetadataCollector::notify_enter_call(const AztecAddress& contract_
}

void CallStackMetadataCollector::notify_exit_call(bool success,
uint32_t pc,
PC pc,
const std::optional<std::string>& halting_message,
const ReturnDataProvider& return_data_provider,
const InternalCallStackProvider& internal_call_stack_provider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class CallStackMetadataCollector : public CallStackMetadataCollectorInterface {

void set_phase(CoarseTransactionPhase phase) override;
void notify_enter_call(const AztecAddress& contract_address,
uint32_t caller_pc,
PC caller_pc,
const CalldataProvider& calldata_provider,
bool is_static_call,
const Gas& gas_limit) override;
void notify_exit_call(bool success,
uint32_t pc,
PC pc,
const std::optional<std::string>& halting_message,
const ReturnDataProvider& return_data_provider,
const InternalCallStackProvider& internal_call_stack_provider) override;
Expand Down Expand Up @@ -62,9 +62,9 @@ InternalCallStackProvider make_internal_call_stack_provider(
class NoopCallStackMetadataCollector : public CallStackMetadataCollectorInterface {
public:
void set_phase(CoarseTransactionPhase) override {}
void notify_enter_call(const AztecAddress&, uint32_t, const CalldataProvider&, bool, const Gas&) override {}
void notify_enter_call(const AztecAddress&, PC, const CalldataProvider&, bool, const Gas&) override {}
void notify_exit_call(bool,
uint32_t,
PC,
const std::optional<std::string>&,
const ReturnDataProvider&,
const InternalCallStackProvider&) override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ TEST(CallStackMetadataCollectorTest, SingleCallEnterAndExit)
{
CallStackMetadataCollector collector(limits);
AztecAddress contract_addr(0x1234);
uint32_t caller_pc = 100;
uint32_t exit_pc = 200;
PC caller_pc = 100;
PC exit_pc = 200;
Gas gas_limit{ 1000, 2000 };
std::vector<FF> calldata = { FF(0xabcd), FF(0xef01) };
std::vector<FF> return_data = { FF(0x5678), FF(0x9abc) };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ EnqueuedCallResult HybridExecution::execute(std::unique_ptr<ContextInterface> en
Instruction instruction = context.get_bytecode_manager().read_instruction(pc);

debug("@", pc, " ", instruction.to_string());
context.set_next_pc(pc + static_cast<uint32_t>(instruction.size_in_bytes()));
context.set_next_pc(pc + static_cast<PC>(instruction.size_in_bytes()));

//// Temporality group 4 starts ////

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ BytecodeId PureTxBytecodeManager::get_bytecode(const AztecAddress& address)
return bytecode_id;
}

Instruction PureTxBytecodeManager::read_instruction(const BytecodeId& bytecode_id, uint32_t pc)
Instruction PureTxBytecodeManager::read_instruction(const BytecodeId& bytecode_id, PC pc)
{
// The corresponding bytecode is already stored in the cache if we call this routine. This is safe-guarded by the
// fact that it is added in the cache when we retrieve the bytecode_id.
Expand All @@ -95,7 +95,7 @@ Instruction PureTxBytecodeManager::read_instruction(const BytecodeId& bytecode_i

Instruction PureTxBytecodeManager::read_instruction(const BytecodeId&,
std::shared_ptr<std::vector<uint8_t>> bytecode_ptr,
uint32_t pc)
PC pc)
{
BB_BENCH_NAME("TxBytecodeManager::read_instruction");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ class PureTxBytecodeManager : public TxBytecodeManagerInterface {

BytecodeId get_bytecode(const AztecAddress& address) override;
std::shared_ptr<std::vector<uint8_t>> get_bytecode_data(const BytecodeId& bytecode_id) override;
Instruction read_instruction(const BytecodeId& bytecode_id, uint32_t pc) override;
Instruction read_instruction(const BytecodeId& bytecode_id, PC pc) override;
Instruction read_instruction(const BytecodeId& bytecode_id,
std::shared_ptr<std::vector<uint8_t>> bytecode_ptr,
uint32_t pc) override;
PC pc) override;

private:
ContractDBInterface& contract_db;
ContractInstanceManagerInterface& contract_instance_manager;

unordered_flat_map<BytecodeId, std::shared_ptr<std::vector<uint8_t>>> bytecodes;
unordered_flat_set<ContractClassId> retrieved_class_ids;
using InstructionIdentifier = std::tuple</*bytecode_vector*/ void*, /*pc*/ uint32_t>;
using InstructionIdentifier = std::tuple</*bytecode_vector*/ void*, /*pc*/ PC>;
unordered_flat_map<InstructionIdentifier, Instruction> instruction_cache;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MockBytecodeManager : public BytecodeManagerInterface {
MockBytecodeManager();
~MockBytecodeManager() override;

MOCK_METHOD(Instruction, read_instruction, (uint32_t pc), (override));
MOCK_METHOD(Instruction, read_instruction, (PC pc), (override));
MOCK_METHOD(BytecodeId, get_bytecode_id, (), (override));
MOCK_METHOD(std::optional<BytecodeId>, get_retrieved_bytecode_id, (), (override));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class MockCallStackMetadataCollector : public CallStackMetadataCollectorInterfac
MOCK_METHOD(void,
notify_enter_call,
(const AztecAddress& contract_address,
uint32_t caller_pc,
PC caller_pc,
const CalldataProvider& calldata_provider,
bool is_static_call,
const Gas& gas_limit),
(override));
MOCK_METHOD(void,
notify_exit_call,
(bool success,
uint32_t pc,
PC pc,
const std::optional<std::string>& halting_message,
const ReturnDataProvider& return_data_provider,
const InternalCallStackProvider& internal_call_stack_provider),
Expand Down
Loading