Skip to content

Commit 4d61d86

Browse files
Merge pull request #26 from OffchainLabs/hostio-tracer
Hostio tracer
2 parents 69c097f + 27113b8 commit 4d61d86

5 files changed

Lines changed: 37 additions & 0 deletions

File tree

core/vm/logger.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ type EVMLogger interface {
3333
CaptureArbitrumStorageGet(key common.Hash, depth int, before bool)
3434
CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool)
3535

36+
// Stylus: capture hostio invocation
37+
CaptureStylusHostio(name string, args, outs []byte, ink uint64)
38+
3639
// Transaction level
3740
CaptureTxStart(gasLimit uint64)
3841
CaptureTxEnd(restGas uint64)

eth/tracers/js/tracer_arbitrum.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,20 @@ func (jst *jsTracer) CaptureArbitrumTransfer(
5555

5656
func (*jsTracer) CaptureArbitrumStorageGet(key common.Hash, depth int, before bool) {}
5757
func (*jsTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {}
58+
59+
func (jst *jsTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {
60+
hostio, ok := goja.AssertFunction(jst.obj.Get("hostio"))
61+
if !ok {
62+
return
63+
}
64+
65+
info := jst.vm.NewObject()
66+
info.Set("name", name)
67+
info.Set("args", args)
68+
info.Set("outs", outs)
69+
info.Set("ink", ink)
70+
71+
if _, err := hostio(jst.obj, info); err != nil {
72+
jst.err = wrapError("hostio", err)
73+
}
74+
}

eth/tracers/logger/logger_arbitrum.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ func (*AccessListTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth
4141
func (*JSONLogger) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {}
4242
func (*StructLogger) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {}
4343
func (*mdLogger) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {}
44+
45+
func (*AccessListTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
46+
func (*JSONLogger) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
47+
func (*StructLogger) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
48+
func (*mdLogger) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}

eth/tracers/native/mux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ func (t *muxTracer) CaptureArbitrumTransfer(env *vm.EVM, from, to *common.Addres
131131
}
132132
}
133133

134+
func (t *muxTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {
135+
for _, t := range t.tracers {
136+
t.CaptureStylusHostio(name, args, outs, ink)
137+
}
138+
}
139+
134140
// GetResult returns an empty json object.
135141
func (t *muxTracer) GetResult() (json.RawMessage, error) {
136142
resObject := make(map[string]json.RawMessage)

eth/tracers/native/tracer_arbitrum.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ func (*noopTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int,
9090
func (*prestateTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {}
9191
func (*flatCallTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {}
9292

93+
func (*callTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
94+
func (*fourByteTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
95+
func (*noopTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
96+
func (*prestateTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
97+
func (*flatCallTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
98+
9399
func bigToHex(n *big.Int) string {
94100
if n == nil {
95101
return ""

0 commit comments

Comments
 (0)