-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
399 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
const axios = require('axios'); | ||
|
||
const {Web3} = require('web3'); | ||
var web3 = new Web3('http://localhost:8545'); | ||
|
||
// This is an example, replace it with your own contract's ABI | ||
const contractABI = [ | ||
{ | ||
"inputs": [], | ||
"name": "attack1_int_overflow", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "attack2_reentrancy", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "no_reentrancy", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "attacker2Address1", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract reentrancy_attack", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "benignUserAddress1", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract no_reentrancy_attack", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "multiVulnToken", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract MultiVulnToken", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] | ||
|
||
// Finding the function signature | ||
const functionSignature = web3.eth.abi.encodeFunctionSignature(contractABI.find(x => x.name === 'attack1_int_overflow')); | ||
console.log(functionSignature) | ||
|
||
async function traceRevertedTransaction() { | ||
try { | ||
const response = await axios.post('http://localhost:8545', { | ||
jsonrpc: '2.0', | ||
method: 'debug_traceCall', | ||
params: [ | ||
{ | ||
from: "0xd0f9295EA2A0a26E5D0A57F4A8a77CC42F91d19d", | ||
to: "0xf0d527df89411Fb2149e629C010D31fBEe337698", //contract addr | ||
data: functionSignature, | ||
}, | ||
"latest", | ||
{ | ||
"tracer": "callTracer" | ||
} | ||
], | ||
id: 1, | ||
}); | ||
|
||
console.log('Transaction trace:', response.data.result); | ||
} catch (error) { | ||
console.error('Error:', error); | ||
} | ||
} | ||
|
||
traceRevertedTransaction(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
const axios = require('axios'); | ||
const {Web3} = require('web3'); | ||
var web3 = new Web3('http://localhost:8545'); | ||
|
||
// This is an example, replace it with your own contract's ABI | ||
const contractABI = [ | ||
{ | ||
"inputs": [], | ||
"name": "attack1_int_overflow", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "attack2_reentrancy", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "no_reentrancy", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "attacker2Address1", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract reentrancy_attack", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "benignUserAddress1", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract no_reentrancy_attack", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "multiVulnToken", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract MultiVulnToken", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] | ||
|
||
// Finding the function signature | ||
const functionSignature = web3.eth.abi.encodeFunctionSignature(contractABI.find(x => x.name === 'attack1_int_overflow')); | ||
console.log(functionSignature) | ||
|
||
// 2. Create account variables | ||
const accountFrom = { | ||
privateKey: '0xa2c28995f93af6f9ca02bb1082dfa55fab1d0c7945e7c09b7594d82b83a06f79', | ||
address: '0x0e6322d1B8b3d57D6f96fA3f529892fE77c3daE8', | ||
}; | ||
|
||
const contractAddress = '0x93B1eC1655303B81F5D00b888854eD3674966B14'; // Change addressTo | ||
|
||
|
||
async function send() { | ||
try { | ||
console.log(`Attempting to send transaction from ${accountFrom.address} to ${contractAddress}`); | ||
const nonce = await web3.eth.getTransactionCount(accountFrom.address, "latest"); | ||
|
||
const rawTx = { | ||
from: accountFrom.address, | ||
to: contractAddress, | ||
nonce: web3.utils.toHex(nonce), | ||
gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei')), | ||
gasLimit: web3.utils.toHex(300000), | ||
data: functionSignature, | ||
}; | ||
|
||
const signedTx = await web3.eth.accounts.signTransaction(rawTx, accountFrom.privateKey); | ||
|
||
const response = await axios.post('http://localhost:8545', { | ||
jsonrpc: '2.0', | ||
method: 'eth_sendRawTransaction', | ||
params: [signedTx.rawTransaction], | ||
id: 1, | ||
}); | ||
|
||
console.log("The hash of your transaction is: ", response.data.result, | ||
"\nCheck Transactions tab in your Ethereum client to view your transaction!"); | ||
} catch (error) { | ||
console.log("Something went wrong while submitting your transaction:", error); | ||
} | ||
}; | ||
|
||
send(); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
https://bolenzhang.github.io/2018/04/29/%E4%BB%A5%E5%A4%AA%E5%9D%8A%E7%A7%81%E9%93%BE%E6%90%AD%E5%BB%BA%E5%8F%8A%E6%99%BA%E8%83%BD%E5%90%88%E7%BA%A6%E9%83%A8%E7%BD%B2/ | ||
|
||
|
||
```shell | ||
geth --goerli account new | ||
|
||
geth --goerli | ||
|
||
geth --http --http.corsdomain https://remix.ethereum.org --goerli --vmdebug --allow-insecure-unlock --unlock “0x97b35d326217bb5b15b92aa2f57874f7f26bd6e4” | ||
|
||
geth --http --goerli --miner.etherbase '0x97b35d326217bb5b15b92aa2f57874f7f26bd6e4' --mine | ||
|
||
geth --goerli attach | ||
> eth.accounts | ||
["0x97b35d326217bb5b15b92aa2f57874f7f26bd6e4", "0x9741cc9982265464ae3d84d96706f6a1f7265d8a"] | ||
> miner.setEtherbase(eth.accounts[0]) | ||
true | ||
> eth.coinbase | ||
"0x97b35d326217bb5b15b92aa2f57874f7f26bd6e4" | ||
``` | ||
|
||
|
||
```shell | ||
geth init --datadir node1 genesis.json | ||
|
||
geth --networkid 191 --nodiscover --http --http.addr "127.0.0.1" --http.port 8545 --http.api personal,eth,net,web3 --allow-insecure-unlock --datadir node1 console | ||
|
||
geth --datadir node1 --networkid 13756 --http --http.corsdomain https://remix.ethereum.org | ||
``` |
Empty file.
Oops, something went wrong.