Skip to content

Commit

Permalink
Merge pull request #2487 from OffchainLabs/fix-stylus-prestatetracerbug
Browse files Browse the repository at this point in the history
Update scopeContext's stack to have correct contract address while tracing for contract calls
  • Loading branch information
joshuacolvin0 authored Jul 15, 2024
2 parents c768543 + f39fde2 commit 262d934
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
25 changes: 20 additions & 5 deletions arbos/programs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,31 @@ func newApiClosures(
startGas := am.SaturatingUSub(gasLeft, baseCost) * 63 / 64
gas := am.MinInt(startGas, gasReq)

// Tracing: emit the call (value transfer is done later in evm.Call)
if tracingInfo != nil {
tracingInfo.Tracer.CaptureState(0, opcode, startGas, baseCost+gas, scope, []byte{}, depth, nil)
}

// EVM rule: calls that pay get a stipend (opCall)
if value.Sign() != 0 {
gas = am.SaturatingUAdd(gas, params.CallStipend)
}

// Tracing: emit the call (value transfer is done later in evm.Call)
if tracingInfo != nil {
var args []uint256.Int
args = append(args, *uint256.NewInt(gas)) // gas
args = append(args, *uint256.NewInt(0).SetBytes(contract.Bytes())) // to address
if opcode == vm.CALL {
args = append(args, *uint256.NewInt(0).SetBytes(value.Bytes())) // call value
}
args = append(args, *uint256.NewInt(0)) // memory offset
args = append(args, *uint256.NewInt(uint64(len(input)))) // memory length
args = append(args, *uint256.NewInt(0)) // return offset
args = append(args, *uint256.NewInt(0)) // return size
s := &vm.ScopeContext{
Memory: util.TracingMemoryFromBytes(input),
Stack: util.TracingStackFromArgs(args...),
Contract: scope.Contract,
}
tracingInfo.Tracer.CaptureState(0, opcode, startGas, baseCost+gas, s, []byte{}, depth, nil)
}

var ret []byte
var returnGas uint64

Expand Down
5 changes: 1 addition & 4 deletions arbos/util/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ func (info *TracingInfo) RecordEmitLog(topics []common.Hash, data []byte) {
for _, topic := range topics {
args = append(args, HashToUint256(topic)) // topic: 32-byte value. Max topics count is 4
}
memory := vm.NewMemory()
memory.Resize(size)
memory.Set(0, size, data)
scope := &vm.ScopeContext{
Memory: memory,
Memory: TracingMemoryFromBytes(data),
Stack: TracingStackFromArgs(args...),
Contract: info.Contract,
}
Expand Down

0 comments on commit 262d934

Please sign in to comment.