diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/events/bytecode_events.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/events/bytecode_events.hpp index 11c2e3877678..1920128b12ec 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/events/bytecode_events.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/events/bytecode_events.hpp @@ -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> bytecode; std::optional error; // To be used with deduplicating event emitters. - using Key = std::tuple; + using Key = std::tuple; Key get_key() const { return { bytecode_id, pc }; } }; diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/events/context_events.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/events/context_events.hpp index 24927022d3e1..89fb1ba349f1 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/events/context_events.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/events/context_events.hpp @@ -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; @@ -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; diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/bytecode_manager.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/bytecode_manager.cpp index 80ee05a504b5..e259b46f05af 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/bytecode_manager.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/bytecode_manager.cpp @@ -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> bytecode_ptr, - uint32_t pc) + PC pc) { BB_BENCH_NAME("TxBytecodeManager::read_instruction"); diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/bytecode_manager.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/bytecode_manager.hpp index 539c174227ec..6de82522f004 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/bytecode_manager.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/bytecode_manager.hpp @@ -48,10 +48,10 @@ class TxBytecodeManager : public TxBytecodeManagerInterface { BytecodeId get_bytecode(const AztecAddress& address) override; std::shared_ptr> 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> bytecode_ptr, - uint32_t pc) override; + PC pc) override; private: ContractDBInterface& contract_db; @@ -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"); diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/context.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/context.hpp index 95f2c0f824d1..a3dc9be44fa8 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/context.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/context.hpp @@ -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; } @@ -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; diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.cpp index 761ede9b9547..e7214cf3f619 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.cpp @@ -1771,7 +1771,7 @@ EnqueuedCallResult Execution::execute(std::unique_ptr enqueued instruction = context.get_bytecode_manager().read_instruction(pc); debug("@", pc, " ", instruction.to_string()); - context.set_next_pc(pc + static_cast(instruction.size_in_bytes())); + context.set_next_pc(pc + static_cast(instruction.size_in_bytes())); // next_pc is overwritten in dispatch_opcode() for JUMP, JUMPI, INTERNALCALL, and INTERNALRETURN. // Resolve the operands. diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.hpp index 0e6fcfa514c7..d65a0ae67713 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.hpp @@ -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 halting_message; // If reverted. }; diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.test.cpp index 5b7ad0ec7fe3..b94506eef02c 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.test.cpp @@ -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 internal_call_stack_manager; ON_CALL(context, get_internal_call_stack_manager).WillByDefault(ReturnRef(internal_call_stack_manager)); diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/interfaces/bytecode_manager.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/interfaces/bytecode_manager.hpp index 1e6e60f70e40..440f03b5d8e6 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/interfaces/bytecode_manager.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/interfaces/bytecode_manager.hpp @@ -22,11 +22,11 @@ class TxBytecodeManagerInterface { virtual std::shared_ptr> 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> bytecode_ptr, - uint32_t pc) = 0; + PC pc) = 0; }; // Manages the bytecode of a single nested call. Therefore always the same bytecode. @@ -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. diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/interfaces/call_stack_metadata_collector.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/interfaces/call_stack_metadata_collector.hpp index e0701bfddea1..e4dc894e623e 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/interfaces/call_stack_metadata_collector.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/interfaces/call_stack_metadata_collector.hpp @@ -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& halting_message, const ReturnDataProvider& return_data_provider, const InternalCallStackProvider& internal_call_stack_provider) = 0; diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/interfaces/context.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/interfaces/context.hpp index d9f60dd71d52..8696eeea4a6c 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/interfaces/context.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/interfaces/context.hpp @@ -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; diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/call_stack_metadata_collector.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/call_stack_metadata_collector.cpp index 6a1e8f633b16..8ba8d0f5b9b5 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/call_stack_metadata_collector.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/call_stack_metadata_collector.cpp @@ -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) @@ -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& halting_message, const ReturnDataProvider& return_data_provider, const InternalCallStackProvider& internal_call_stack_provider) diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/call_stack_metadata_collector.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/call_stack_metadata_collector.hpp index b66fd5895646..7e8eb6791b3e 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/call_stack_metadata_collector.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/call_stack_metadata_collector.hpp @@ -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& halting_message, const ReturnDataProvider& return_data_provider, const InternalCallStackProvider& internal_call_stack_provider) override; @@ -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&, const ReturnDataProvider&, const InternalCallStackProvider&) override diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/call_stack_metadata_collector.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/call_stack_metadata_collector.test.cpp index 863cadb41048..92e65c9e7bf8 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/call_stack_metadata_collector.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/call_stack_metadata_collector.test.cpp @@ -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 calldata = { FF(0xabcd), FF(0xef01) }; std::vector return_data = { FF(0x5678), FF(0x9abc) }; diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/standalone/hybrid_execution.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/standalone/hybrid_execution.cpp index 82edd369dc88..7c97e540b9c2 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/standalone/hybrid_execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/standalone/hybrid_execution.cpp @@ -51,7 +51,7 @@ EnqueuedCallResult HybridExecution::execute(std::unique_ptr en Instruction instruction = context.get_bytecode_manager().read_instruction(pc); debug("@", pc, " ", instruction.to_string()); - context.set_next_pc(pc + static_cast(instruction.size_in_bytes())); + context.set_next_pc(pc + static_cast(instruction.size_in_bytes())); //// Temporality group 4 starts //// diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/standalone/pure_bytecode_manager.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/standalone/pure_bytecode_manager.cpp index 514145741977..bedddc8dac0c 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/standalone/pure_bytecode_manager.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/standalone/pure_bytecode_manager.cpp @@ -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. @@ -95,7 +95,7 @@ Instruction PureTxBytecodeManager::read_instruction(const BytecodeId& bytecode_i Instruction PureTxBytecodeManager::read_instruction(const BytecodeId&, std::shared_ptr> bytecode_ptr, - uint32_t pc) + PC pc) { BB_BENCH_NAME("TxBytecodeManager::read_instruction"); diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/standalone/pure_bytecode_manager.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/standalone/pure_bytecode_manager.hpp index 5b10d6f9be1a..df86be8e5472 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/standalone/pure_bytecode_manager.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/standalone/pure_bytecode_manager.hpp @@ -31,10 +31,10 @@ class PureTxBytecodeManager : public TxBytecodeManagerInterface { BytecodeId get_bytecode(const AztecAddress& address) override; std::shared_ptr> 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> bytecode_ptr, - uint32_t pc) override; + PC pc) override; private: ContractDBInterface& contract_db; @@ -42,7 +42,7 @@ class PureTxBytecodeManager : public TxBytecodeManagerInterface { unordered_flat_map>> bytecodes; unordered_flat_set retrieved_class_ids; - using InstructionIdentifier = std::tuple; + using InstructionIdentifier = std::tuple; unordered_flat_map instruction_cache; }; diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_bytecode_manager.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_bytecode_manager.hpp index 5f4b843a505f..a151ee7e9706 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_bytecode_manager.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_bytecode_manager.hpp @@ -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, get_retrieved_bytecode_id, (), (override)); }; diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_call_stack_metadata_collector.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_call_stack_metadata_collector.hpp index ff9f85bc7b2e..4c16feb4a59a 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_call_stack_metadata_collector.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_call_stack_metadata_collector.hpp @@ -16,7 +16,7 @@ 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), @@ -24,7 +24,7 @@ class MockCallStackMetadataCollector : public CallStackMetadataCollectorInterfac MOCK_METHOD(void, notify_exit_call, (bool success, - uint32_t pc, + PC pc, const std::optional& halting_message, const ReturnDataProvider& return_data_provider, const InternalCallStackProvider& internal_call_stack_provider),