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

feat(vm): EVM emulator support – base #2979

Merged
merged 85 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
bbd7db9
Make address optional in transaction data
IAvecilla Sep 11, 2024
4e6bed2
Add migrations and update queries with evm simulator
IAvecilla Sep 11, 2024
723c5e3
Add evm simulator as base system contract and update callers
IAvecilla Sep 11, 2024
3a3a300
Add ts tests and contracts for evm simulator
IAvecilla Sep 11, 2024
8132132
Update multivm bootloaders bin files for vm1_5_0
IAvecilla Sep 11, 2024
6cae61a
Update lock file
IAvecilla Sep 11, 2024
dfef5ea
Update contracts submodule
IAvecilla Sep 11, 2024
ddc35de
Improve get contract address for sql queries
IAvecilla Sep 12, 2024
cf454e2
Merge branch 'main' into tx-to-optional-address
IAvecilla Sep 12, 2024
a5c22ea
Make recipient address optional for L2Tx
IAvecilla Sep 12, 2024
c075fb4
Fix error lints
IAvecilla Sep 12, 2024
6c94de9
Insert null in sql for contract address instead of empty bytes
IAvecilla Sep 17, 2024
b280eb3
Remove require and support None value for protobuff Transaction
IAvecilla Sep 17, 2024
d49f3f8
Make address optional for Transaction recipient account
IAvecilla Sep 17, 2024
5e9179d
Optionally add contract address to transaction signature
IAvecilla Sep 17, 2024
0034e3e
Check address is not null and reject transaction
IAvecilla Sep 17, 2024
d9e2b9a
Merge branch 'main' into tx-to-optional-address
IAvecilla Sep 17, 2024
9c3dad1
Make test only Execute to always have a valid address instead of null
IAvecilla Sep 17, 2024
9652368
Update execute use for tests in multivm crate to have a valid contrac…
IAvecilla Sep 17, 2024
189e591
Update comment for optional field in execute proto message
IAvecilla Sep 18, 2024
2ac399e
Unwrap contract address for l1 tx since it should always be present
IAvecilla Sep 18, 2024
6be103f
Merge branch 'main' into tx-to-optional-address
IAvecilla Sep 18, 2024
9700ff3
Merge branch 'tx-to-optional-address' into evm-simulator-base-sc
jrchatruc Sep 18, 2024
be77938
Remove tests for the evm simulator
IAvecilla Sep 19, 2024
f8816cf
Merge remote-tracking branch 'upstream/main' into evm-simulator-base-sc
jrchatruc Sep 19, 2024
7608ace
Delete contracts and aux functions used for evm tests
IAvecilla Sep 19, 2024
ed97d24
Fix fmt
IAvecilla Sep 19, 2024
f922068
feat: EVM simulator as optional for the server (#276)
IAvecilla Sep 19, 2024
2388ae8
Revert multivm bootloader change
jrchatruc Sep 19, 2024
00f0324
Check for evm simulator to avoid failing for transactions with null c…
IAvecilla Sep 19, 2024
c14b5aa
Fix multicall with evm simulator on
IAvecilla Sep 19, 2024
c8d1896
Fix multicall when evm simulator is absent
IAvecilla Sep 19, 2024
072222d
Remove hardcoded hash for evm simulator when its not enabled
IAvecilla Sep 20, 2024
a08ea6c
Fix format
IAvecilla Sep 20, 2024
5bdabe3
Check for evm simulator in execute_internal_transfer_test function
IAvecilla Sep 20, 2024
1385cb6
Merge branch 'main' into evm-simulator-base-sc
IAvecilla Sep 24, 2024
9010c56
Fix doc comment for UseEvmSimulator config
IAvecilla Sep 24, 2024
774b848
Remove evm simulator code hash from miniblocks table
IAvecilla Sep 24, 2024
e85228b
Fix review comments
IAvecilla Sep 24, 2024
0f7c5da
Update sqlx cached queries
IAvecilla Sep 25, 2024
b5c7544
Fix lints and format
IAvecilla Sep 25, 2024
9b0590d
Merge branch 'main' into evm-simulator-base-sc
IAvecilla Sep 25, 2024
653b543
Add evm simulator config to load config function
IAvecilla Sep 25, 2024
d2d61a4
Add evm simulator to general test config and protobuf message
IAvecilla Sep 25, 2024
44e714b
Add use evm simulator config to general config file
IAvecilla Sep 25, 2024
e4aee9b
Make EVM simulator optional
slowli Sep 26, 2024
a7d45b0
Remove garbage deps from `multivm`
slowli Sep 26, 2024
9b04a75
Remove garbage deps from `types`
slowli Sep 26, 2024
613abae
Resolve some nits
slowli Sep 27, 2024
5d21e75
Change `new_known_factory_deps` type
slowli Sep 27, 2024
a80d649
Revert changes in `multivm` unit tests
slowli Sep 27, 2024
ff0b1e8
Remove `UseEvmSimulator` config
slowli Sep 27, 2024
21ef547
Revert changes in config files
slowli Sep 27, 2024
1a0c00c
Sketch EVM simulator switch in API server
slowli Sep 27, 2024
e63ac21
Disable EVM simulator for some tests
slowli Sep 27, 2024
6342503
Fix SQL queries with EVM simulator hash
slowli Sep 27, 2024
68e2647
Fix `creating_block_args_after_snapshot_recovery` test
slowli Sep 27, 2024
5a9b8e3
Load EVM simulator during genesis if appropriate
slowli Sep 27, 2024
ee5f98f
Update from upstream
slowli Sep 27, 2024
8b05e37
Remove unnecessary deps from `contracts`
slowli Sep 27, 2024
d0440aa
Return `miniblocks.evm_simulator_code_hash`
slowli Sep 27, 2024
1828756
Fix env config test
slowli Sep 27, 2024
41fa851
Fix witness generator
slowli Sep 27, 2024
d242f13
Make EVM simulator optional in toolbox
slowli Sep 27, 2024
7784017
Remove unused dependency
slowli Sep 27, 2024
2046ca4
Fix `eth_sender` tests
slowli Sep 30, 2024
da16bcb
Rename args in tx conversions
slowli Sep 30, 2024
d2bb42c
Revert changes in `ProtocolUpgrade`
slowli Sep 30, 2024
473c564
Fix commitment unit tests
slowli Sep 30, 2024
d66ba59
Misc brush-up
slowli Sep 30, 2024
95acb2c
Restore `migration` unit tests
slowli Oct 1, 2024
636dfaa
Brush up `TransactionReceipt` conversion
slowli Oct 1, 2024
8b7c48c
Test transaction conversion with `to == None`
slowli Oct 1, 2024
875e18c
Check EVM simulator presence during tx conversion
slowli Oct 1, 2024
e726b27
Test txs with `to == None` for API server
slowli Oct 1, 2024
ff22c20
Disallow `to == None` for calls in API server
slowli Oct 1, 2024
9d30565
Update from upstream
slowli Oct 1, 2024
86daedc
Update from upstream
slowli Oct 1, 2024
33967dd
Update from upstream
slowli Oct 2, 2024
0aecc14
Sketch far call tracer
slowli Oct 3, 2024
8d4779d
Test EVM simulator tracing
slowli Oct 3, 2024
2d0e37c
Brush up mock system contracts
slowli Oct 4, 2024
71e3dbe
Rename "EVM simulator" -> "EVM emulator"
slowli Oct 7, 2024
f2532ec
Update from upstream
slowli Oct 7, 2024
449b55a
Update from upstream
slowli Oct 8, 2024
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
1 change: 1 addition & 0 deletions core/bin/genesis_generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ async fn generate_new_config(
genesis_commitment: None,
bootloader_hash: Some(base_system_contracts.bootloader),
default_aa_hash: Some(base_system_contracts.default_aa),
evm_simulator_hash: base_system_contracts.evm_simulator,
..genesis_config
};

Expand Down
5 changes: 4 additions & 1 deletion core/bin/system-constants-generator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ pub static GAS_TEST_SYSTEM_CONTRACTS: Lazy<BaseSystemContracts> = Lazy::new(|| {

let bytecode = read_sys_contract_bytecode("", "DefaultAccount", ContractLanguage::Sol);
let hash = hash_bytecode(&bytecode);

BaseSystemContracts {
default_aa: SystemContractCode {
code: bytes_to_be_words(bytecode),
hash,
},
bootloader,
evm_simulator: None,
}
});

Expand Down Expand Up @@ -214,13 +216,14 @@ pub(super) fn execute_internal_transfer_test() -> u32 {
let bytecode = read_sys_contract_bytecode("", "DefaultAccount", ContractLanguage::Sol);
let hash = hash_bytecode(&bytecode);
let default_aa = SystemContractCode {
code: bytes_to_be_words(bytecode),
code: bytes_to_be_words(bytecode.clone()),
hash,
};

let base_system_smart_contracts = BaseSystemContracts {
bootloader,
default_aa,
evm_simulator: None,
};

let system_env = SystemEnv {
Expand Down
3 changes: 3 additions & 0 deletions core/lib/config/src/configs/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ pub struct StateKeeperConfig {
pub bootloader_hash: Option<H256>,
#[deprecated(note = "Use GenesisConfig::default_aa_hash instead")]
pub default_aa_hash: Option<H256>,
#[deprecated(note = "Use GenesisConfig::evm_simulator_hash instead")]
pub evm_simulator_hash: Option<H256>,
#[deprecated(note = "Use GenesisConfig::l1_batch_commit_data_generator_mode instead")]
#[serde(default)]
pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode,
Expand Down Expand Up @@ -178,6 +180,7 @@ impl StateKeeperConfig {
protective_reads_persistence_enabled: true,
bootloader_hash: None,
default_aa_hash: None,
evm_simulator_hash: None,
l1_batch_commit_data_generator_mode: L1BatchCommitmentMode::Rollup,
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/lib/config/src/configs/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct GenesisConfig {
pub genesis_commitment: Option<H256>,
pub bootloader_hash: Option<H256>,
pub default_aa_hash: Option<H256>,
pub evm_simulator_hash: Option<H256>,
pub l1_chain_id: L1ChainId,
pub sl_chain_id: Option<SLChainId>,
pub l2_chain_id: L2ChainId,
Expand Down Expand Up @@ -49,6 +50,7 @@ impl GenesisConfig {
genesis_commitment: Some(H256::repeat_byte(0x17)),
bootloader_hash: Default::default(),
default_aa_hash: Default::default(),
evm_simulator_hash: Default::default(),
l1_chain_id: L1ChainId(9),
sl_chain_id: None,
protocol_version: Some(ProtocolSemanticVersion {
Expand Down
2 changes: 2 additions & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ impl Distribution<configs::chain::StateKeeperConfig> for EncodeDist {
fee_account_addr: None,
bootloader_hash: None,
default_aa_hash: None,
evm_simulator_hash: None,
l1_batch_commit_data_generator_mode: Default::default(),
}
}
Expand Down Expand Up @@ -728,6 +729,7 @@ impl Distribution<configs::GenesisConfig> for EncodeDist {
genesis_commitment: Some(rng.gen()),
bootloader_hash: Some(rng.gen()),
default_aa_hash: Some(rng.gen()),
evm_simulator_hash: Some(rng.gen()),
fee_account: rng.gen(),
l1_chain_id: L1ChainId(self.sample(rng)),
sl_chain_id: None,
Expand Down
5 changes: 5 additions & 0 deletions core/lib/constants/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ pub const CODE_ORACLE_ADDRESS: Address = H160([
0x00, 0x00, 0x80, 0x12,
]);

pub const EVM_GAS_MANAGER_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x13,
]);

/// Note, that the `Create2Factory` is explicitly deployed on a non-system-contract address.
pub const CREATE2_FACTORY_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down
26 changes: 25 additions & 1 deletion core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ pub fn deployer_contract() -> Contract {
load_sys_contract("ContractDeployer")
}

pub fn known_code_storage_contract() -> Contract {
load_sys_contract("KnownCodesStorage")
}

pub fn l1_messenger_contract() -> Contract {
load_sys_contract("L1Messenger")
}
Expand Down Expand Up @@ -293,6 +297,7 @@ fn read_zbin_bytecode_from_path(bytecode_path: PathBuf) -> Vec<u8> {
fs::read(&bytecode_path)
.unwrap_or_else(|err| panic!("Can't read .zbin bytecode at {:?}: {}", bytecode_path, err))
}

/// Hash of code and code which consists of 32 bytes words
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SystemContractCode {
Expand All @@ -304,18 +309,23 @@ pub struct SystemContractCode {
pub struct BaseSystemContracts {
pub bootloader: SystemContractCode,
pub default_aa: SystemContractCode,
/// Never filled in constructors for now. The only way to get the EVM simulator enabled is to call [`Self::with_evm_simulator()`].
pub evm_simulator: Option<SystemContractCode>,
}

#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq)]
pub struct BaseSystemContractsHashes {
pub bootloader: H256,
pub default_aa: H256,
pub evm_simulator: Option<H256>,
}

impl PartialEq for BaseSystemContracts {
fn eq(&self, other: &Self) -> bool {
self.bootloader.hash == other.bootloader.hash
&& self.default_aa.hash == other.default_aa.hash
&& self.evm_simulator.as_ref().map(|contract| contract.hash)
== other.evm_simulator.as_ref().map(|contract| contract.hash)
}
}

Expand All @@ -339,14 +349,27 @@ impl BaseSystemContracts {
BaseSystemContracts {
bootloader,
default_aa,
evm_simulator: None,
}
}
// BaseSystemContracts with proved bootloader - for handling transactions.

/// BaseSystemContracts with proved bootloader - for handling transactions.
pub fn load_from_disk() -> Self {
let bootloader_bytecode = read_proved_batch_bootloader_bytecode();
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

/// Loads the latest EVM simulator for these base system contracts. Logically, it only makes sense to do for the latest protocol version.
slowli marked this conversation as resolved.
Show resolved Hide resolved
pub fn with_latest_evm_simulator(mut self) -> Self {
let bytecode = read_sys_contract_bytecode("", "EvmInterpreter", ContractLanguage::Yul);
let hash = hash_bytecode(&bytecode);
self.evm_simulator = Some(SystemContractCode {
code: bytes_to_be_words(bytecode),
hash,
});
self
}

/// BaseSystemContracts with playground bootloader - used for handling eth_calls.
pub fn playground() -> Self {
let bootloader_bytecode = read_playground_batch_bootloader_bytecode();
Expand Down Expand Up @@ -475,6 +498,7 @@ impl BaseSystemContracts {
BaseSystemContractsHashes {
bootloader: self.bootloader.hash,
default_aa: self.default_aa.hash,
evm_simulator: self.evm_simulator.as_ref().map(|contract| contract.hash),
}
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading