Skip to content

Commit

Permalink
Bring missing system contract changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchatruc committed Sep 10, 2024
1 parent fe5d5f5 commit 4d005d3
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions system-contracts/contracts/ContractDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract ContractDeployer is IContractDeployer, SystemContractBase {
Deployed
}

mapping(address => bytes32) public evmCodeHash;
uint256 constant EVM_HASHES_PREFIX = 1 << 254;

Check failure on line 38 in system-contracts/contracts/ContractDeployer.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state

Check failure on line 38 in system-contracts/contracts/ContractDeployer.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state

Check failure on line 38 in system-contracts/contracts/ContractDeployer.sol

View workflow job for this annotation

GitHub Actions / lint

Explicitly mark visibility of state

uint256 public constructorReturnGas;

Expand All @@ -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
Expand All @@ -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];
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit 4d005d3

Please sign in to comment.