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

Support deterministic deployment of contracts #353

Merged
merged 16 commits into from
Jul 18, 2024
Merged

Conversation

anishnaik
Copy link
Collaborator

@anishnaik anishnaik commented May 1, 2024

closes #333

@anishnaik anishnaik requested a review from Xenomega as a code owner May 1, 2024 21:27
Comment on lines 328 to 356
// Identify which contracts need to be predeployed to a deterministic address by iterating across the mapping
contractAddressOverrides := make(map[common.Hash]common.Address, 0)
for contractName, addrStr := range f.config.Fuzzing.PredeployedContracts {
found := false
// Try to find the associated compilation artifact
for _, contract := range f.contractDefinitions {
if contract.Name() == contractName {
// Hash the init bytecode (so that it can be easily identified in the EVM) and map it to the
// requested address
initBytecodeHash := crypto.Keccak256Hash(contract.CompiledContract().InitBytecode)
contractAddr, err := utils.HexStringToAddress(addrStr)
if err != nil {
return nil, fmt.Errorf("invalid address provided for a predeployed contract: %v", contract.Name())
}
contractAddressOverrides[initBytecodeHash] = contractAddr
found = true
break
}
}

// Throw an error if the contract specified in the config is not found
if !found {
return nil, fmt.Errorf("%v was specified in the predeployed contracts but was not found in the compilation artifacts", contractName)
}
}

// Update the test chain config with the contract address overrides
f.config.Fuzzing.TestChainConfig.ContractAddressOverrides = contractAddressOverrides

Copy link
Collaborator Author

@anishnaik anishnaik May 1, 2024

Choose a reason for hiding this comment

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

I really really hate that I had to sort of replicate this logic again but I couldn't think of another way of translating contract name -> compilation artifact before passing the information to the test chain.

I can add a TODO to make this a refactor when we merge the logic for deployments, corpus replays, and call sequence executions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Feedback on maybe placing this elsewhere is also greatly appreciated.

fuzzing/fuzzer.go Outdated Show resolved Hide resolved
@0xalpharush
Copy link
Contributor

Is there any reason we can't insert into the stateDB directly?
https://github.com/ethereum/go-ethereum/blob/8d42e115b1cae4f09fd02b71c06ec9c85f22ad4f/cmd/evm/runner.go#L264-L264

# Conflicts:
#	fuzzing/fuzzer.go
# Conflicts:
#	chain/test_chain.go
#	chain/vendored/apply_transaction.go
#	fuzzing/fuzzer.go
#	go.mod
#	go.sum
@anishnaik anishnaik requested a review from 0xalpharush July 18, 2024 14:38
@0xalpharush 0xalpharush merged commit 0ce00fd into master Jul 18, 2024
12 checks passed
@0xalpharush 0xalpharush deleted the dev/deploy-contracts branch July 18, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Add ability to deterministically deploy bytecode to specific addresses
2 participants