From 4d005d39655da1b888098e843b43cf655bbd68e2 Mon Sep 17 00:00:00 2001 From: Javier Chatruc Date: Tue, 10 Sep 2024 15:19:49 -0300 Subject: [PATCH] Bring missing system contract changes --- .../contracts/ContractDeployer.sol | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/system-contracts/contracts/ContractDeployer.sol b/system-contracts/contracts/ContractDeployer.sol index b002013cf..3b32c7014 100644 --- a/system-contracts/contracts/ContractDeployer.sol +++ b/system-contracts/contracts/ContractDeployer.sol @@ -35,7 +35,7 @@ contract ContractDeployer is IContractDeployer, SystemContractBase { Deployed } - mapping(address => bytes32) public evmCodeHash; + uint256 constant EVM_HASHES_PREFIX = 1 << 254; uint256 public constructorReturnGas; @@ -51,7 +51,7 @@ contract ContractDeployer is IContractDeployer, SystemContractBase { uint256 bytecodeLen = uint256(bytes32(paddedNewDeployedCode[:32])); bytes memory trueBytecode = paddedNewDeployedCode[32:32 + bytecodeLen]; - evmCodeHash[msg.sender] = keccak256(trueBytecode); + _setEvmCodeHash(msg.sender, keccak256(trueBytecode)); constructorReturnGas = constructorGasLeft; // ToDO: use efficient call @@ -68,6 +68,10 @@ contract ContractDeployer is IContractDeployer, SystemContractBase { _; } + function evmCodeHash(address _address) external view returns (bytes32 _hash) { + _hash = _getEvmCodeHash(_address); + } + /// @notice Returns information about a certain account. function getAccountInfo(address _address) external view returns (AccountInfo memory info) { return accountInfo[_address]; @@ -539,7 +543,23 @@ contract ContractDeployer is IContractDeployer, SystemContractBase { } } - require(evmCodeHash[_newAddress] != 0x0, "The code hash must be set after the constructor call"); - emit ContractDeployed(_sender, evmCodeHash[_newAddress], _newAddress); + + bytes32 codeHash = _getEvmCodeHash(_newAddress); + require(codeHash != 0x0, "The code hash must be set after the constructor call"); + emit ContractDeployed(_sender, codeHash, _newAddress); + } + + function _setEvmCodeHash(address _address, bytes32 _hash) internal { + assembly { + let slot := or(EVM_HASHES_PREFIX, _address) + sstore(slot, _hash) + } + } + + function _getEvmCodeHash(address _address) internal view returns (bytes32 _hash) { + assembly { + let slot := or(EVM_HASHES_PREFIX, _address) + _hash := sload(slot) + } } }