Skip to content

Commit

Permalink
Revamp detecting constructor arguments (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
kigawas authored Nov 26, 2022
1 parent 6954d5c commit ccff03c
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 64 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ repos:
pass_filenames: false

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: check-yaml

- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
# allow "imported but unused" for pre-commit, forbid it elsewhere e.g. in vscode
Expand Down
40 changes: 20 additions & 20 deletions poetry.lock

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

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pycryptodome = "^3.15.0"

[tool.poetry.dev-dependencies]
black = "^22.10.0"
flake8 = "^5.0.4"
flake8 = {version = "^6.0.0", python = "^3.8.1"}
ipython = {version = "^8.6.0", python = "^3.8"}
mypy = "^0.991"

Expand Down
6 changes: 4 additions & 2 deletions tests/data/caller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Made with Remix IDE

"""
// SPDX-License-Identifier: GPL-3.0
Expand All @@ -12,7 +14,7 @@
}
"""

CALLER_CONTRACT_ABI = [
CALLER_ABI = [
{
"inputs": [{"internalType": "address", "name": "_addr", "type": "address"}],
"stateMutability": "nonpayable",
Expand All @@ -21,7 +23,7 @@
]


CALLER_CONSTRUCTOR_CALL_INPUT = (
CALLER_CONSTRUCTOR_CALL_INPUT_WITHOUT_BYTECODE = (
"0x0000000000000000000000000000000000000000000000000000000000000002"
)

Expand Down
9 changes: 3 additions & 6 deletions tests/data/example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Made with Remix IDE
"""
// SPDX-License-Identifier: GPL-3.0
Expand Down Expand Up @@ -25,7 +26,7 @@
}
"""

EXAMPLE_CONTRACT_ABI = [
EXAMPLE_ABI = [
{
"inputs": [
{"internalType": "uint256", "name": "num", "type": "uint256"},
Expand All @@ -39,13 +40,9 @@
"type": "constructor",
}
]

EXAMPLE_BYTECODE = "0x608060405234801561001057600080fd5b50604051610353380380610353833981810160405260c081101561003357600080fd5b8151602083015160408085018051915193959294830192918464010000000082111561005e57600080fd5b90830190602082018581111561007357600080fd5b825164010000000081118282018810171561008d57600080fd5b82525081516020918201929091019080838360005b838110156100ba5781810151838201526020016100a2565b50505050905090810190601f1680156100e75780820380516001836020036101000a031916815260200191505b506040526020018051604051939291908464010000000082111561010a57600080fd5b90830190602082018581111561011f57600080fd5b825186602082028301116401000000008211171561013c57600080fd5b82525081516020918201928201910280838360005b83811015610169578181015183820152602001610151565b50505050919091016040908152602083810151939091015160008a90556001805460ff19168a1515179055875193955093506101ac926002925090870190610210565b5082516101c090600390602086019061029c565b506004805483919060ff191660018360038111156101da57fe5b0217905550600480546001600160a01b0390921661010002610100600160a81b0319909216919091179055506103069350505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282610246576000855561028c565b82601f1061025f57805160ff191683800117855561028c565b8280016001018555821561028c579182015b8281111561028c578251825591602001919060010190610271565b506102989291506102f1565b5090565b82805482825590600052602060002090810192821561028c579160200282015b8281111561028c57825182546001600160a01b0319166001600160a01b039091161782556020909201916001909101906102bc565b5b8082111561029857600081556001016102f2565b603f806103146000396000f3fe6080604052600080fdfea2646970667358221220a75435b85057a239995042116d1f84a8c1d97199bcc159a3927fccf5b9bb703364736f6c63430007060033"

EXAMPLE_CONSTRUCTOR_CALL_INPUT = "0x608060405234801561001057600080fd5b50604051610353380380610353833981810160405260c081101561003357600080fd5b8151602083015160408085018051915193959294830192918464010000000082111561005e57600080fd5b90830190602082018581111561007357600080fd5b825164010000000081118282018810171561008d57600080fd5b82525081516020918201929091019080838360005b838110156100ba5781810151838201526020016100a2565b50505050905090810190601f1680156100e75780820380516001836020036101000a031916815260200191505b506040526020018051604051939291908464010000000082111561010a57600080fd5b90830190602082018581111561011f57600080fd5b825186602082028301116401000000008211171561013c57600080fd5b82525081516020918201928201910280838360005b83811015610169578181015183820152602001610151565b50505050919091016040908152602083810151939091015160008a90556001805460ff19168a1515179055875193955093506101ac926002925090870190610210565b5082516101c090600390602086019061029c565b506004805483919060ff191660018360038111156101da57fe5b0217905550600480546001600160a01b0390921661010002610100600160a81b0319909216919091179055506103069350505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282610246576000855561028c565b82601f1061025f57805160ff191683800117855561028c565b8280016001018555821561028c579182015b8281111561028c578251825591602001919060010190610271565b506102989291506102f1565b5090565b82805482825590600052602060002090810192821561028c579160200282015b8281111561028c57825182546001600160a01b0319166001600160a01b039091161782556020909201916001909101906102bc565b5b8082111561029857600081556001016102f2565b603f806103146000396000f3fe6080604052600080fdfea2646970667358221220a75435b85057a239995042116d1f84a8c1d97199bcc159a3927fccf5b9bb703364736f6c634300070600330000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000036161610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"


EXAMPLE_CONTRACT_BYTECODE = "0x608060405234801561001057600080fd5b50604051610353380380610353833981810160405260c081101561003357600080fd5b8151602083015160408085018051915193959294830192918464010000000082111561005e57600080fd5b90830190602082018581111561007357600080fd5b825164010000000081118282018810171561008d57600080fd5b82525081516020918201929091019080838360005b838110156100ba5781810151838201526020016100a2565b50505050905090810190601f1680156100e75780820380516001836020036101000a031916815260200191505b506040526020018051604051939291908464010000000082111561010a57600080fd5b90830190602082018581111561011f57600080fd5b825186602082028301116401000000008211171561013c57600080fd5b82525081516020918201928201910280838360005b83811015610169578181015183820152602001610151565b50505050919091016040908152602083810151939091015160008a90556001805460ff19168a1515179055875193955093506101ac926002925090870190610210565b5082516101c090600390602086019061029c565b506004805483919060ff191660018360038111156101da57fe5b0217905550600480546001600160a01b0390921661010002610100600160a81b0319909216919091179055506103069350505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282610246576000855561028c565b82601f1061025f57805160ff191683800117855561028c565b8280016001018555821561028c579182015b8281111561028c578251825591602001919060010190610271565b506102989291506102f1565b5090565b82805482825590600052602060002090810192821561028c579160200282015b8281111561028c57825182546001600160a01b0319166001600160a01b039091161782556020909201916001909101906102bc565b5b8082111561029857600081556001016102f2565b603f806103146000396000f3fe6080604052600080fdfea2646970667358221220a75435b85057a239995042116d1f84a8c1d97199bcc159a3927fccf5b9bb703364736f6c63430007060033"

EXAMPLE_CONSTRUCTOR_CALL_ARGUMENT = [
("uint256", "num", 0),
("bool", "_enable", False),
Expand Down
36 changes: 36 additions & 0 deletions tests/data/storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Made with Remix IDE

"""
pragma solidity >=0.7.0 <0.9.0;
contract Storage {
uint256[] numbers;
constructor (uint256[] memory _nums) {
numbers = _nums;
}
function retrieve() public view returns (uint256[] memory){
return numbers;
}
}
"""

STORAGE_ABI = [
{
"inputs": [{"internalType": "uint256[]", "name": "_nums", "type": "uint256[]"}],
"stateMutability": "nonpayable",
"type": "constructor",
},
{
"inputs": [],
"name": "retrieve",
"outputs": [{"internalType": "uint256[]", "name": "", "type": "uint256[]"}],
"stateMutability": "view",
"type": "function",
},
]
STORAGE_BYTECODE = "0x608060405234801561001057600080fd5b506040516104813803806104818339818101604052810190610032919061016c565b806000908051906020019061004892919061004f565b50506102ac565b82805482825590600052602060002090810192821561008b579160200282015b8281111561008a57825182559160200191906001019061006f565b5b509050610098919061009c565b5090565b5b808211156100b557600081600090555060010161009d565b5090565b60006100cc6100c7846101da565b6101b5565b905080838252602082019050828560208602820111156100ef576100ee610275565b5b60005b8581101561011f57816101058882610157565b8452602084019350602083019250506001810190506100f2565b5050509392505050565b600082601f83011261013e5761013d610270565b5b815161014e8482602086016100b9565b91505092915050565b60008151905061016681610295565b92915050565b6000602082840312156101825761018161027f565b5b600082015167ffffffffffffffff8111156101a05761019f61027a565b5b6101ac84828501610129565b91505092915050565b60006101bf6101d0565b90506101cb8282610210565b919050565b6000604051905090565b600067ffffffffffffffff8211156101f5576101f4610241565b5b602082029050602081019050919050565b6000819050919050565b61021982610284565b810181811067ffffffffffffffff8211171561023857610237610241565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b61029e81610206565b81146102a957600080fd5b50565b6101c6806102bb6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80632e64cec114610030575b600080fd5b61003861004e565b604051610045919061012b565b60405180910390f35b6060600080548060200260200160405190810160405280929190818152602001828054801561009c57602002820191906000526020600020905b815481526020019060010190808311610088575b5050505050905090565b60006100b2838361011c565b60208301905092915050565b60006100c98261015d565b6100d38185610175565b93506100de8361014d565b8060005b8381101561010f5781516100f688826100a6565b975061010183610168565b9250506001810190506100e2565b5085935050505092915050565b61012581610186565b82525050565b6000602082019050818103600083015261014581846100be565b905092915050565b6000819050602082019050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600081905091905056fea26469706673582212209414c410f7b7ebbe78b90880f5478a19e5ff8b6ff64816f86b5bdaa2a8854ee564736f6c63430008070033"
STORAGE_CONSTRUCTOR_CALL_INPUT = "0x608060405234801561001057600080fd5b506040516104813803806104818339818101604052810190610032919061016c565b806000908051906020019061004892919061004f565b50506102ac565b82805482825590600052602060002090810192821561008b579160200282015b8281111561008a57825182559160200191906001019061006f565b5b509050610098919061009c565b5090565b5b808211156100b557600081600090555060010161009d565b5090565b60006100cc6100c7846101da565b6101b5565b905080838252602082019050828560208602820111156100ef576100ee610275565b5b60005b8581101561011f57816101058882610157565b8452602084019350602083019250506001810190506100f2565b5050509392505050565b600082601f83011261013e5761013d610270565b5b815161014e8482602086016100b9565b91505092915050565b60008151905061016681610295565b92915050565b6000602082840312156101825761018161027f565b5b600082015167ffffffffffffffff8111156101a05761019f61027a565b5b6101ac84828501610129565b91505092915050565b60006101bf6101d0565b90506101cb8282610210565b919050565b6000604051905090565b600067ffffffffffffffff8211156101f5576101f4610241565b5b602082029050602081019050919050565b6000819050919050565b61021982610284565b810181811067ffffffffffffffff8211171561023857610237610241565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b61029e81610206565b81146102a957600080fd5b50565b6101c6806102bb6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80632e64cec114610030575b600080fd5b61003861004e565b604051610045919061012b565b60405180910390f35b6060600080548060200260200160405190810160405280929190818152602001828054801561009c57602002820191906000526020600020905b815481526020019060010190808311610088575b5050505050905090565b60006100b2838361011c565b60208301905092915050565b60006100c98261015d565b6100d38185610175565b93506100de8361014d565b8060005b8381101561010f5781516100f688826100a6565b975061010183610168565b9250506001810190506100e2565b5085935050505092915050565b61012581610186565b82525050565b6000602082019050818103600083015261014581846100be565b905092915050565b6000819050602082019050919050565b600081519050919050565b6000602082019050919050565b600082825260208201905092915050565b600081905091905056fea26469706673582212209414c410f7b7ebbe78b90880f5478a19e5ff8b6ff64816f86b5bdaa2a8854ee564736f6c6343000807003300000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003"
STORAGE_CONSTRUCTOR_CALL_ARGUMENT = [("uint256[]", "_nums", (1, 2, 3))]
8 changes: 4 additions & 4 deletions tests/data/tether.py

Large diffs are not rendered by default.

Loading

0 comments on commit ccff03c

Please sign in to comment.