anvil_zksync_core/node/
call_error_tracer.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
use once_cell::sync::OnceCell;
use std::sync::Arc;
use zksync_multivm::interface::storage::WriteStorage;
use zksync_multivm::interface::tracer::VmExecutionStopReason;
use zksync_multivm::tracers::old::OldTracers;
use zksync_multivm::{
    tracers::dynamic::vm_1_5_0::DynTracer,
    vm_latest::{HistoryMode, SimpleMemory, VmTracer},
    zk_evm_latest::{
        tracing::{AfterDecodingData, VmLocalStateData},
        vm_state::ErrorFlags,
    },
    IntoOldVmTracer,
};

#[derive(Debug, Clone)]
pub struct CallErrorTracer {
    result: Arc<OnceCell<ErrorFlags>>,
}

impl CallErrorTracer {
    pub fn new(result: Arc<OnceCell<ErrorFlags>>) -> Self {
        Self { result }
    }
}

impl<S, H: HistoryMode> DynTracer<S, SimpleMemory<H>> for CallErrorTracer {
    fn after_decoding(
        &mut self,
        _state: VmLocalStateData<'_>,
        data: AfterDecodingData,
        _memory: &SimpleMemory<H>,
    ) {
        // The top frame is processed last, its error flags
        // overwrite any previously observed ones.
        if !data.error_flags_accumulated.is_empty() {
            let _ = self.result.set(data.error_flags_accumulated);
        }
    }
}

impl<S: WriteStorage, H: HistoryMode> VmTracer<S, H> for CallErrorTracer {}

//
// The rest of the file contains stub tracer implementations for older VM versions.
// Reasoning: `CallErrorTracer` needs to implement `MultiVmTracer` to be compatible with era
// abstractions such as `BatchExecutor` and `BatchExecutorFactory`.
//

impl<S, H: zksync_multivm::vm_1_4_1::HistoryMode>
    zksync_multivm::tracers::dynamic::vm_1_4_1::DynTracer<
        S,
        zksync_multivm::vm_1_4_1::SimpleMemory<H>,
    > for CallErrorTracer
{
}

impl<S: WriteStorage, H: zksync_multivm::vm_1_4_1::HistoryMode>
    zksync_multivm::vm_1_4_1::VmTracer<S, H> for CallErrorTracer
{
    fn after_vm_execution(
        &mut self,
        _state: &mut zksync_multivm::vm_1_4_1::ZkSyncVmState<S, H>,
        _bootloader_state: &zksync_multivm::vm_1_4_1::BootloaderState,
        _stop_reason: VmExecutionStopReason,
    ) {
        todo!()
    }
}

impl<S, H: zksync_multivm::vm_1_4_2::HistoryMode>
    zksync_multivm::tracers::dynamic::vm_1_4_1::DynTracer<
        S,
        zksync_multivm::vm_1_4_2::SimpleMemory<H>,
    > for CallErrorTracer
{
}

impl<S: WriteStorage, H: zksync_multivm::vm_1_4_2::HistoryMode>
    zksync_multivm::vm_1_4_2::VmTracer<S, H> for CallErrorTracer
{
    fn after_vm_execution(
        &mut self,
        _state: &mut zksync_multivm::vm_1_4_2::ZkSyncVmState<S, H>,
        _bootloader_state: &zksync_multivm::vm_1_4_2::BootloaderState,
        _stop_reason: VmExecutionStopReason,
    ) {
        todo!()
    }
}

impl<S: WriteStorage, H: zksync_multivm::vm_boojum_integration::HistoryMode>
    zksync_multivm::tracers::dynamic::vm_1_4_0::DynTracer<
        S,
        zksync_multivm::vm_boojum_integration::SimpleMemory<H>,
    > for CallErrorTracer
{
}

impl<S: WriteStorage, H: zksync_multivm::vm_boojum_integration::HistoryMode>
    zksync_multivm::vm_boojum_integration::VmTracer<S, H> for CallErrorTracer
{
    fn after_vm_execution(
        &mut self,
        _state: &mut zksync_multivm::vm_boojum_integration::ZkSyncVmState<S, H>,
        _bootloader_state: &zksync_multivm::vm_boojum_integration::BootloaderState,
        _stop_reason: VmExecutionStopReason,
    ) {
        todo!()
    }
}

impl<S: WriteStorage, H: zksync_multivm::vm_refunds_enhancement::HistoryMode>
    zksync_multivm::tracers::dynamic::vm_1_3_3::DynTracer<
        S,
        zksync_multivm::vm_refunds_enhancement::SimpleMemory<H>,
    > for CallErrorTracer
{
}

impl<S: WriteStorage, H: zksync_multivm::vm_refunds_enhancement::HistoryMode>
    zksync_multivm::vm_refunds_enhancement::VmTracer<S, H> for CallErrorTracer
{
    fn after_vm_execution(
        &mut self,
        _state: &mut zksync_multivm::vm_refunds_enhancement::ZkSyncVmState<S, H>,
        _bootloader_state: &zksync_multivm::vm_refunds_enhancement::BootloaderState,
        _stop_reason: VmExecutionStopReason,
    ) {
        todo!()
    }
}

impl<S: WriteStorage, H: zksync_multivm::vm_virtual_blocks::HistoryMode>
    zksync_multivm::tracers::dynamic::vm_1_3_3::DynTracer<
        S,
        zksync_multivm::vm_virtual_blocks::SimpleMemory<H>,
    > for CallErrorTracer
{
}

impl<H: zksync_multivm::vm_virtual_blocks::HistoryMode>
    zksync_multivm::vm_virtual_blocks::ExecutionEndTracer<H> for CallErrorTracer
{
}

impl<S: WriteStorage, H: zksync_multivm::vm_virtual_blocks::HistoryMode>
    zksync_multivm::vm_virtual_blocks::ExecutionProcessing<S, H> for CallErrorTracer
{
}

impl<S: WriteStorage, H: zksync_multivm::vm_virtual_blocks::HistoryMode>
    zksync_multivm::vm_virtual_blocks::VmTracer<S, H> for CallErrorTracer
{
}

impl IntoOldVmTracer for CallErrorTracer {
    fn old_tracer(&self) -> OldTracers {
        todo!()
    }
}