Skip to content

Commit

Permalink
complete revert trace
Browse files Browse the repository at this point in the history
  • Loading branch information
Billy1900 committed Aug 1, 2023
1 parent c2da481 commit 242f855
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 44 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,7 @@ then you will get a json file `trace.json` which contains the execution trace. A
```bash
python3 trace_process.py --trace_file trace.json --output trace1.txt
```
```
### How to get the trace of a reverted transaction?
More details are [here](get_trace/get_revert_trace.md).
46 changes: 46 additions & 0 deletions get-trace/get_revert_trace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# How to get the trace of a reverted transaction?
The file is `index3.js` and we have to use the API `debug_traceCall`. However, some framework even client do not support this. After some investigation, we have two approaches to do this.

## 1. Build a local private network
### goerli network
```shell
geth --goerli account new # create new account

geth --http --http.corsdomain https://remix.ethereum.org --goerli --vmdebug --allow-insecure-unlock --unlock “0x97b35d326217bb5b15b92aa2f57874f7f26bd6e4” # start goerli network and connect to remix

geth --goerli attach # open another interactive terminal
> eth.accounts
["0x97b35d326217bb5b15b92aa2f57874f7f26bd6e4", "0x9741cc9982265464ae3d84d96706f6a1f7265d8a"]
> miner.setEtherbase(eth.accounts[0])
true
> eth.coinbase
"0x97b35d326217bb5b15b92aa2f57874f7f26bd6e4"
> miner.start() # start to mine (add some fund to the account)

# then you could deploy the contract and use index3.js via `node index3.js` to get trace.
```

### Customized local network
do this within `TCTchain` folder.
```shell
geth init --datadir node1 genesis.json # network initialization

geth --datadir node1 --networkid 13756 --http --http.corsdomain https://remix.ethereum.org # start the network and connect to remix

# then follow the steps in goerli network section.
```

## 2. framework
the second approach is to use development framework that supports `debug_traceCall`. Here I recommend to use [foundry](https://book.getfoundry.sh/).

After you sucessfully install foundry, use the command to install latest forge, cast, anvil, and chisel.
```shell
$ foundryup
```

and then use the command to start a local network.
```shell
$ anvil
```

then just deploy the contract and use `index3.js` to get trace.
2 changes: 1 addition & 1 deletion get-trace/index1.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const contractABI = [
}
]

const contract_address = "0xfE534D7658b233E35bCB5d230F263C3BB4fF0753"
const contract_address = "0x5FbDB2315678afecb367f032d93F642f64180aa3"

var Web3Contract = new web3.eth.Contract(contractABI, contract_address)

Expand Down
6 changes: 3 additions & 3 deletions get-trace/index2.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ const functionSignature = web3.eth.abi.encodeFunctionSignature(contractABI.find(

// 2. Create account variables
const accountFrom = {
privateKey: '0x3a3a5a560064da8fe89e51c9b7e1b6386eb960ff42dbfa768f30d86e8d11d7e3',
address: '0x84A7B1b8094ff18c6a058BEbcA62236316BbE539',
privateKey: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
};

const addressTo = '0xa3950FF01e378f2A237A3C13a74eFE67C9726D67'; // Change addressTo
const addressTo = '0x5FbDB2315678afecb367f032d93F642f64180aa3'; // Change addressTo

console.log("sender addr:", accountFrom.address, " to addr: ", addressTo)

Expand Down
9 changes: 3 additions & 6 deletions get-trace/index3.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,16 @@ async function traceRevertedTransaction() {
method: 'debug_traceCall',
params: [
{
from: "0xd0f9295EA2A0a26E5D0A57F4A8a77CC42F91d19d",
to: "0xf0d527df89411Fb2149e629C010D31fBEe337698", //contract addr
from: "0xe4E341401D7904c4C78db2De8bd7d923150DF980",
to: "0x1c16dADF903f6B25f79c8c8038341053371Fc15b", //contract addr
data: functionSignature,
},
"latest",
{
"tracer": "callTracer"
}
],
id: 1,
});

console.log('Transaction trace:', response.data.result);
console.log('Transaction EVM trace:', response.data.result);
} catch (error) {
console.error('Error:', error);
}
Expand Down
6 changes: 3 additions & 3 deletions get-trace/index4.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ console.log(functionSignature)

// 2. Create account variables
const accountFrom = {
privateKey: '0xa2c28995f93af6f9ca02bb1082dfa55fab1d0c7945e7c09b7594d82b83a06f79',
address: '0x0e6322d1B8b3d57D6f96fA3f529892fE77c3daE8',
privateKey: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
};

const contractAddress = '0x93B1eC1655303B81F5D00b888854eD3674966B14'; // Change addressTo
const contractAddress = '0x5FbDB2315678afecb367f032d93F642f64180aa3'; // Change addressTo


async function send() {
Expand Down
30 changes: 0 additions & 30 deletions get-trace/readme.md

This file was deleted.

0 comments on commit 242f855

Please sign in to comment.