-
Notifications
You must be signed in to change notification settings - Fork 47
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
Conversation
fuzzing/fuzzer.go
Outdated
// 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 | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Is there any reason we can't insert into the stateDB directly? |
# Conflicts: # fuzzing/fuzzer.go
# Conflicts: # chain/test_chain.go # chain/vendored/apply_transaction.go # fuzzing/fuzzer.go # go.mod # go.sum
closes #333