Skip to content

Commit

Permalink
private chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Billy1900 committed Jul 25, 2023
1 parent 1d16740 commit 98aa49f
Show file tree
Hide file tree
Showing 10 changed files with 399 additions and 4 deletions.
1 change: 1 addition & 0 deletions get-trace/MultiVulnToken3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ contract Submitter {
benignUserAddress1 = new no_reentrancy_attack(address(multiVulnToken),address(0x71C7656EC7ab88b098defB751B7401B5f6d8976F));
attacker2Address1 = new reentrancy_attack(address(multiVulnToken),address(0x71C7656EC7ab88b098defB751B7401B5f6d8976F));
}

function attack1_int_overflow() public {
multiVulnToken.transferProxy(
address(this),
Expand Down
Empty file added get-trace/contracts/.gitkeep
Empty file.
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: '0xf60b17f41fbe2439ade252df277118da48d7e9f83d56',
address: '0xf60b17f41fbe2439ade252df277118da48d7e9f8',
privateKey: '0x3a3a5a560064da8fe89e51c9b7e1b6386eb960ff42dbfa768f30d86e8d11d7e3',
address: '0x84A7B1b8094ff18c6a058BEbcA62236316BbE539',
};

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

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

Expand Down
106 changes: 106 additions & 0 deletions get-trace/index3.js
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();


117 changes: 117 additions & 0 deletions get-trace/index4.js
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 added get-trace/migrations/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion get-trace/priv_key_decrypt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from web3.auto import w3
import binascii

key_file_path = "/Users/billy/Library/Ethereum/rinkeby/keystore/UTC--2023-07-08T09-07-25.779700000Z--8ca598d518af8e104f2d9e1ceb9dc6307c8bc02d"
key_file_path = "/Users/billy/Library/Ethereum/goerli/keystore/UTC--2023-07-20T07-58-34.125121000Z--97b35d326217bb5b15b92aa2f57874f7f26bd6e4"

with open(key_file_path) as keyfile:
encrypted_key = keyfile.read()
Expand Down
30 changes: 30 additions & 0 deletions get-trace/readme.md
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 added get-trace/test/.gitkeep
Empty file.
Loading

0 comments on commit 98aa49f

Please sign in to comment.