Skip to content

Commit 1bf5d01

Browse files
ngotchacshekhirin
authored andcommitted
Fix trace call for inner reverts (ethereum#25971)
Inner call reverts will now return the reason similar to the top-level call. Separately, if top-level call is of type CREATE and it fails, its `to` field will now be cleared to `0x00...00` instead of being set to the created address.
1 parent e4f2764 commit 1bf5d01

File tree

8 files changed

+132
-36
lines changed

8 files changed

+132
-36
lines changed

eth/tracers/internal/tracetest/testdata/call_tracer/deep_calls.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@
263263
"gas": "0x20ee1",
264264
"gasUsed": "0x5374",
265265
"input": "0x581d5d60000000000000000000000000c212e03b9e060e36facad5fd8f4435412ca22e6b0000000000000000000000000000000000000000000000280faf689c35ac0000",
266-
"output": "0x",
267266
"to": "0xcf00ffd997ad14939736f026006498e3f099baaf",
268267
"type": "CALL",
269268
"value": "0x0"
@@ -305,7 +304,6 @@
305304
"gas": "0x1a91d",
306305
"gasUsed": "0x12fa",
307306
"input": "0x0accce0600000000000000000000000000000000000000000000000000000000000000025842545553440000000000000000000000000000000000000000000000000000000000000000000000000000c212e03b9e060e36facad5fd8f4435412ca22e6b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
308-
"output": "0x",
309307
"to": "0x2a98c5f40bfa3dee83431103c535f6fae9a8ad38",
310308
"type": "CALL",
311309
"value": "0x0"
@@ -377,7 +375,6 @@
377375
"gas": "0x16e62",
378376
"gasUsed": "0xebb",
379377
"input": "0x645a3b72584254555344000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002816d180e30c390000",
380-
"output": "0x",
381378
"to": "0x2a98c5f40bfa3dee83431103c535f6fae9a8ad38",
382379
"type": "CALL",
383380
"value": "0x0"
@@ -387,7 +384,6 @@
387384
"gas": "0x283b9",
388385
"gasUsed": "0xc51c",
389386
"input": "0x949ae479000000000000000000000000c212e03b9e060e36facad5fd8f4435412ca22e6b0000000000000000000000000000000000000000000000280faf689c35ac0000",
390-
"output": "0x",
391387
"to": "0x3e9286eafa2db8101246c2131c09b49080d00690",
392388
"type": "CALL",
393389
"value": "0x0"
@@ -397,7 +393,6 @@
397393
"gas": "0x30b4a",
398394
"gasUsed": "0xedb7",
399395
"input": "0x51a34eb80000000000000000000000000000000000000000000000280faf689c35ac0000",
400-
"output": "0x",
401396
"to": "0xb4fe7aa695b326c9d219158d2ca50db77b39f99f",
402397
"type": "CALL",
403398
"value": "0x0"
@@ -407,7 +402,6 @@
407402
"gas": "0x37b38",
408403
"gasUsed": "0x1810b",
409404
"input": "0x51a34eb80000000000000000000000000000000000000000000000280faf689c35ac0000",
410-
"output": "0x",
411405
"to": "0xc212e03b9e060e36facad5fd8f4435412ca22e6b",
412406
"type": "CALL",
413407
"value": "0x0"

eth/tracers/internal/tracetest/testdata/call_tracer/delegatecall.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
"gas": "0x2d6e28",
9090
"gasUsed": "0xbd55",
9191
"input": "0x7065cb480000000000000000000000001523e55a1ca4efbae03355775ae89f8d7699ad9e",
92-
"output": "0x",
9392
"to": "0x269296dddce321a6bcbaa2f0181127593d732cba",
9493
"type": "CALL",
9594
"value": "0x0"

eth/tracers/internal/tracetest/testdata/call_tracer/inner_create_oog_outer_throw.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

eth/tracers/internal/tracetest/testdata/call_tracer/inner_instafail.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@
5656
"value": "0x0",
5757
"gas": "0x1a466",
5858
"gasUsed": "0x72de",
59-
"input": "0x2e1a7d4d00000000000000000000000000000000000000000000000014d1120d7b160000",
60-
"output": "0x",
61-
"calls": []
59+
"input": "0x2e1a7d4d00000000000000000000000000000000000000000000000014d1120d7b160000"
6260
}
6361
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"genesis": {
3+
"baseFeePerGas": "1000000000",
4+
"difficulty": "1",
5+
"extraData": "0x00000000000000000000000000000000000000000000000000000000000000003623191d4ccfbbdf09e8ebf6382a1f8257417bc10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
6+
"gasLimit": "11500000",
7+
"hash": "0x2af138b8a06e65b8dd0999df70b9e87609e9fc91ea201f08b1cc4f25ef01fcf6",
8+
"miner": "0x0000000000000000000000000000000000000000",
9+
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
10+
"nonce": "0x0000000000000000",
11+
"number": "0",
12+
"stateRoot": "0xa775801d572e9b79585eb131d18d79f8a0f71895455ab9a5b656911428e11708",
13+
"timestamp": "0",
14+
"totalDifficulty": "1",
15+
"alloc": {
16+
"0x3623191d4ccfbbdf09e8ebf6382a1f8257417bc1": {
17+
"balance": "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7"
18+
},
19+
"0xd15abca351f79181dedfb6d019e382db90f3628a": {
20+
"balance": "0x0"
21+
}
22+
},
23+
"config": {
24+
"chainId": 1337,
25+
"homesteadBlock": 0,
26+
"eip150Block": 0,
27+
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
28+
"eip155Block": 0,
29+
"eip158Block": 0,
30+
"byzantiumBlock": 0,
31+
"constantinopleBlock": 0,
32+
"petersburgBlock": 0,
33+
"istanbulBlock": 0,
34+
"muirGlacierBlock": 0,
35+
"berlinBlock": 0,
36+
"londonBlock": 0,
37+
"clique": {
38+
"period": 0,
39+
"epoch": 30000
40+
}
41+
}
42+
},
43+
"context": {
44+
"number": "1",
45+
"difficulty": "2",
46+
"timestamp": "1665537018",
47+
"gasLimit": "11511229",
48+
"miner": "0x0000000000000000000000000000000000000000"
49+
},
50+
"input": "0x02f9029d82053980849502f90085010c388d00832dc6c08080b90241608060405234801561001057600080fd5b50600060405161001f906100a2565b604051809103906000f08015801561003b573d6000803e3d6000fd5b5090508073ffffffffffffffffffffffffffffffffffffffff1663c04062266040518163ffffffff1660e01b815260040160006040518083038186803b15801561008457600080fd5b505afa158015610098573d6000803e3d6000fd5b50505050506100af565b610145806100fc83390190565b603f806100bd6000396000f3fe6080604052600080fdfea264697066735822122077f7dbd3450d6e817079cf3fe27107de5768bb3163a402b94e2206b468eb025664736f6c63430008070033608060405234801561001057600080fd5b50610125806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c040622614602d575b600080fd5b60336035565b005b60036002116076576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401606d906097565b60405180910390fd5b565b6000608360128360b5565b9150608c8260c6565b602082019050919050565b6000602082019050818103600083015260ae816078565b9050919050565b600082825260208201905092915050565b7f546869732063616c6c6564206661696c6564000000000000000000000000000060008201525056fea264697066735822122033f8d92e29d467e5ea08d0024eab0b36b86b8cdb3542c6e89dbaabeb8ffaa42064736f6c63430008070033c001a07566181071cabaf58b70fc41557eb813bfc7a24f5c58554e7fed0bf7c031f169a0420af50b5fe791a4d839e181a676db5250b415dfb35cb85d544db7a1475ae2cc",
51+
"result": {
52+
"from": "0x3623191d4ccfbbdf09e8ebf6382a1f8257417bc1",
53+
"to": "0x0000000000000000000000000000000000000000",
54+
"gas": "0x2cd774",
55+
"gasUsed": "0x25590",
56+
"input": "0x608060405234801561001057600080fd5b50600060405161001f906100a2565b604051809103906000f08015801561003b573d6000803e3d6000fd5b5090508073ffffffffffffffffffffffffffffffffffffffff1663c04062266040518163ffffffff1660e01b815260040160006040518083038186803b15801561008457600080fd5b505afa158015610098573d6000803e3d6000fd5b50505050506100af565b610145806100fc83390190565b603f806100bd6000396000f3fe6080604052600080fdfea264697066735822122077f7dbd3450d6e817079cf3fe27107de5768bb3163a402b94e2206b468eb025664736f6c63430008070033608060405234801561001057600080fd5b50610125806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c040622614602d575b600080fd5b60336035565b005b60036002116076576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401606d906097565b60405180910390fd5b565b6000608360128360b5565b9150608c8260c6565b602082019050919050565b6000602082019050818103600083015260ae816078565b9050919050565b600082825260208201905092915050565b7f546869732063616c6c6564206661696c6564000000000000000000000000000060008201525056fea264697066735822122033f8d92e29d467e5ea08d0024eab0b36b86b8cdb3542c6e89dbaabeb8ffaa42064736f6c63430008070033",
57+
"output": "0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000012546869732063616c6c6564206661696c65640000000000000000000000000000",
58+
"error": "execution reverted",
59+
"revertReason": "This called failed",
60+
"calls": [
61+
{
62+
"from": "0xdebfb4b387033eac57af7b3de5116dd60056803b",
63+
"gas": "0x2ba851",
64+
"gasUsed": "0xe557",
65+
"to": "0xd15abca351f79181dedfb6d019e382db90f3628a",
66+
"input": "0x608060405234801561001057600080fd5b50610125806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063c040622614602d575b600080fd5b60336035565b005b60036002116076576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401606d906097565b60405180910390fd5b565b6000608360128360b5565b9150608c8260c6565b602082019050919050565b6000602082019050818103600083015260ae816078565b9050919050565b600082825260208201905092915050565b7f546869732063616c6c6564206661696c6564000000000000000000000000000060008201525056fea264697066735822122033f8d92e29d467e5ea08d0024eab0b36b86b8cdb3542c6e89dbaabeb8ffaa42064736f6c63430008070033",
67+
"output": "0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063c040622614602d575b600080fd5b60336035565b005b60036002116076576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401606d906097565b60405180910390fd5b565b6000608360128360b5565b9150608c8260c6565b602082019050919050565b6000602082019050818103600083015260ae816078565b9050919050565b600082825260208201905092915050565b7f546869732063616c6c6564206661696c6564000000000000000000000000000060008201525056fea264697066735822122033f8d92e29d467e5ea08d0024eab0b36b86b8cdb3542c6e89dbaabeb8ffaa42064736f6c63430008070033",
68+
"value": "0x0",
69+
"type": "CREATE"
70+
},
71+
{
72+
"from": "0xdebfb4b387033eac57af7b3de5116dd60056803b",
73+
"gas": "0x2ac548",
74+
"gasUsed": "0x1b2",
75+
"to": "0xd15abca351f79181dedfb6d019e382db90f3628a",
76+
"input": "0xc0406226",
77+
"output": "0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000012546869732063616c6c6564206661696c65640000000000000000000000000000",
78+
"error": "execution reverted",
79+
"revertReason": "This called failed",
80+
"type": "STATICCALL"
81+
}
82+
],
83+
"value": "0x0",
84+
"type": "CREATE"
85+
}
86+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
This test tests out the trace generated by the deployment of this contract:
2+
3+
```solidity
4+
contract Revertor {
5+
function run() public pure {
6+
require(2 > 3, "This called failed");
7+
}
8+
}
9+
10+
contract Contract {
11+
constructor() {
12+
Revertor r = new Revertor();
13+
r.run();
14+
}
15+
}
16+
```
17+
18+
The trace should show a revert, with the revert reason for both the top-call as well
19+
as the inner call.

eth/tracers/internal/tracetest/testdata/call_tracer/selfdestruct.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"gas": "0x0",
5959
"gasUsed": "0x0",
6060
"input": "0x",
61-
"to": "0x000000000000000000000000000000000000dEaD",
61+
"to": "0x000000000000000000000000000000000000dead",
6262
"type": "SELFDESTRUCT",
6363
"value": "0x4d87094125a369d9bd5"
6464
}
@@ -67,7 +67,6 @@
6767
"gas": "0x10738",
6868
"gasUsed": "0x6fcb",
6969
"input": "0x63e4bff40000000000000000000000000024f658a46fbb89d8ac105e98d7ac7cbbaf27c5",
70-
"output": "0x",
7170
"to": "0x3b873a919aa0512d5a0f09e6dcceaa4a6727fafe",
7271
"type": "CALL",
7372
"value": "0x0"

eth/tracers/native/call.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,28 @@ func (f callFrame) TypeString() string {
5656
return f.Type.String()
5757
}
5858

59+
func (f *callFrame) capture(output []byte, err error) {
60+
output = common.CopyBytes(output)
61+
if err == nil {
62+
f.Output = output
63+
return
64+
}
65+
f.Error = err.Error()
66+
if f.Type == vm.CREATE || f.Type == vm.CREATE2 {
67+
f.To = common.Address{}
68+
}
69+
if !errors.Is(err, vm.ErrExecutionReverted) || len(output) == 0 {
70+
return
71+
}
72+
f.Output = output
73+
if len(output) < 4 {
74+
return
75+
}
76+
if unpacked, err := abi.UnpackRevert(output); err == nil {
77+
f.Revertal = unpacked
78+
}
79+
}
80+
5981
type callFrameMarshaling struct {
6082
TypeString string `json:"type"`
6183
Gas hexutil.Uint64
@@ -110,22 +132,7 @@ func (t *callTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Ad
110132

111133
// CaptureEnd is called after the call finishes to finalize the tracing.
112134
func (t *callTracer) CaptureEnd(output []byte, gasUsed uint64, _ time.Duration, err error) {
113-
output = common.CopyBytes(output)
114-
if err == nil {
115-
t.callstack[0].Output = output
116-
return
117-
}
118-
t.callstack[0].Error = err.Error()
119-
if !errors.Is(err, vm.ErrExecutionReverted) || len(output) == 0 {
120-
return
121-
}
122-
t.callstack[0].Output = output
123-
if len(output) < 4 {
124-
return
125-
}
126-
if unpacked, err := abi.UnpackRevert(output); err == nil {
127-
t.callstack[0].Revertal = unpacked
128-
}
135+
t.callstack[0].capture(output, err)
129136
}
130137

131138
// CaptureState implements the EVMLogger interface to trace a single step of VM execution.
@@ -174,14 +181,7 @@ func (t *callTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
174181
size -= 1
175182

176183
call.GasUsed = gasUsed
177-
if err == nil {
178-
call.Output = common.CopyBytes(output)
179-
} else {
180-
call.Error = err.Error()
181-
if call.Type == vm.CREATE || call.Type == vm.CREATE2 {
182-
call.To = common.Address{}
183-
}
184-
}
184+
call.capture(output, err)
185185
t.callstack[size-1].Calls = append(t.callstack[size-1].Calls, call)
186186
}
187187

0 commit comments

Comments
 (0)