Skip to content

Commit

Permalink
Merge pull request ethereum#26 from OffchainLabs/hostio-tracer
Browse files Browse the repository at this point in the history
Hostio tracer
  • Loading branch information
rachel-bousfield authored Sep 14, 2023
2 parents 69c097f + 27113b8 commit 4d61d86
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/vm/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type EVMLogger interface {
CaptureArbitrumStorageGet(key common.Hash, depth int, before bool)
CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool)

// Stylus: capture hostio invocation
CaptureStylusHostio(name string, args, outs []byte, ink uint64)

// Transaction level
CaptureTxStart(gasLimit uint64)
CaptureTxEnd(restGas uint64)
Expand Down
17 changes: 17 additions & 0 deletions eth/tracers/js/tracer_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,20 @@ func (jst *jsTracer) CaptureArbitrumTransfer(

func (*jsTracer) CaptureArbitrumStorageGet(key common.Hash, depth int, before bool) {}
func (*jsTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {}

func (jst *jsTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {
hostio, ok := goja.AssertFunction(jst.obj.Get("hostio"))
if !ok {
return
}

info := jst.vm.NewObject()
info.Set("name", name)
info.Set("args", args)
info.Set("outs", outs)
info.Set("ink", ink)

if _, err := hostio(jst.obj, info); err != nil {
jst.err = wrapError("hostio", err)
}
}
5 changes: 5 additions & 0 deletions eth/tracers/logger/logger_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ func (*AccessListTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth
func (*JSONLogger) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {}
func (*StructLogger) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {}
func (*mdLogger) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {}

func (*AccessListTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
func (*JSONLogger) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
func (*StructLogger) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
func (*mdLogger) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
6 changes: 6 additions & 0 deletions eth/tracers/native/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ func (t *muxTracer) CaptureArbitrumTransfer(env *vm.EVM, from, to *common.Addres
}
}

func (t *muxTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {
for _, t := range t.tracers {
t.CaptureStylusHostio(name, args, outs, ink)
}
}

// GetResult returns an empty json object.
func (t *muxTracer) GetResult() (json.RawMessage, error) {
resObject := make(map[string]json.RawMessage)
Expand Down
6 changes: 6 additions & 0 deletions eth/tracers/native/tracer_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func (*noopTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int,
func (*prestateTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {}
func (*flatCallTracer) CaptureArbitrumStorageSet(key, value common.Hash, depth int, before bool) {}

func (*callTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
func (*fourByteTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
func (*noopTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
func (*prestateTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}
func (*flatCallTracer) CaptureStylusHostio(name string, args, outs []byte, ink uint64) {}

func bigToHex(n *big.Int) string {
if n == nil {
return ""
Expand Down

0 comments on commit 4d61d86

Please sign in to comment.