Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp(contracts): Improve make command to compile smart contracts #2487

Merged
merged 57 commits into from May 1, 2024

Conversation

MalteHerrmann
Copy link
Contributor

@MalteHerrmann MalteHerrmann commented Apr 17, 2024

Description

This PR is tackling something that has bugged me for a long time, which is that the compilation of the JSON data for smart contracts was not as easily done as I would have liked it to be. E.g. for the files in the testdata in the precompiles, one would have to add those into Remix along with all other related contracts, then compile them, stringify the ABI and copy the bytecode into the corresponding JSON file.

To make this easier, I've turned the contracts subdirectory into a Hardhat project and built the compile_smart_contracts.py script. This is scanning the repository for available Solidity smart contracts with a corresponding JSON file, copies all available .sol files, compiles them, and then overwrites the available JSON files with the updated version.

To compile the available smart contracts, run:

make contracts-compile

To clean the contracts directory from build artifacts and downloaded dependencies, run:

make contracts-clean

In order to add a new contract, for which a corresponding JSON file should be generated, run:

make contracts-add CONTRACT=[PATH/TO/CONTRACT].sol

In order to support the structure of JSON files generated by Hardhat, it was necessary to add a new type evmtypes.HardhatCompiledContract, which contains a method to convert those into the expected evmtypes.CompiledContract which is the prior format.

In addition to the changes above, @GAtom22 pointed out that the instantiation of the smart contracts in init() functions is very noisy as test-related data is set up every time that a production node is started. This is cleaned up in this PR as well by introducing dedicated functions to load the contracts in the tests.


Closes: ENG-1777

Copy link

linear bot commented Apr 17, 2024

Signed-off-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com>
Copy link
Contributor

@GAtom22 GAtom22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @MalteHerrmann!!
Left a few questions

x/evm/types/compiled_contract.go Outdated Show resolved Hide resolved
x/evm/types/compiled_contract.go Outdated Show resolved Hide resolved
x/evm/types/compiled_contract.go Outdated Show resolved Hide resolved
x/evm/types/compiled_contract_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@0xstepit 0xstepit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @MalteHerrmann! 👏 left some nits

scripts/compile_smart_contracts/README.md Outdated Show resolved Hide resolved
x/evm/types/compiled_contract_test.go Outdated Show resolved Hide resolved
x/evm/keeper/testdata/contracts.go Outdated Show resolved Hide resolved
x/evm/statedb/testdata/flash_loan.go Show resolved Hide resolved
x/erc20/keeper/testdata/erc20maliciousdelayed.go Outdated Show resolved Hide resolved
x/erc20/keeper/testdata/erc20DirectBalanceManipulation.go Outdated Show resolved Hide resolved
Makefile Show resolved Hide resolved
scripts/compile_smart_contracts/README.md Outdated Show resolved Hide resolved
MalteHerrmann and others added 9 commits April 24, 2024 11:40
Co-authored-by: Ramiro Carlucho <ramirocarlucho@gmail.com>
Co-authored-by: stepit <48993133+0xstepit@users.noreply.github.com>
Signed-off-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com>
# Conflicts:
#	CHANGELOG.md
#	contracts/erc20.go
#	contracts/erc20DirectBalanceManipulation.go
#	contracts/erc20burnable.go
#	contracts/erc20maliciousdelayed.go
#	contracts/flash_loan.go
#	precompiles/bank/testdata/bank.go
#	precompiles/distribution/integration_test.go
#	precompiles/erc20/testdata/erc20_allowance_caller.go
#	precompiles/erc20/testdata/erc20_no_metadata.go
#	precompiles/erc20/testdata/erc20minter_openzeppelinv5.go
#	precompiles/ics20/integration_test.go
#	precompiles/staking/integration_test.go
#	precompiles/staking/testdata/staking_caller.go
#	precompiles/testutil/contracts/distribution_caller.go
#	precompiles/testutil/contracts/interchain_sender.go
#	precompiles/vesting/integration_test.go
#	precompiles/vesting/testdata/vesting_caller.go
#	precompiles/werc20/testdata/wevmos.go
#	x/erc20/keeper/utils_test.go
#	x/evm/statedb/integration_test.go
@MalteHerrmann MalteHerrmann dismissed GAtom22’s stale review April 24, 2024 14:43

addressed the comments

contracts/utils/utils.go Dismissed Show dismissed Hide dismissed
contracts/utils/utils.go Outdated Show resolved Hide resolved
contracts/utils/utils.go Outdated Show resolved Hide resolved
contracts/utils/utils.go Outdated Show resolved Hide resolved
contracts/utils/utils.go Outdated Show resolved Hide resolved
scripts/compile_smart_contracts/README.md Outdated Show resolved Hide resolved
MalteHerrmann and others added 4 commits April 24, 2024 17:12
Signed-off-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com>
Signed-off-by: MalteHerrmann <42640438+MalteHerrmann@users.noreply.github.com>
@MalteHerrmann MalteHerrmann enabled auto-merge (squash) May 1, 2024 11:12
@MalteHerrmann MalteHerrmann merged commit 91319d2 into main May 1, 2024
44 of 46 checks passed
@MalteHerrmann MalteHerrmann deleted the malte/improve-sc-compilation branch May 1, 2024 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants