Skip to content

Commit

Permalink
Adding isCall(), fixing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shahafn committed Dec 19, 2024
1 parent 6c94b38 commit 9bc24ba
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions eth/tracers/native/erc7562.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (t *erc7562Tracer) OnTxEnd(receipt *types.Receipt, err error) {
t.callstackWithOpcodes[0].GasUsed = receipt.GasUsed
if t.config.WithLog {
// Logs are not emitted when the call fails
clearFailedLogs2(&t.callstackWithOpcodes[0], false)
t.clearFailedLogs(&t.callstackWithOpcodes[0], false)
}
}

Expand Down Expand Up @@ -384,14 +384,14 @@ func (t *erc7562Tracer) Stop(err error) {

// clearFailedLogs clears the logs of a callframe and all its children
// in case of execution failure.
func clearFailedLogs2(cf *callFrameWithOpcodes, parentFailed bool) {
func (t *erc7562Tracer) clearFailedLogs(cf *callFrameWithOpcodes, parentFailed bool) {
failed := cf.failed() || parentFailed
// Clear own logs
if failed {
cf.Logs = nil
}
for i := range cf.Calls {
clearFailedLogs2(&cf.Calls[i], failed)
t.clearFailedLogs(&cf.Calls[i], failed)
}
}

Expand Down Expand Up @@ -429,8 +429,6 @@ func (t *erc7562Tracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tra
t.storeUsedOpcode(opcode, currentCallFrame)
t.handleStorageAccess(opcode, scope, currentCallFrame)
t.storeKeccak(opcode, scope)
//t.lastOp = opcode
//t.handleLogs(opcode, scope)
}

func (t *erc7562Tracer) handleReturnRevert(opcode vm.OpCode) {
Expand All @@ -443,8 +441,7 @@ func (t *erc7562Tracer) handleReturnRevert(opcode vm.OpCode) {

func (t *erc7562Tracer) handleGasObserved(lastOp vm.OpCode, opcode vm.OpCode, currentCallFrame *callFrameWithOpcodes) {
// [OP-012]
isCall := opcode == vm.CALL || opcode == vm.STATICCALL || opcode == vm.DELEGATECALL || opcode == vm.CALLCODE
pendingGasObserved := lastOp == vm.GAS && !isCall
pendingGasObserved := lastOp == vm.GAS && !isCall(opcode)
if pendingGasObserved {
incrementCount(currentCallFrame.UsedOpcodes, vm.GAS)
}
Expand Down Expand Up @@ -502,8 +499,6 @@ func (t *erc7562Tracer) handleExtOpcodes(lastOpInfo *opcodeWithPartialStack, opc
if isEXT(lastOpInfo.Opcode) {
addr := common.HexToAddress(lastOpInfo.StackTop3[0].Hex())

// TODO: THIS CODE SEEMS TO BE EQUIVALENT TO THE STRING BASED BUT IT IS LOGICALLY WRONG AND WILL NEVER WORK.
// TODO: INSTEAD WE MAY NEED TO DEFER ADDING ADDRESS TO 'ExtCodeAccessInfo' UNTIL AFTER THE 'ISZERO' CHECK.
// only store the last EXTCODE* opcode per address - could even be a boolean for our current use-case
// [OP-051]

Expand Down Expand Up @@ -535,11 +530,7 @@ func peepStack(stackData []uint256.Int, n int) *uint256.Int {
}

func isEXTorCALL(opcode vm.OpCode) bool {
return isEXT(opcode) ||
opcode == vm.CALL ||
opcode == vm.CALLCODE ||
opcode == vm.DELEGATECALL ||
opcode == vm.STATICCALL
return isEXT(opcode) || isCall(opcode)
}

func isEXT(opcode vm.OpCode) bool {
Expand All @@ -548,6 +539,13 @@ func isEXT(opcode vm.OpCode) bool {
opcode == vm.EXTCODECOPY
}

func isCall(opcode vm.OpCode) bool {
return opcode == vm.CALL ||
opcode == vm.CALLCODE ||
opcode == vm.DELEGATECALL ||
opcode == vm.STATICCALL
}

// Check if this opcode is ignored for the purposes of generating the used opcodes report
func (t *erc7562Tracer) isIgnoredOpcode(opcode vm.OpCode) bool {
if _, ok := t.ignoredOpcodes[opcode]; ok {
Expand Down

0 comments on commit 9bc24ba

Please sign in to comment.