AST parser from solc json file
Project description
An AST parser for solc json outputs
Parsing AST with solidity source code and get contract information.
Quickstart
Installation
Clone this repository and install it with pip:
git clone https://github.com/sbip-sg/solc-json-parser.git
cd solc-json-parser
pip install .
Usage
Example usage using standard json:
import json
from solc_json_parser.standard_json_parser import StandardJsonParser
with open('contracts/standard_json/75b8.standard-input.json') as f:
input_json = json.load(f)
version = '0.8.4'
parser = StandardJsonParser(input_json, version)
# Get all contract names
parser.all_contract_names
# ['IERC1271',
# ...
# 'ContractKeys',
# 'NFTfiSigningUtils',
# 'NftReceiver',
# 'Ownable']
# Get source code by PC
source = parser.source_by_pc('DirectLoanFixedOffer', 13232)
source
# {'pc': 13232,
# 'linenums': [921, 924],
# 'fragment': 'LoanChecksAndCalculations.computeRevenueShare(\n adminFee,\n loanExtras.revenueShareInBasisPoints\n )',
# 'fid': 'contracts/loans/direct/loanTypes/DirectLoanBaseMinimal.sol',
# 'begin': 45007,
# 'end': 45134,
# 'source_idx': 26,
# 'source_path': 'contracts/loans/direct/loanTypes/DirectLoanBaseMinimal.sol'}
# Get function AST unit by PC
func = parser.function_unit_by_pc('DirectLoanFixedOffer', 13232)
# Parameter names of this function
[n.get('name') for n in func.get('parameters').get('parameters')]
# ['_loanId', '_borrower', '_lender', '_loan']
# Function selector, available only for external or public functions
func.get('functionSelector')
# Get the innermost AST unit by PC
parser.ast_unit_by_pc('DirectLoanFixedOffer', 13232)
Command line tools
solc-json-parser --help
Decode binary to opcodes:
❯ solc-json-parser dp 0x60806040525f80fdfea26469706673582212200466fd4ed0d73499199c39545f7019da158defa354cc0051afe02754ec8e32b464736f6c63430008180033
PUSH1 0x80
PUSH1 0x40
MSTORE
PUSH0 0x
DUP1
REVERT
INVALID
LOG2
PUSH5 0x6970667358
0X22
SLT
SHA3
DIV
PUSH7 0xfd4ed0d7349919
SWAP13
...
Note
- This library only supports detecting Solidity version newer than or equal to
v0.4.11. This is due to the limitation of the base library py-solc-x.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
solc-json-parser-0.1.9.tar.gz
(47.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file solc-json-parser-0.1.9.tar.gz.
File metadata
- Download URL: solc-json-parser-0.1.9.tar.gz
- Upload date:
- Size: 47.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d9d5d2c7c88fdc05c8610a5062acd3f0b86bbff7a3a7a034c94026c8c9c88b1
|
|
| MD5 |
41076957024763331d28438152527755
|
|
| BLAKE2b-256 |
401b1f16f3b5acefedea62272f04a1fe82e5aece7174529a3d7d2ed4a30a0eb1
|
File details
Details for the file solc_json_parser-0.1.9-py3-none-any.whl.
File metadata
- Download URL: solc_json_parser-0.1.9-py3-none-any.whl
- Upload date:
- Size: 43.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ed3b503dbe2aa63d79a37e48c426563730493f91b17e1dccaedd0c49dd93226
|
|
| MD5 |
ac5f345bcec436b94c722aba65f21ddd
|
|
| BLAKE2b-256 |
5f02b274ff0260504cf1f8fddf7aa223cef1f216705319e4a62d37ed0672a847
|