07月20, 2020

How to get solidity runtime opcode and debug trace transaction

Let's see how to get solidify runtime opcode and debug trace step by step :-)

Note that all the following installation and debugging are all on Mac OS.

  1. solc and solc-select

  2. slither

  3. ganache-cli

  4. remix

  5. web3


0 step- install solc and solc-select in Mac os

harry@bubble ~ % brew reinstall solidity
==> Downloading https://github.com/ethereum/solidity/releases/download/v0.6.12/s
Already downloaded: /Users/harry/Library/Caches/Homebrew/downloads/f4e132a62ca3461f37b07e3c9878acbbf48bbfc842d03c2f0958eebaa7072234--solidity_0.6.12.tar.gz
==> Reinstalling ethereum/ethereum/solidity 
==> cmake . -DTESTS=OFF
==> make install
brew  /usr/local/Cellar/solidity/0.6.12: 8 files, 25.6MB, built in 3 minutes 42 seconds
harry@bubble ~ % solc
solc, the Solidity commandline compiler.

This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. See 'solc --license'
for details.

Usage: solc [options] [input_file...]
Compiles the given Solidity input files (or the standard input if none given or
"-" is used as a file name) and outputs the components specified in the options
at standard output or in files in the output directory, if specified.
Imports are automatically read from the filesystem, but it is also possible to
remap paths using the context:prefix=path syntax.
Example:
solc --bin -o /tmp/solcoutput dapp-bin=/usr/local/lib/dapp-bin contract.sol

General Information:
  --help               Show help message and exit.
  --version            Show version and exit.
  --license            Show licensing information and exit.

Input Options:
  --base-path path     Use the given path as the root of the source tree 
                       instead of the root of the filesystem.
  --allow-paths path(s)
                       Allow a given path for imports. A list of paths can be 
                       supplied by separating them with a comma.
  --ignore-missing     Ignore missing files.
  --error-recovery     Enables additional parser error recovery.

Output Options:
  -o [ --output-dir ] path
                       If given, creates one file per component and 
                       contract/file at the specified directory.
  --overwrite          Overwrite existing files (used together with -o).
  --evm-version version
                       Select desired EVM version. Either homestead, 
                       tangerineWhistle, spuriousDragon, byzantium, 
                       constantinople, petersburg, istanbul (default) or 
                       berlin.
  --revert-strings debug,default,strip,verboseDebug
                       Strip revert (and require) reason strings or add 
                       additional debugging information.

Alternative Input Modes:
  --standard-json      Switch to Standard JSON input / output mode, ignoring 
                       all options. It reads from standard input, if no input 
                       file was given, otherwise it reads from the provided 
                       input file. The result will be written to standard 
                       output.
  --link               Switch to linker mode, ignoring all options apart from 
                       --libraries and modify binaries in place.
  --assemble           Switch to assembly mode, ignoring all options except 
                       --machine, --yul-dialect, --optimize and 
                       --yul-optimizations and assumes input is assembly.
  --yul                Switch to Yul mode, ignoring all options except 
                       --machine, --yul-dialect, --optimize and 
                       --yul-optimizations and assumes input is Yul.
  --strict-assembly    Switch to strict assembly mode, ignoring all options 
                       except --machine, --yul-dialect, --optimize and 
                       --yul-optimizations and assumes input is strict 
                       assembly.
  --import-ast         Import ASTs to be compiled, assumes input holds the AST 
                       in compact JSON format. Supported Inputs is the output 
                       of the --standard-json or the one produced by 
                       --combined-json ast,compact-format

Assembly Mode Options:
  --machine evm,evm15,ewasm
                       Target machine in assembly or Yul mode.
  --yul-dialect evm,ewasm
                       Input dialect to use in assembly or yul mode.

Linker Mode Options:
  --libraries libs     Direct string or file containing library addresses. 
                       Syntax: <libraryName>:<address> [, or whitespace] ...
                       Address is interpreted as a hex string optionally 
                       prefixed by 0x.

Output Formatting:
  --pretty-json        Output JSON in pretty format. Currently it only works 
                       with the combined JSON output.
  --color              Force colored output.
  --no-color           Explicitly disable colored output, disabling terminal 
                       auto-detection.
  --error-codes        Output error codes.
  --old-reporter       Enables old diagnostics reporter (legacy option, will be
                       removed).

Output Components:
  --ast-json           AST of all source files in JSON format.
  --ast-compact-json   AST of all source files in a compact JSON format.
  --asm                EVM assembly of the contracts.
  --asm-json           EVM assembly of the contracts in JSON format.
  --opcodes            Opcodes of the contracts.
  --bin                Binary of the contracts in hex.
  --bin-runtime        Binary of the runtime part of the contracts in hex.
  --abi                ABI specification of the contracts.
  --ir                 Intermediate Representation (IR) of all contracts 
                       (EXPERIMENTAL).
  --ir-optimized       Optimized intermediate Representation (IR) of all 
                       contracts (EXPERIMENTAL).
  --ewasm              Ewasm text representation of all contracts 
                       (EXPERIMENTAL).
  --hashes             Function signature hashes of the contracts.
  --userdoc            Natspec user documentation of all contracts.
  --devdoc             Natspec developer documentation of all contracts.
  --metadata           Combined Metadata JSON whose Swarm hash is stored 
                       on-chain.
  --storage-layout     Slots, offsets and types of the contract's state 
                       variables.

Extra Output:
  --gas                Print an estimate of the maximal gas usage for each 
                       function.
  --combined-json abi,asm,ast,bin,bin-runtime,compact-format,devdoc,hashes,interface,metadata,opcodes,srcmap,srcmap-runtime,storage-layout,userdoc
                       Output a single json document containing the specified 
                       information.

Metadata Options:
  --metadata-hash ipfs,none,swarm
                       Choose hash method for the bytecode metadata or disable 
                       it.
  --metadata-literal   Store referenced sources as literal data in the metadata
                       output.

Optimizer Options:
  --optimize           Enable bytecode optimizer.
  --optimize-runs n (=200)
                       Set for how many contract runs to optimize. Lower values
                       will optimize more for initial deployment cost, higher 
                       values will optimize more for high-frequency usage.
  --optimize-yul       Legacy option, ignored. Use the general --optimize to 
                       enable Yul optimizer.
  --no-optimize-yul    Disable Yul optimizer in Solidity.
  --yul-optimizations steps
                       Forces yul optimizer to use the specified sequence of 
                       optimization steps instead of the built-in one.
harry@bubble ~ % solc --version
solc, the solidity compiler commandline interface
Version: 0.6.12+commit.27d51765.Darwin.appleclang
harry@bubble ~ % git clone https://github.com/trailofbits/solc-select.git
Cloning into 'solc-select'...
remote: Enumerating objects: 23, done.
remote: Counting objects: 100% (23/23), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 163 (delta 6), reused 15 (delta 5), pack-reused 140
Receiving objects: 100% (163/163), 45.74 KiB | 1.39 MiB/s, done.
Resolving deltas: 100% (64/64), done.
harry@bubble ~ % cd solc-select
harry@bubble solc-select % docker build -t trailofbits/solc-select:latest .
Sending build context to Docker daemon  168.4kB
Step 1/26 : FROM ethereum/solc:nightly-alpine
nightly-alpine: Pulling from ethereum/solc
df20fa9351a1: Already exists 
2d0a9693f1a6: Already exists 
Digest: sha256:3363400a889d35ccadce7331ba8849e37f730b0a407ebd1bbc4b532c8786a226
Status: Downloaded newer image for ethereum/solc:nightly-alpine
 ---> 99f5dc1367de
Step 2/26 : MAINTAINER Evan Sultanik
 ---> Running in 6baa10b03f11
Removing intermediate container 6baa10b03f11
 ---> b7234f4054d3
Step 3/26 : USER root
 ---> Running in 484eee0ee7a3
Removing intermediate container 484eee0ee7a3
 ---> 294b4666cb89
Step 4/26 : RUN mv /usr/local/bin/solc /usr/bin/solc-vnightly
 ---> Running in b37f57a80006
Removing intermediate container b37f57a80006
 ---> a0e1111e5c69
Step 5/26 : RUN apk update
 ---> Running in 9a9624ca00c6
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
v3.12.0-175-g8b3334c57c [http://dl-cdn.alpinelinux.org/alpine/v3.12/main]
v3.12.0-177-g0fe5306cd8 [http://dl-cdn.alpinelinux.org/alpine/v3.12/community]
OK: 12749 distinct packages available
Removing intermediate container 9a9624ca00c6
 ---> 77a1a3df4bb3
Step 6/26 : RUN apk upgrade
 ---> Running in 6b77e2915802
(1/6) Upgrading musl (1.1.24-r8 -> 1.1.24-r9)
(2/6) Upgrading busybox (1.31.1-r16 -> 1.31.1-r19)
Executing busybox-1.31.1-r19.post-upgrade
(3/6) Upgrading alpine-baselayout (3.2.0-r6 -> 3.2.0-r7)
Executing alpine-baselayout-3.2.0-r7.pre-upgrade
Executing alpine-baselayout-3.2.0-r7.post-upgrade
(4/6) Upgrading ca-certificates-bundle (20191127-r2 -> 20191127-r4)
(5/6) Upgrading ssl_client (1.31.1-r16 -> 1.31.1-r19)
(6/6) Upgrading musl-utils (1.1.24-r8 -> 1.1.24-r9)
Executing busybox-1.31.1-r19.trigger
OK: 6 MiB in 14 packages
Removing intermediate container 6b77e2915802
 ---> 96484eff236e
Step 7/26 : RUN apk add bash curl
 ---> Running in ccf7a20f6982
(1/8) Installing ncurses-terminfo-base (6.2_p20200523-r0)
(2/8) Installing ncurses-libs (6.2_p20200523-r0)
(3/8) Installing readline (8.0.4-r0)
(4/8) Installing bash (5.0.17-r0)
Executing bash-5.0.17-r0.post-install
(5/8) Installing ca-certificates (20191127-r4)
(6/8) Installing nghttp2-libs (1.41.0-r0)
(7/8) Installing libcurl (7.69.1-r0)
(8/8) Installing curl (7.69.1-r0)
Executing busybox-1.31.1-r19.trigger
Executing ca-certificates-20191127-r4.trigger
OK: 9 MiB in 22 packages
Removing intermediate container ccf7a20f6982
 ---> a6369a194cb0
Step 8/26 : COPY scripts/install_solc.sh /
 ---> a203f5de8ddd
Step 9/26 : COPY scripts/semver.sh /
 ---> a8d143e443e9
Step 10/26 : RUN bash /install_solc.sh
 ---> Running in 9ce07e167f45
[+] successfully downloaded solc 0.6.12
[+] successfully downloaded solc 0.6.11
[+] successfully downloaded solc 0.6.10
[+] successfully downloaded solc 0.6.9
[+] successfully downloaded solc 0.6.8
[+] successfully downloaded solc 0.6.7
[+] successfully downloaded solc 0.6.6
[+] successfully downloaded solc 0.6.5
[+] successfully downloaded solc 0.6.4
[+] successfully downloaded solc 0.6.3
[+] successfully downloaded solc 0.6.2
[+] successfully downloaded solc 0.6.1
[+] successfully downloaded solc 0.6.0
[+] successfully downloaded solc 0.5.17
[+] successfully downloaded solc 0.5.16
[+] successfully downloaded solc 0.5.15
[+] successfully downloaded solc 0.5.14
[+] successfully downloaded solc 0.5.13
[+] successfully downloaded solc 0.5.12
[+] successfully downloaded solc 0.5.11
[+] successfully downloaded solc 0.5.10
[+] successfully downloaded solc 0.5.9
[+] successfully downloaded solc 0.5.8
[+] successfully downloaded solc 0.5.7
[+] successfully downloaded solc 0.5.6
[+] successfully downloaded solc 0.5.5
[+] successfully downloaded solc 0.5.4
[+] successfully downloaded solc 0.5.3
[+] successfully downloaded solc 0.5.2
[+] successfully downloaded solc 0.5.1
[+] successfully downloaded solc 0.5.0
[+] successfully downloaded solc 0.4.26
[+] successfully downloaded solc 0.4.25
[+] successfully downloaded solc 0.4.24
[+] successfully downloaded solc 0.4.23
[+] successfully downloaded solc 0.4.22
[+] successfully downloaded solc 0.4.21
[+] successfully downloaded solc 0.4.20
[+] successfully downloaded solc 0.4.19
[+] successfully downloaded solc 0.4.18
[+] successfully downloaded solc 0.4.17
[+] successfully downloaded solc 0.4.16
[+] successfully downloaded solc 0.4.15
[+] successfully downloaded solc 0.4.14
[+] successfully downloaded solc 0.4.13
[+] successfully downloaded solc 0.4.12
[+] successfully downloaded solc 0.4.11
[+] successfully downloaded solc 0.4.10
[+] successfully downloaded solc 0.4.9
[+] successfully downloaded solc 0.4.8
[+] successfully downloaded solc 0.4.7
[+] successfully downloaded solc 0.4.6
[+] successfully downloaded solc 0.4.5
[+] successfully downloaded solc 0.4.4
[+] successfully downloaded solc 0.4.3
[+] successfully downloaded solc 0.4.2
[+] successfully downloaded solc 0.4.1
[+] successfully downloaded solc 0.4.0
[+] 0.3.6 is too old, not installing
[+] 0.3.5 is too old, not installing
[+] 0.3.4 is too old, not installing
[+] 0.3.3 is too old, not installing
[+] 0.3.2 is too old, not installing
[+] 0.3.1 is too old, not installing
[+] 0.3.0 is too old, not installing
[+] 0.2.2 is too old, not installing
[+] 0.2.1 is too old, not installing
[+] 0.2.0 is too old, not installing
[+] 0.1.7 is too old, not installing
[+] 0.1.6 is too old, not installing
[+] 0.1.5 is too old, not installing
[+] 0.1.4 is too old, not installing
[+] 0.1.3 is too old, not installing
[+] 0.1.2 is too old, not installing
Removing intermediate container 9ce07e167f45
 ---> 8927ae391db8
Step 11/26 : RUN rm /install_solc.sh /semver.sh
 ---> Running in 3b667bfde5af
Removing intermediate container 3b667bfde5af
 ---> 606702e2ac2e
Step 12/26 : COPY scripts/solc-select /usr/bin/
 ---> 756483e90244
Step 13/26 : RUN apk -U add findutils
 ---> Running in 7d3b17739074
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/1) Installing findutils (4.7.0-r0)
Executing busybox-1.31.1-r19.trigger
OK: 10 MiB in 23 packages
Removing intermediate container 7d3b17739074
 ---> 46bcb724dd4f
Step 14/26 : RUN solc-select --list | grep -v nightly | tail -n1 | xargs solc-select
 ---> Running in e742a76f12ca
Removing intermediate container e742a76f12ca
 ---> 89a758e4491a
Step 15/26 : COPY scripts/solc /usr/bin/
 ---> 76865a6d8fc1
Step 16/26 : COPY scripts/solc-wrapper /usr/bin/
 ---> 09bac167f07f
Step 17/26 : COPY scripts/chroot.sh /usr/bin/
 ---> a8dfe5790a6b
Step 18/26 : COPY scripts/install.sh /usr/bin/
 ---> cd947a94eb40
Step 19/26 : COPY bin/solc /etc/solc_template
 ---> a53f3e83a0bf
Step 20/26 : RUN cat /etc/solc_template >> /usr/bin/install.sh
 ---> Running in cf5cdfc25887
Removing intermediate container cf5cdfc25887
 ---> 54302448798e
Step 21/26 : RUN echo EOF >> /usr/bin/install.sh
 ---> Running in af04347dbc6c
Removing intermediate container af04347dbc6c
 ---> 8cba08e7d656
Step 22/26 : RUN echo finalize >> /usr/bin/install.sh
 ---> Running in ef3091f14c0c
Removing intermediate container ef3091f14c0c
 ---> 4bffb194df35
Step 23/26 : RUN rm /etc/solc_template
 ---> Running in dd89750d5977
Removing intermediate container dd89750d5977
 ---> ace2668b8eb4
Step 24/26 : RUN mkdir -p /workdir
 ---> Running in df79826f75bf
Removing intermediate container df79826f75bf
 ---> 25cc87b44499
Step 25/26 : WORKDIR /workdir
 ---> Running in b468c0ab1446
Removing intermediate container b468c0ab1446
 ---> f69281b91ab8
Step 26/26 : ENTRYPOINT ["/usr/bin/solc-wrapper"]
 ---> Running in bd0a1b35da1e
Removing intermediate container bd0a1b35da1e
 ---> 87e94da61857
Successfully built 87e94da61857
Successfully tagged trailofbits/solc-select:latest


harry@bubble solc-select % sudo bin/solc --install                
Password:
Installing solc-select...
Overwrite /usr/local/bin/solc? [yN] y
Installed solc to /usr/local/bin/solc
harry@bubble solc-select % solc --versions
0.6.12
0.6.11
0.6.10
0.6.9
0.6.8
0.6.7
0.6.6
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.17
0.5.16
0.5.15
0.5.14
0.5.13
0.5.12
0.5.11
0.5.10
0.5.9
0.5.8
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.26
0.4.25
0.4.24
0.4.23
0.4.22
0.4.21
0.4.20
0.4.19
0.4.18
0.4.17
0.4.16
0.4.15
0.4.14
0.4.13
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
nightly
harry@bubble solc-select % solc use 0.4.18
Now using version 0.4.18
harry@bubble solc-select % solc --version
solc, the solidity compiler commandline interface
Version: 0.4.18+commit.9cf6e910.Linux.g++
harry@bubble solc-select % >....                                                                                  
0.5.14
...

1 step - install and import Slither, Project Interpreter ->slither-analyzer

form slither import Slither
contracts = Slither(f'./contractsPath/HoloToken.sol')
for contract in contracts:
    if contract == 'HoloToken':
    contract.slither.crytic_compile

2 step install ganache-cli

# you will get an error if the node version is bigger than 12
# first check your current node version 
node --version
# to see available node versions
brew search node
# to unlink from current version
brew unlink node
# install the version e.g. 12
brew install node@12
# to link installed new version
brew link node@12
# to see your new node version
node --version
# if you use npm to install, the following errors may occur:

harry@bubble solc-select % npm install -g ganache-cli
/usr/local/bin/ganache-cli -> /usr/local/lib/node_modules/ganache-cli/cli.js
+ ganache-cli@6.9.1
updated 1 package in 1.655s
harry@bubble solc-select % ganache-cli 
Ganache CLI v6.9.1 (ganache-core: 2.10.2)
Error: Callback was already called.
    at /usr/local/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:17:276
    at s.<anonymous> (/usr/local/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:17:2238)
    at s.emit (events.js:314:20)
    at s.destroy (/usr/local/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:37:712589)
    at finish (_stream_writable.js:658:14)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
harry@bubble solc-select % brew install node@12
Warning: node@12 12.18.2 is already installed and up-to-date
To reinstall 12.18.2, run `brew reinstall node@12`
harry@bubble solc-select % brew update
Already up-to-date.
harry@bubble solc-select % node -v
zsh: command not found: node
harry@bubble solc-select % export PATH="/usr/local/opt/node@12/bin:$PATH"
harry@bubble solc-select % node
Welcome to Node.js v12.18.2.
Type ".help" for more information.
> exit
Uncaught ReferenceError: exit is not defined
> exit
Uncaught ReferenceError: exit is not defined
> 
(To exit, press ^C again or ^D or type .exit)
> 
harry@bubble solc-select % 
harry@bubble solc-select % 
harry@bubble solc-select % ganache-cli                                     
Ganache CLI v6.9.1 (ganache-core: 2.10.2)

Available Accounts
==================
(0) 0xd83FBca51Cced8aA76259aB40089a368F7160359 (100 ETH)
(1) 0x0fF8243ddaCD754D53ADf40e1c06943Df6C867d4 (100 ETH)
(2) 0x6136041E2E79223ae6B8D25B61DC1EC7dc4FB506 (100 ETH)
(3) 0x173E654e6B5bF30fa6E504c7F236Ef0914c6b16d (100 ETH)
(4) 0x67300f8024aE0D9c6944f6fa259950EBB1C060D6 (100 ETH)
(5) 0xc6382e41d19003b490639C5cd116DE5738660C0D (100 ETH)
(6) 0x2E596d37820783C0877c68b3CA394d279596347A (100 ETH)
(7) 0x0C5Cd3D235eAB4440AC96Cf80d436c2D39fd42Be (100 ETH)
(8) 0x2CcF9C3C8CF6c861F340350Bb4f7A0A873e6e07c (100 ETH)
(9) 0x62bfC4D1e94132d51b02Ce8A5EB9080846e23094 (100 ETH)

Private Keys
==================
(0) 0x5c7c76b9f3209a60c4a79753d6c51ccc08bbfcec4579d929effca42b504ab883
(1) 0x743d2d95ef2c35c6c4e6d715fecdba089eef062ba58c8b1d33af9a4b8d16531f
(2) 0x31043908ac069835124df6c6e63943a1227c85952cb45939a3f06ea13815e212
(3) 0x8ee648bbb2d7f8607871854d36e8b3367f95a26348b97a9054036f7a9d3131e6
(4) 0x65030f75ff9bdb9b884250cf54869f86039f5b64f5d4bdd0b4a775e71ef65f02
(5) 0xdec43ffca2df75915ed0067dec5756b1c5275415bcf1000fb46a993328c38335
(6) 0x6e4b998914500c2790a10a8186d188a1d4f087df084a66a577edabf8e69279ec
(7) 0x4c48faa8b2961e1c7adab61dcc2bfb430d3e32c040218c6f90087f57357ed644
(8) 0xc2c28ef964856f5ad1d824658ffcb948372c5ad7d8b71d64ddc5a05cb1e79a6e
(9) 0x3c578ef90582ed204c424a6d03901dddbaa46b3887107949aa294a9cfb0f03e0

HD Wallet
==================
Mnemonic:      crack comic write extra resource wisdom ridge chase buddy slim begin fish
Base HD Path:  m/44'/60'/0'/0/{account_index}

Gas Price
==================
20000000000

Gas Limit
==================
6721975

Call Gas Limit
==================
9007199254740991

ganache-cli --debug

    harry@bubble solc-select % ganache-cli --debug
Ganache CLI v6.9.1 (ganache-core: 2.10.2)

Available Accounts
==================
(0) 0x8a026ba3D0a2c545488DD2B3802D9a52828dE367 (100 ETH)
(1) 0x0a8B6e719Bbf9d54C72ef57a29669C6F57c4a437 (100 ETH)
(2) 0xBF5CC0c7b062c90D1Df6E95A931c8bEcA41C58aB (100 ETH)
(3) 0xd624aEE449F2D8De4Eb58ad25EE149dE9EC966a8 (100 ETH)
(4) 0xDaad295FfC6Fb6fcB3E5140603A34780df092A23 (100 ETH)
(5) 0x2A1CE63aCe3322188C50EbD669141D367bCF2Dc7 (100 ETH)
(6) 0x9fD69cCe3909D7F07541D4dA4EBc83932Bfc4c51 (100 ETH)
(7) 0x22140856690c6723fF35308CC93eCE56c25D91Aa (100 ETH)
(8) 0x29B75Ee1ED4bED2b8B136741227C840daEea5504 (100 ETH)
(9) 0xf71A37348F7BD06965573279342e53AD782e2731 (100 ETH)

Private Keys
==================
(0) 0x40f2e65741977af2799114a7cb5b71968a2d2b637bd7d73667c12cfc13c99b44
(1) 0x5fa6fa447b2b1a174034b4288c9359e2327845597db7c05ea8ea3942586441a2
(2) 0x61572f9926f040325b16340f8dac995ccf8bba405b9f696f72aca5249ca4b56d
(3) 0x673eecf9971e03a94c71b93e08e304b6a3e679a8d686ee4cf17cb8b79059f435
(4) 0xfdb23fede5c68fe71739e3009f9f6f71e5b39c93a4858dd91566e1ab14aabeb5
(5) 0x62f4da2f39e9b75486c4842cdd166ba9d63635e7773b06eeab2f8ca802c26771
(6) 0x5127e9d3c1f9b0ade4d61980c521d9acdbdaedca5597a2f32431ffc3ebd166cf
(7) 0x19dd0077bfe9bd2d40daf6188a26c98e974206f6c48a6c01cd6d5200e54db1a1
(8) 0x8a0e61c3bd9d21134b25db316cd80c97ed05f237944c59fafd921cc9fc111063
(9) 0xaf1259e2e2c0ca233f95dbc71a3956aa6808bb09c241ed94b3e22e3f3e5e05c7

HD Wallet
==================
Mnemonic:      bracket learn fever deposit peanut dilemma celery come jelly stem parrot okay
Base HD Path:  m/44'/60'/0'/0/{account_index}

Gas Price
==================
20000000000

Gas Limit
==================
6721975

Call Gas Limit
==================
9007199254740991

Listening on 127.0.0.1:8545
net_listening
eth_getBlockByNumber
net_version
eth_accounts
net_version
net_version
eth_accounts
net_version
eth_accounts
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
net_version
eth_accounts
eth_getBlockByNumber
net_version
eth_accounts
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
net_version
eth_accounts
net_version
eth_accounts
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBlockByNumber
net_version
eth_accounts
net_version
eth_accounts
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
net_version
eth_accounts
eth_estimateGas
PUSH1
PUSH1
MSTORE
PUSH1
PUSH1
SSTORE
CALLVALUE
DUP1
ISZERO
PUSH2
JUMPI
JUMPDEST
POP
PUSH1
DUP1
PUSH2
PUSH1
CODECOPY
PUSH1
RETURN
PUSH1
PUSH1
MSTORE
PUSH1
PUSH1
SSTORE
CALLVALUE
DUP1
ISZERO
PUSH2
JUMPI
JUMPDEST
POP
PUSH1
DUP1
PUSH2
PUSH1
CODECOPY
PUSH1
RETURN
net_version
eth_sendTransaction
PUSH1
PUSH1
MSTORE
PUSH1
PUSH1
SSTORE
CALLVALUE
DUP1
ISZERO
PUSH2
JUMPI
JUMPDEST
POP
PUSH1
DUP1
PUSH2
PUSH1
CODECOPY
PUSH1
RETURN

  Transaction: 0x624977c17b4f4e5847ed10a8168f47a4b59b80e765157d085182148743e0aa65
  Contract created: 0x702ee9bfdf6d3796531a2ecb4a185f9a54dd08d7
  Gas usage: 122401
  Block Number: 1
  Block Time: Wed Jul 22 2020 22:12:28 GMT-0500 (Central Daylight Time)

net_version
eth_getTransactionReceipt
eth_getTransactionByHash
eth_getTransactionByHash
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getTransactionReceipt
net_version
eth_accounts
eth_getBlockByNumber
net_version
eth_accounts
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
net_version
eth_accounts
net_version
eth_accounts
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBlockByNumber
net_version
eth_accounts
net_version
eth_accounts
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
net_version
eth_accounts
eth_getBlockByNumber
net_version
eth_accounts
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
net_version
eth_accounts
net_version
eth_accounts
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBalance
eth_getBlockByNumber
net_version
eth_accounts
eth_accounts
eth_estimateGas
PUSH1
PUSH1
MSTORE
PUSH1
CALLDATASIZE
LT
PUSH1
JUMPI
PUSH1
CALLDATALOAD
PUSH29
SWAP1
DIV
PUSH4
AND
DUP1
PUSH4
EQ
PUSH1
JUMPI
JUMPDEST
CALLVALUE
DUP1
ISZERO
PUSH1
JUMPI
JUMPDEST
POP
PUSH1
PUSH1
DUP1
CALLDATASIZE
SUB
DUP2
ADD
SWAP1
DUP1
DUP1
CALLDATALOAD
SWAP1
PUSH1
ADD
SWAP1
SWAP3
SWAP2
SWAP1
POP
POP
POP
PUSH1
JUMP
JUMPDEST
DUP1
PUSH1
DUP1
DUP3
DUP3
SLOAD
ADD
SWAP3
POP
POP
DUP2
SWAP1
SSTORE
POP
POP
JUMP
JUMPDEST
STOP
PUSH1
PUSH1
MSTORE
PUSH1
CALLDATASIZE
LT
PUSH1
JUMPI
PUSH1
CALLDATALOAD
PUSH29
SWAP1
DIV
PUSH4
AND
DUP1
PUSH4
EQ
PUSH1
JUMPI
JUMPDEST
CALLVALUE
DUP1
ISZERO
PUSH1
JUMPI
JUMPDEST
POP
PUSH1
PUSH1
DUP1
CALLDATASIZE
SUB
DUP2
ADD
SWAP1
DUP1
DUP1
CALLDATALOAD
SWAP1
PUSH1
ADD
SWAP1
SWAP3
SWAP2
SWAP1
POP
POP
POP
PUSH1
JUMP
JUMPDEST
DUP1
PUSH1
DUP1
DUP3
DUP3
SLOAD
ADD
SWAP3
POP
POP
DUP2
SWAP1
SSTORE
POP
POP
JUMP
JUMPDEST
STOP
net_version
eth_sendTransaction
PUSH1
PUSH1
MSTORE
PUSH1
CALLDATASIZE
LT
PUSH1
JUMPI
PUSH1
CALLDATALOAD
PUSH29
SWAP1
DIV
PUSH4
AND
DUP1
PUSH4
EQ
PUSH1
JUMPI
JUMPDEST
CALLVALUE
DUP1
ISZERO
PUSH1
JUMPI
JUMPDEST
POP
PUSH1
PUSH1
DUP1
CALLDATASIZE
SUB
DUP2
ADD
SWAP1
DUP1
DUP1
CALLDATALOAD
SWAP1
PUSH1
ADD
SWAP1
SWAP3
SWAP2
SWAP1
POP
POP
POP
PUSH1
JUMP
JUMPDEST
DUP1
PUSH1
DUP1
DUP3
DUP3
SLOAD
ADD
SWAP3
POP
POP
DUP2
SWAP1
SSTORE
POP
POP
JUMP
JUMPDEST
STOP

3.remix https://remix.ethereum.org/

Creat a solidity program, select the correct compiler, and compile it. select the web3 provider at the Environment.

Deploy the contract.

Enter the correct parameter value and operate the function call。

check balance value,

Get the transaction hash. 0xa453dc27efe762768cfe628bb92a604d70aea7c5b04d1090a5ce87d93981b402

4. get runtime opcode

import requests
import json
from web3 import Web3

url = 'http://127.0.0.1:8545'
headers = {'Content-Type': 'application/json'}
txHash = '0xa453dc27efe762768cfe628bb92a604d70aea7c5b04d1090a5ce87d93981b402'
data = {
    'id': 1337,
    'jsonrpc': '2.0',
    'method': 'debug_traceTransaction',
    'params': [txHash, {}]
}

r = requests.post(url, data=json.dumps(data), headers=headers)
res = json.loads(r.content)
print(res['result'])

alt

Reference debug_traceTransaction https://github.com/ethereum/go-ethereum/wiki/Management-APIs#debug_tracetransaction

https://github.com/ethereum/go-ethereum/wiki/Management-APIs#debug_tracetransaction

本文链接:https://harry.ren/post/runtimeOpcode+debugTrace.html

-- EOF --

Comments