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

[EVM-Equivalence-YUL] Implement evmCodeHash without mapping #751

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions system-contracts/contracts/ContractDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract ContractDeployer is IContractDeployer, ISystemContract {
Deployed
}

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

uint256 public constructorReturnGas;

Expand All @@ -43,7 +43,7 @@ contract ContractDeployer is IContractDeployer, ISystemContract {
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 @@ -58,6 +58,10 @@ contract ContractDeployer is IContractDeployer, ISystemContract {
_;
}

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 @@ -505,6 +509,20 @@ contract ContractDeployer is IContractDeployer, ISystemContract {
}
}

require(evmCodeHash[_newAddress] != 0x0, "The code hash must be set after the constructor call");
require(_getEvmCodeHash(_newAddress) != 0x0, "The code hash must be set after the constructor call");
}

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)
}
}
}
Loading