EVM Kernel: Enable migration logic for predeployed contracts
What
The initialization mechanism for predeployed contracts (such as the withdrawal and bridge contracts) is updated to support overwriting existing bytecode with a newer version, effectively enabling migration logic during kernel initialization.
Why
Previously, the initialization logic would strictly check if any code existed at the target address. If the code hash was not empty, it assumed the contract was already correctly deployed and skipped execution. This behavior prevented the kernel from updating these predeployed contracts when their Solidity implementation changed, as the presence of the old version blocked the installation of the new one.
How
The init_precompile_bytecode function is modified to accept the
expected code_hash as an argument. Instead of returning early merely
if the account code is not empty, it now returns early only if the
current on-chain code hash matches the expected hash. If there is a
mismatch (and the account is not empty), the function now explicitly
deletes the old code via CodeStorage::delete before proceeding to
write the new bytecode. The call sites in init_precompile_bytecodes
are updated to pass the specific code hashes for the internal
forwarder, withdrawal, and FA bridge contracts.
Manual tests
You can use the Tezt scenario introduced in this branch and test it with Farfadet’s kernel and with the latest kernel. The former will fail, the latter will succeed
Checklist
- Document the interface of any function added or modified (see the coding guidelines)
- Document any change to the user interface, including configuration parameters (see node configuration)
- Provide automatic testing (see the testing guide).
-
For new features and bug fixes, add an item in the appropriate changelog (
docs/protocols/alpha.rstfor the protocol and the environment,CHANGES.rstat the root of the repository for everything else). -
Select suitable reviewers using the
Reviewersfield below. -
Select as
Assigneethe next person who should take action on that MR