|
| 1 | +use core::ops::ControlFlow; |
| 2 | + |
| 3 | +use vm_core::{Word, mast::CallNode}; |
| 4 | + |
| 5 | +use super::{MainTraceFragmentGenerator, TraceRowType, trace_builder::OperationTraceConfig}; |
| 6 | + |
| 7 | +impl MainTraceFragmentGenerator { |
| 8 | + /// Adds a trace row for a CALL/SYSCALL operation (start or end) to the main trace fragment. |
| 9 | + /// |
| 10 | + /// This method populates the system, decoder, and stack columns for a single trace row |
| 11 | + /// corresponding to either the start or end of a CALL/SYSCALL block execution. It uses the |
| 12 | + /// shared control flow trace building infrastructure. |
| 13 | + pub fn add_call_trace_row( |
| 14 | + &mut self, |
| 15 | + call_node: &CallNode, |
| 16 | + program: &vm_core::mast::MastForest, |
| 17 | + trace_type: TraceRowType, |
| 18 | + ) -> ControlFlow<()> { |
| 19 | + // For CALL/SYSCALL operations, the hasher state in start operations contains the callee |
| 20 | + // hash in the first half, and zeros in the second half (since CALL only has one |
| 21 | + // child) |
| 22 | + let callee_hash: Word = program |
| 23 | + .get_node_by_id(call_node.callee()) |
| 24 | + .expect("callee should exist") |
| 25 | + .digest() |
| 26 | + .into(); |
| 27 | + let zero_hash: Word = [vm_core::ZERO; 4]; |
| 28 | + |
| 29 | + let config = OperationTraceConfig { |
| 30 | + start_opcode: if call_node.is_syscall() { |
| 31 | + vm_core::Operation::SysCall.op_code() |
| 32 | + } else { |
| 33 | + vm_core::Operation::Call.op_code() |
| 34 | + }, |
| 35 | + start_hasher_state: (callee_hash, zero_hash), |
| 36 | + end_node_digest: call_node.digest().into(), |
| 37 | + }; |
| 38 | + |
| 39 | + self.add_control_flow_trace_row(config, trace_type) |
| 40 | + } |
| 41 | + |
| 42 | + /// Adds a trace row for the start of a CALL/SYSCALL operation. |
| 43 | + /// |
| 44 | + /// This is a convenience method that calls `add_call_trace_row` with `TraceRowType::Start`. |
| 45 | + pub fn add_call_start_trace_row( |
| 46 | + &mut self, |
| 47 | + call_node: &CallNode, |
| 48 | + program: &vm_core::mast::MastForest, |
| 49 | + ) -> ControlFlow<()> { |
| 50 | + self.add_call_trace_row(call_node, program, TraceRowType::Start) |
| 51 | + } |
| 52 | + |
| 53 | + /// Adds a trace row for the end of a CALL/SYSCALL operation. |
| 54 | + /// |
| 55 | + /// This is a convenience method that calls `add_call_trace_row` with `TraceRowType::End`. |
| 56 | + pub fn add_call_end_trace_row( |
| 57 | + &mut self, |
| 58 | + call_node: &CallNode, |
| 59 | + program: &vm_core::mast::MastForest, |
| 60 | + ) -> ControlFlow<()> { |
| 61 | + self.add_call_trace_row(call_node, program, TraceRowType::End) |
| 62 | + } |
| 63 | +} |
0 commit comments