Skip to content

Commit

Permalink
feat(EVM): Return evm gas used in external create methods (#1130)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov authored Dec 6, 2024
1 parent 0c00649 commit 5ec8486
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
32 changes: 16 additions & 16 deletions system-contracts/SystemContractsHashes.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,49 @@
"contractName": "AccountCodeStorage",
"bytecodePath": "zkout/AccountCodeStorage.sol/AccountCodeStorage.json",
"sourceCodePath": "contracts-preprocessed/AccountCodeStorage.sol",
"bytecodeHash": "0x01000073b3bc1272f774b6d9be05721f6d7eb8d092fdea1b98a6cfaebc31d140",
"bytecodeHash": "0x0100007317994a1fc65998cd916c99f52951e58cefedce3c330aacf7fd20dd94",
"sourceCodeHash": "0xfdac12f45b5cfd4abd12923206f2d6f253d11a6624783e079b55e975d573ceb6"
},
{
"contractName": "BootloaderUtilities",
"bytecodePath": "zkout/BootloaderUtilities.sol/BootloaderUtilities.json",
"sourceCodePath": "contracts-preprocessed/BootloaderUtilities.sol",
"bytecodeHash": "0x010006f3cf25451770a2adca96ba19aa526caccc63ea71cb175969ff2fd48546",
"bytecodeHash": "0x010006f3eaa43c2aeece380d750965b772ae2d8874f942fe598445977118fd23",
"sourceCodeHash": "0x10f30ac1a7098c7fddec2659ac43422783e8d3fdde02a3ba4d3ff45d451d7001"
},
{
"contractName": "ComplexUpgrader",
"bytecodePath": "zkout/ComplexUpgrader.sol/ComplexUpgrader.json",
"sourceCodePath": "contracts-preprocessed/ComplexUpgrader.sol",
"bytecodeHash": "0x010000472e443f07ce828b486959956abf538f1079bf6a48d576d8a586638550",
"bytecodeHash": "0x010000470769b6a1ab43e898daf381c7df9753c51e8001e06b6daa39357f42a8",
"sourceCodeHash": "0x796046a914fb676ba2bbd337b2924311ee2177ce54571c18a2c3945755c83614"
},
{
"contractName": "Compressor",
"bytecodePath": "zkout/Compressor.sol/Compressor.json",
"sourceCodePath": "contracts-preprocessed/Compressor.sol",
"bytecodeHash": "0x0100013fdefa9989778db1a64e851f672c664591ca30cdf5da346ad6096cae57",
"bytecodeHash": "0x0100013f2c94736cbc8e992f7e84df5e01a64d15bf2443c2dda5bee7476c9575",
"sourceCodeHash": "0xc6f7cd8b21aae52ed3dd5083c09b438a7af142a4ecda6067c586770e8be745a5"
},
{
"contractName": "ContractDeployer",
"bytecodePath": "zkout/ContractDeployer.sol/ContractDeployer.json",
"sourceCodePath": "contracts-preprocessed/ContractDeployer.sol",
"bytecodeHash": "0x010006716d699486ec8c5575a116f09c7173e6a1287a23f56dc7a03b695fc7d6",
"sourceCodeHash": "0x5df9078b16d7cfc294017aa1db6a81893853753fc9f767d91c543ec29b7b7555"
"bytecodeHash": "0x01000673f8b088c2c27ab36f025b222a908368fd22b461bf97b12784753b2fea",
"sourceCodeHash": "0xbb9a2717e6fd1da15df4ef1862d2e55e661547f973478bb1fc3cab1ea3cca575"
},
{
"contractName": "Create2Factory",
"bytecodePath": "zkout/Create2Factory.sol/Create2Factory.json",
"sourceCodePath": "contracts-preprocessed/Create2Factory.sol",
"bytecodeHash": "0x0100003f1e72af6311dafd0cfdf6d8b06458657fa0e01504129e8402730a94b0",
"bytecodeHash": "0x0100003ff00c4656ed039bac6da4b2f56c01acf662faff586f7032d33de48634",
"sourceCodeHash": "0x114d9322a9ca654989f3e0b3b21f1311dbc4db84f443d054cd414f6414d84de3"
},
{
"contractName": "DefaultAccount",
"bytecodePath": "zkout/DefaultAccount.sol/DefaultAccount.json",
"sourceCodePath": "contracts-preprocessed/DefaultAccount.sol",
"bytecodeHash": "0x0100050b78c8bba8aa0816a1b754d8cd6647d84de85a00db0bf4fbb603524e51",
"bytecodeHash": "0x0100050bcb0eb0f55ec0821967b509b2ae60fa52ff94f0f934b4de464e2f3a5d",
"sourceCodeHash": "0x300c864fcb3bc6a562875c7b1d83df15d466515da0a878a426b1aaeac26f3656"
},
{
Expand All @@ -59,56 +59,56 @@
"contractName": "ImmutableSimulator",
"bytecodePath": "zkout/ImmutableSimulator.sol/ImmutableSimulator.json",
"sourceCodePath": "contracts-preprocessed/ImmutableSimulator.sol",
"bytecodeHash": "0x010000336a67d5bcf7e6eaaa518fedb0081b3cd8576df3827bc3e2c52c507ecd",
"bytecodeHash": "0x010000338218e48deb166b7e6486e558038239530c8f30bdbc0b15dffc671aa6",
"sourceCodeHash": "0x9659e69f7db09e8f60a8bb95314b1ed26afcc689851665cf27f5408122f60c98"
},
{
"contractName": "KnownCodesStorage",
"bytecodePath": "zkout/KnownCodesStorage.sol/KnownCodesStorage.json",
"sourceCodePath": "contracts-preprocessed/KnownCodesStorage.sol",
"bytecodeHash": "0x010000cde2ac89fde1127da56da7be365205e6728bc6c158e8298809dc4b4de2",
"bytecodeHash": "0x010000cd7ef93ae3e09683ca91c705700694f3f9bd25f5d0d5fecd38d667eccf",
"sourceCodeHash": "0x851fb5e170dfde39f1f9bc74654ec0b8f8f1d4c2fb20c06c77844c1e3ee0659a"
},
{
"contractName": "L1Messenger",
"bytecodePath": "zkout/L1Messenger.sol/L1Messenger.json",
"sourceCodePath": "contracts-preprocessed/L1Messenger.sol",
"bytecodeHash": "0x01000263945edeb299d65573cfe866f0e0be60d9b4a8e2a95f51fa9ac5a53cd2",
"bytecodeHash": "0x01000263345d82f95b6533501ee84340770418287866931d64899423815527f8",
"sourceCodeHash": "0xa8768fdaac6d8804782f14e2a51bbe2b6be31dee9103b6d02d149ea8dc46eb6a"
},
{
"contractName": "L2BaseToken",
"bytecodePath": "zkout/L2BaseToken.sol/L2BaseToken.json",
"sourceCodePath": "contracts-preprocessed/L2BaseToken.sol",
"bytecodeHash": "0x010000db88ef9018d889e667652a27f5d2658aec6886a784a13259e7338c7ca1",
"bytecodeHash": "0x010000dbc44fbd6fd01e930a4cbbb59a17b285bd86fc5dbe11f59d1f375f6286",
"sourceCodeHash": "0xdea518b1ea16718b0f0ec6155b227a8bc8f51374a9eebf7bc17cfe84433df740"
},
{
"contractName": "MsgValueSimulator",
"bytecodePath": "zkout/MsgValueSimulator.sol/MsgValueSimulator.json",
"sourceCodePath": "contracts-preprocessed/MsgValueSimulator.sol",
"bytecodeHash": "0x0100005905d49dbc9a0d6cf2b20ab7a91d78ae90d27405f4345b0514cd677e15",
"bytecodeHash": "0x010000594d78e2e2a0f0fa224c8ba6b3fd8ab8b283bff7420c1b565fe8a61ee7",
"sourceCodeHash": "0x082f3dcbc2fe4d93706c86aae85faa683387097d1b676e7ebd00f71ee0f13b71"
},
{
"contractName": "NonceHolder",
"bytecodePath": "zkout/NonceHolder.sol/NonceHolder.json",
"sourceCodePath": "contracts-preprocessed/NonceHolder.sol",
"bytecodeHash": "0x010000cfc02c13988766e9866f1ab4a3ac8a193e57ac8912e6fd1161948b9d1d",
"bytecodeHash": "0x010000cf17e28b461edeaf764b45bd824cf6b1a653478624bfa361c813a61b5d",
"sourceCodeHash": "0xcd0c0366effebf2c98c58cf96322cc242a2d1c675620ef5514b7ed1f0a869edc"
},
{
"contractName": "PubdataChunkPublisher",
"bytecodePath": "zkout/PubdataChunkPublisher.sol/PubdataChunkPublisher.json",
"sourceCodePath": "contracts-preprocessed/PubdataChunkPublisher.sol",
"bytecodeHash": "0x0100004175cbb16026df5b85b84655b4fb084bb04231a105baebcc8260e5d851",
"bytecodeHash": "0x01000041dab57304eb3d41b96948d580eb388f303bdf058c15b71afcef0ffac0",
"sourceCodeHash": "0xd7161e2c8092cf57b43c6220bc605c0e7e540bddcde1af24e2d90f75633b098e"
},
{
"contractName": "SystemContext",
"bytecodePath": "zkout/SystemContext.sol/SystemContext.json",
"sourceCodePath": "contracts-preprocessed/SystemContext.sol",
"bytecodeHash": "0x010001c58b2d426f41453b876e4c860d931b5442ce46c998bd53e2721507ae72",
"bytecodeHash": "0x010001c54c88a8fb2427458c7b4caddc0c7927e396a60a5e690408d36a25eceb",
"sourceCodeHash": "0xe2f6eb015d260aafe9405b28ef3ec27921add4de7f329b7ef61e0aa6c9365e29"
},
{
Expand Down
16 changes: 10 additions & 6 deletions system-contracts/contracts/ContractDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ contract ContractDeployer is IContractDeployer, SystemContractBase {
/// @notice Deploys an EVM contract using address derivation of EVM's `CREATE` opcode.
/// @param _initCode The init code for the contract.
/// Note: this method may be callable only in system mode.
function createEVM(bytes calldata _initCode) external payable override onlySystemCall returns (address) {
/// @return The amount of EVM gas used.
/// @return The address of created contract.
function createEVM(bytes calldata _initCode) external payable override onlySystemCall returns (uint256, address) {
uint256 senderNonce;
// If the account is an EOA, use the min nonce. If it's a contract, use deployment nonce
if (msg.sender == tx.origin) {
Expand All @@ -189,27 +191,29 @@ contract ContractDeployer is IContractDeployer, SystemContractBase {

address newAddress = Utils.getNewAddressCreateEVM(msg.sender, senderNonce);

_evmDeployOnAddress(msg.sender, newAddress, _initCode);
uint256 evmGasUsed = _evmDeployOnAddress(msg.sender, newAddress, _initCode);

return newAddress;
return (evmGasUsed, newAddress);
}

/// @notice Deploys an EVM contract using address derivation of EVM's `CREATE2` opcode.
/// @param _salt The CREATE2 salt.
/// @param _initCode The init code for the contract.
/// Note: this method may be callable only in system mode.
/// @return The amount of EVM gas used.
/// @return The address of created contract.
function create2EVM(
bytes32 _salt,
bytes calldata _initCode
) external payable override onlySystemCall returns (address) {
) external payable override onlySystemCall returns (uint256, address) {
NONCE_HOLDER_SYSTEM_CONTRACT.incrementDeploymentNonce(msg.sender);
// No collision is possible with the zksync's non-EVM CREATE2, since the prefixes are different
bytes32 bytecodeHash = EfficientCall.keccak(_initCode);
address newAddress = Utils.getNewAddressCreate2EVM(msg.sender, _salt, bytecodeHash);

_evmDeployOnAddress(msg.sender, newAddress, _initCode);
uint256 evmGasUsed = _evmDeployOnAddress(msg.sender, newAddress, _initCode);

return newAddress;
return (evmGasUsed, newAddress);
}

/// @notice Method used by EVM emulator to check if contract can be deployed.
Expand Down
7 changes: 5 additions & 2 deletions system-contracts/contracts/interfaces/IContractDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,12 @@ interface IContractDeployer {
/// @notice Can be called by an account to update its nonce ordering
function updateNonceOrdering(AccountNonceOrdering _nonceOrdering) external;

function createEVM(bytes calldata _initCode) external payable returns (address newAddress);
function createEVM(bytes calldata _initCode) external payable returns (uint256 evmGasUsed, address newAddress);

function create2EVM(bytes32 _salt, bytes calldata _initCode) external payable returns (address);
function create2EVM(
bytes32 _salt,
bytes calldata _initCode
) external payable returns (uint256 evmGasUsed, address newAddress);

/// @notice Returns keccak of EVM bytecode at address if it is an EVM contract. Returns bytes32(0) if it isn't a EVM contract.
function evmCodeHash(address) external view returns (bytes32);
Expand Down

0 comments on commit 5ec8486

Please sign in to comment.