Skip to content

Commit

Permalink
Merge pull request #26 from theethernaut/onboarding/util-calldata
Browse files Browse the repository at this point in the history
Calldata decoding util
  • Loading branch information
eternauta1337 authored Oct 2, 2024
2 parents a7638ed + e4b87b3 commit d168053
Show file tree
Hide file tree
Showing 5 changed files with 406 additions and 0 deletions.
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/ethernaut-interact/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ This plugin adds the following tasks:
- logs Finds logs emitted by a contract
- send Sends ether to an address
- token Interacts with any ERC20 token
- tx Gives information about a mined transaction
- standards Checks if a contract address meets known token standards

## Environment extensions
Expand Down
42 changes: 42 additions & 0 deletions packages/ethernaut-interact/src/tasks/tx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const types = require('ethernaut-common/src/validation/types')
const output = require('ethernaut-common/src/ui/output')
const EthernautCliError = require('ethernaut-common/src/error/error')
const loadAbi = require('../internal/load-abi')

require('../scopes/interact')
.task('tx', 'Gives information about a mined transaction')
.addPositionalParam(
'transactionId',
'The transaction to lookup',
undefined,
types.bytes32,
)
.addPositionalParam(
'abi',
'The ABI path of the file to decode the tx',
undefined,
types.string,
)
.setAction(async ({ transactionId, abi }, hre) => {
try {
const _abi = loadAbi(abi)
const iface = new hre.ethers.Interface(_abi)
const tx = await hre.ethers.provider.getTransaction(transactionId)
if (!tx)
throw new EthernautCliError('ethernaut-interact', 'No tx found.', false)
const decodedData = iface.parseTransaction({ data: tx.data })

// console.log(decodedData)

const str = `
functionName:
${decodedData.name},
args:
(${decodedData.args.join(', ')})
`

return output.resultBox(str)
} catch (err) {
return output.errorBox(err)
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,333 @@
[
{
"inputs": [
{ "internalType": "uint256", "name": "chainId_", "type": "uint256" }
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "src",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "guy",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "wad",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": true,
"inputs": [
{
"indexed": true,
"internalType": "bytes4",
"name": "sig",
"type": "bytes4"
},
{
"indexed": true,
"internalType": "address",
"name": "usr",
"type": "address"
},
{
"indexed": true,
"internalType": "bytes32",
"name": "arg1",
"type": "bytes32"
},
{
"indexed": true,
"internalType": "bytes32",
"name": "arg2",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "LogNote",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "src",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "dst",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "wad",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"constant": true,
"inputs": [],
"name": "DOMAIN_SEPARATOR",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "PERMIT_TYPEHASH",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{ "internalType": "address", "name": "", "type": "address" },
{ "internalType": "address", "name": "", "type": "address" }
],
"name": "allowance",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "usr", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "approve",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "balanceOf",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "usr", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "burn",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [{ "internalType": "address", "name": "guy", "type": "address" }],
"name": "deny",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "usr", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "mint",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "src", "type": "address" },
{ "internalType": "address", "name": "dst", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "move",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "nonces",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "holder", "type": "address" },
{ "internalType": "address", "name": "spender", "type": "address" },
{ "internalType": "uint256", "name": "nonce", "type": "uint256" },
{ "internalType": "uint256", "name": "expiry", "type": "uint256" },
{ "internalType": "bool", "name": "allowed", "type": "bool" },
{ "internalType": "uint8", "name": "v", "type": "uint8" },
{ "internalType": "bytes32", "name": "r", "type": "bytes32" },
{ "internalType": "bytes32", "name": "s", "type": "bytes32" }
],
"name": "permit",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "usr", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "pull",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "usr", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "push",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [{ "internalType": "address", "name": "guy", "type": "address" }],
"name": "rely",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "dst", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "transfer",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "src", "type": "address" },
{ "internalType": "address", "name": "dst", "type": "address" },
{ "internalType": "uint256", "name": "wad", "type": "uint256" }
],
"name": "transferFrom",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "version",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [{ "internalType": "address", "name": "", "type": "address" }],
"name": "wards",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
Loading

0 comments on commit d168053

Please sign in to comment.