This repository has been archived by the owner on Nov 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtracing.mini
118 lines (103 loc) · 2.54 KB
/
tracing.mini
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
//
// Copyright 2021, Offchain Labs, Inc. All rights reserved.
//
use output::outbox_getEvmTracer;
use output::outbox_setEvmTracer;
use std::bytearray::ByteArray;
use std::bytearray::bytearray_new;
use std::stack::Stack;
use std::stack::stack_new;
use std::stack::stack_push;
use std::stack::stack_pop;
type EvmTracer = struct {
recordStack: Stack,
}
public impure func evmTracer_clear() {
outbox_setEvmTracer(evmTracer_new());
}
public func evmTracer_new() -> EvmTracer {
return struct {
recordStack: stack_new(),
};
}
public impure func evmTracer_emit() {
let val = unsafecast<any>(());
let theStack = outbox_getEvmTracer().recordStack;
loop {
if let Some(res) = stack_pop(theStack) {
let (us, item) = res;
theStack = us;
val = (item, val);
} else {
asm((20000, val),) { debugprint };
return;
}
}
}
public impure func evmTracer_emitAndClear() {
evmTracer_emit();
evmTracer_clear();
}
public impure func evmTracer_push(typecode: uint, item: any) {
let oldTracer = outbox_getEvmTracer();
outbox_setEvmTracer(oldTracer with {
recordStack: stack_push(oldTracer.recordStack, (typecode, item))
});
}
public impure func evmTracer_pushCall(
callType: uint,
calldata: ByteArray,
callvalue: uint,
from: address,
to: address,
gas: uint,
gasPrice: uint,
) {
evmTracer_push(
const::TraceEvent_call,
(callType, calldata, callvalue, from, to, gas, gasPrice, ~0),
);
}
public impure func evmTracer_pushReturnRevert(
resultCode: uint,
returndata: ByteArray,
gasUsed: uint,
) {
evmTracer_push(
const::TraceEvent_returnOrRevert,
(resultCode, returndata, gasUsed, ~0),
);
}
public impure func evmTracer_pushCallAndResultNoExecution(
callType: uint,
calldata: ByteArray,
callvalue: uint,
from: address,
to: address,
gas: uint,
gasPrice: uint,
resultCode: uint,
) {
evmTracer_pushCall(callType, calldata, callvalue, from, to, gas, gasPrice);
evmTracer_pushReturnRevert(resultCode, bytearray_new(0), 0);
}
public impure func evmTracer_pushCreate(
code: ByteArray,
addr: address,
) {
evmTracer_push(
const::TraceEvent_create,
(code, addr, ~0),
);
}
public impure func evmTracer_pushCreate2(
code: ByteArray,
currentAddr: address,
salt: uint,
createdAddr: address,
) {
evmTracer_push(
const::TraceEvent_create2,
(code, currentAddr, salt, createdAddr, ~0),
);
}