Error

trace_transaction 和跟踪錯誤

  • January 25, 2022

我很難理解跟踪中的錯誤是如何應用的。讓我們考慮一下這個 tx:

Etherscan 詳細的痕跡

看到只有 call_0 的狀態為“Reverted”(將滑鼠懸停在紅色驚嘆號上以查看錯誤),然後其餘所有狀態為“Out of gas”。但是,當我們使用 Erigon 或 OpenEthereum 跟踪此交易時,我們得到(我刪除了長輸入和輸出欄位,因為它們不相關):

   [
   {
       "action": {
           "from": "0xf3c0b1ebfd01bc7e56825e6ecbd1379039944129",
           "callType": "call",
           "gas": "0x2aff8",
           "to": "0x958e1e0be167e89eb05eb81e5ac57d260eb9ba03",
           "value": "0x0"
       },
       "blockHash": "0xd0824a89cbab67dfc489c1950f2aebd501aadf4ca48f3a4ebdea0f29ad701a8d",
       "blockNumber": 7497726,
       "result": {
           "gasUsed": "0x2a749",
           "output": "0x"
       },
       "subtraces": 1,
       "traceAddress": [],
       "transactionHash": "0x6d4007f5bf5c71bad9e2331414843c078f9deaf9debb0427855a34b613d11b93",
       "transactionPosition": 65,
       "type": "call"
   },
   {
       "action": {
           "from": "0x958e1e0be167e89eb05eb81e5ac57d260eb9ba03",
           "callType": "call",
           "gas": "0x200db",
           "to": "0x7be8076f4ea4a4ad08075c2508e481d6c946d12b",
           "value": "0x38d7ea4c68000"
       },
       "blockHash": "0xd0824a89cbab67dfc489c1950f2aebd501aadf4ca48f3a4ebdea0f29ad701a8d",
       "blockNumber": 7497726,
       "error": "Reverted",
       "result": null,
       "subtraces": 6,
       "traceAddress": [
           0
       ],
       "transactionHash": "0x6d4007f5bf5c71bad9e2331414843c078f9deaf9debb0427855a34b613d11b93",
       "transactionPosition": 65,
       "type": "call"
   },
   {
       "action": {
           "from": "0x7be8076f4ea4a4ad08075c2508e481d6c946d12b",
           "callType": "call",
           "gas": "0x17729",
           "to": "0xa5409ec958c83c3f309868babaca7c86dcb077c1",
           "value": "0x0"
       },
       "blockHash": "0xd0824a89cbab67dfc489c1950f2aebd501aadf4ca48f3a4ebdea0f29ad701a8d",
       "blockNumber": 7497726,
       "result": {
           "gasUsed": "0x372",
       },
       "subtraces": 0,
       "traceAddress": [
           0,
           0
       ],
       "transactionHash": "0x6d4007f5bf5c71bad9e2331414843c078f9deaf9debb0427855a34b613d11b93",
       "transactionPosition": 65,
       "type": "call"
   },
   {
       "action": {
           "from": "0x7be8076f4ea4a4ad08075c2508e481d6c946d12b",
           "callType": "call",
           "gas": "0x16ba4",
           "input": "0x97204d8e",
           "to": "0xa5409ec958c83c3f309868babaca7c86dcb077c1",
           "value": "0x0"
       },
       "blockHash": "0xd0824a89cbab67dfc489c1950f2aebd501aadf4ca48f3a4ebdea0f29ad701a8d",
       "blockNumber": 7497726,
       "result": {
           "gasUsed": "0x2c9",
       },
       "subtraces": 0,
       "traceAddress": [
           0,
           1
       ],
       "transactionHash": "0x6d4007f5bf5c71bad9e2331414843c078f9deaf9debb0427855a34b613d11b93",
       "transactionPosition": 65,
       "type": "call"
   },
   {
       "action": {
           "from": "0x7be8076f4ea4a4ad08075c2508e481d6c946d12b",
           "callType": "call",
           "gas": "0x16279",
           "input": "0x5c60da1b",
           "to": "0xb45c99cf1af90630b81ded8fbccbf20f96cc4995",
           "value": "0x0"
       },
       "blockHash": "0xd0824a89cbab67dfc489c1950f2aebd501aadf4ca48f3a4ebdea0f29ad701a8d",
       "blockNumber": 7497726,
       "result": {
           "gasUsed": "0x271",
       },
       "subtraces": 0,
       "traceAddress": [
           0,
           2
       ],
       "transactionHash": "0x6d4007f5bf5c71bad9e2331414843c078f9deaf9debb0427855a34b613d11b93",
       "transactionPosition": 65,
       "type": "call"
   },
   {
       "action": {
           "from": "0x7be8076f4ea4a4ad08075c2508e481d6c946d12b",
           "callType": "call",
           "gas": "0x8fc",
           "input": "0x",
           "to": "0x5b3256965e7c3cf26e11fcaf296dfc8807c01073",
           "value": "0x28ed6103d000"
       },
       "blockHash": "0xd0824a89cbab67dfc489c1950f2aebd501aadf4ca48f3a4ebdea0f29ad701a8d",
       "blockNumber": 7497726,
       "result": {
           "gasUsed": "0x0",
           "output": "0x"
       },
       "subtraces": 0,
       "traceAddress": [
           0,
           3
       ],
       "transactionHash": "0x6d4007f5bf5c71bad9e2331414843c078f9deaf9debb0427855a34b613d11b93",
       "transactionPosition": 65,
       "type": "call"
   },
   {
       "action": {
           "from": "0x7be8076f4ea4a4ad08075c2508e481d6c946d12b",
           "callType": "call",
           "gas": "0x8fc",
           "input": "0x",
           "to": "0x425f013fb466b2df721f23ac0ba21049d1c6abd7",
           "value": "0x3649143c2b000"
       },
       "blockHash": "0xd0824a89cbab67dfc489c1950f2aebd501aadf4ca48f3a4ebdea0f29ad701a8d",
       "blockNumber": 7497726,
       "result": {
           "gasUsed": "0x0",
           "output": "0x"
       },
       "subtraces": 0,
       "traceAddress": [
           0,
           4
       ],
       "transactionHash": "0x6d4007f5bf5c71bad9e2331414843c078f9deaf9debb0427855a34b613d11b93",
       "transactionPosition": 65,
       "type": "call"
   },
   {
       "action": {
           "from": "0x7be8076f4ea4a4ad08075c2508e481d6c946d12b",
           "callType": "call",
           "gas": "0xc434",
           "to": "0xb45c99cf1af90630b81ded8fbccbf20f96cc4995",
           "value": "0x0"
       },
       "blockHash": "0xd0824a89cbab67dfc489c1950f2aebd501aadf4ca48f3a4ebdea0f29ad701a8d",
       "blockNumber": 7497726,
       "result": {
           "gasUsed": "0xbf24",
       },
       "subtraces": 1,
       "traceAddress": [
           0,
           5
       ],
       "transactionHash": "0x6d4007f5bf5c71bad9e2331414843c078f9deaf9debb0427855a34b613d11b93",
       "transactionPosition": 65,
       "type": "call"
   },
   {
       "action": {
           "from": "0xb45c99cf1af90630b81ded8fbccbf20f96cc4995",
           "callType": "delegatecall",
           "gas": "0xbbb3",
           "to": "0xf9e266af4bca5890e2781812cc6a6e89495a79f2",
           "value": "0x0"
       },
       "blockHash": "0xd0824a89cbab67dfc489c1950f2aebd501aadf4ca48f3a4ebdea0f29ad701a8d",
       "blockNumber": 7497726,
       "result": {
           "gasUsed": "0xb970",
       },
       "subtraces": 2,
       "traceAddress": [
           0,
           5,
           0
       ],
       "transactionHash": "0x6d4007f5bf5c71bad9e2331414843c078f9deaf9debb0427855a34b613d11b93",
       "transactionPosition": 65,
       "type": "call"
   },
   {
       "action": {
           "from": "0xb45c99cf1af90630b81ded8fbccbf20f96cc4995",
           "callType": "call",
           "gas": "0xadb2",
           "to": "0xa5409ec958c83c3f309868babaca7c86dcb077c1",
           "value": "0x0"
       },
       "blockHash": "0xd0824a89cbab67dfc489c1950f2aebd501aadf4ca48f3a4ebdea0f29ad701a8d",
       "blockNumber": 7497726,
       "result": {
           "gasUsed": "0x28d",
       },
       "subtraces": 0,
       "traceAddress": [
           0,
           5,
           0,
           0
       ],
       "transactionHash": "0x6d4007f5bf5c71bad9e2331414843c078f9deaf9debb0427855a34b613d11b93",
       "transactionPosition": 65,
       "type": "call"
   },
   {
       "action": {
           "from": "0xb45c99cf1af90630b81ded8fbccbf20f96cc4995",
           "callType": "call",
           "gas": "0xa587",
           "to": "0x909899c5dbb5002610dd8543b6f638be56e3b17e",
           "value": "0x0"
       },
       "blockHash": "0xd0824a89cbab67dfc489c1950f2aebd501aadf4ca48f3a4ebdea0f29ad701a8d",
       "blockNumber": 7497726,
       "error": "Out of gas",
       "result": null,
       "subtraces": 0,
       "traceAddress": [
           0,
           5,
           0,
           1
       ],
       "transactionHash": "0x6d4007f5bf5c71bad9e2331414843c078f9deaf9debb0427855a34b613d11b93",
       "transactionPosition": 65,
       "type": "call"
   }
]

請注意,錯誤僅出現在 traceAddress 0 中,它顯示“Reverted”,以及 0.5.0.1,它顯示“Out of gas”。

我的問題是:etherscan 怎麼知道應該向上傳播 Out of gas 以填補所有跡線的缺失錯誤,但明確指定的 0 除外?一般來說,錯誤如何在呼叫跟踪中傳播?

在 Etherscan 界面上,所有內容都標記為紅色,因為所有內容都已還原。

Etherscan 知道它需要將所有標記都標記為錯誤的跟踪traceAddress操作[0]。因此,所有子跟踪也被還原(因此第一個條目的每個跟踪traceAddress都是0)。

在 EVM 級別上,還原不會自動向上傳播。Solidity 為合約呼叫添加了一個檢查(除非你使用低級別call,staticcalldelegatecall)來檢查它是否成功,否則它會冒泡恢復。

傳播也可能發生,因為out of gas在子呼叫恢復後沒有足夠的氣體繼續執行。

您還可以在此處查看 Etherscan 使用的原始跟踪:https ://etherscan.io/vmtrace?txhash=0x6d4007f5bf5c71bad9e2331414843c078f9deaf9debb0427855a34b613d11b93&type=parity

編輯:點擊Parity Trace選項菜單以查看 Etherscan 上的跟踪

在此處輸入圖像描述

引用自:https://ethereum.stackexchange.com/questions/119891