Skip to content

Commit 6305387

Browse files
authored
Merge branch 'main' into bf-consensus-0.9
2 parents 993be26 + cea1cb5 commit 6305387

File tree

105 files changed

+3551
-486
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+3551
-486
lines changed

contracts

Submodule contracts updated 100 files

core/lib/basic_types/src/web3/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl From<U64> for U64Number {
5353
// `Signature`, `keccak256`: from `web3::signing`
5454

5555
/// A struct that represents the components of a secp256k1 signature.
56+
#[derive(Debug)]
5657
pub struct Signature {
5758
/// V component in Electrum format with chain-id replay protection.
5859
pub v: u64,

core/lib/contracts/src/lib.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,26 @@ pub fn read_bytecode_from_path(
270270
) -> Option<Vec<u8>> {
271271
let artifact = read_file_to_json_value(&artifact_path)?;
272272

273-
let bytecode = if let Some(bytecode) = artifact["bytecode"].as_str() {
274-
bytecode
275-
.strip_prefix("0x")
276-
.unwrap_or_else(|| panic!("Bytecode in {:?} is not hex", artifact_path))
277-
} else {
278-
artifact["bytecode"]["object"]
279-
.as_str()
280-
.unwrap_or_else(|| panic!("Bytecode not found in {:?}", artifact_path))
281-
};
273+
let bytecode = artifact["bytecode"]
274+
.as_str()
275+
.or_else(|| artifact["bytecode"]["object"].as_str())
276+
.unwrap_or_else(|| panic!("Bytecode not found in {:?}", artifact_path));
277+
// Strip an optional `0x` prefix.
278+
let bytecode = bytecode.strip_prefix("0x").unwrap_or(bytecode);
279+
Some(
280+
hex::decode(bytecode)
281+
.unwrap_or_else(|err| panic!("Can't decode bytecode in {:?}: {}", artifact_path, err)),
282+
)
283+
}
282284

285+
pub fn read_deployed_bytecode_from_path(artifact_path: &Path) -> Option<Vec<u8>> {
286+
let artifact = read_file_to_json_value(artifact_path)?;
287+
let bytecode = artifact["deployedBytecode"]
288+
.as_str()
289+
.or_else(|| artifact["deployedBytecode"]["object"].as_str())
290+
.unwrap_or_else(|| panic!("Deployed bytecode not found in {:?}", artifact_path));
291+
// Strip an optional `0x` prefix.
292+
let bytecode = bytecode.strip_prefix("0x").unwrap_or(bytecode);
283293
Some(
284294
hex::decode(bytecode)
285295
.unwrap_or_else(|err| panic!("Can't decode bytecode in {:?}: {}", artifact_path, err)),

core/lib/multivm/src/versions/shadow/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl Harness {
180180
let (compression_result, exec_result) =
181181
vm.execute_transaction_with_bytecode_compression(deploy_tx.tx.clone(), true);
182182
compression_result.unwrap();
183-
assert!(!exec_result.result.is_failed(), "{:#?}", exec_result);
183+
assert!(!exec_result.result.is_failed(), "{exec_result:#?}");
184184

185185
let load_test_tx = self.bob.get_loadnext_transaction(
186186
deploy_tx.address,
@@ -190,7 +190,7 @@ impl Harness {
190190
let (compression_result, exec_result) =
191191
vm.execute_transaction_with_bytecode_compression(load_test_tx.clone(), true);
192192
compression_result.unwrap();
193-
assert!(!exec_result.result.is_failed(), "{:#?}", exec_result);
193+
assert!(!exec_result.result.is_failed(), "{exec_result:#?}");
194194

195195
self.new_block(vm, &[deploy_tx.tx.hash(), load_test_tx.hash()]);
196196
}

core/lib/multivm/src/versions/shadow/tests.rs

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,21 @@ mod call_tracer {
247247
fn recursive_tx() {
248248
test_recursive_tx::<super::ShadowedFastVm<_, _>>();
249249
}
250+
251+
#[test]
252+
fn evm_to_eravm_call() {
253+
test_evm_to_eravm_call::<super::ShadowedFastVm<_, _>>();
254+
}
255+
256+
#[test]
257+
fn evm_deployment_tx() {
258+
test_evm_deployment_tx::<super::ShadowedFastVm<_, _>>();
259+
}
260+
261+
#[test]
262+
fn evm_deployment_from_contract() {
263+
test_evm_deployment_from_contract::<super::ShadowedFastVm<_, _>>();
264+
}
250265
}
251266

252267
mod circuits {
@@ -291,10 +306,94 @@ mod default_aa {
291306
}
292307
}
293308

294-
mod evm_emulator {
309+
mod evm {
310+
use crate::versions::testonly::evm::*;
311+
312+
#[test]
313+
fn evm_deployment_tx() {
314+
test_evm_deployment_tx::<super::ShadowedFastVm>();
315+
}
316+
317+
#[test]
318+
fn evm_bytecode_decommit() {
319+
test_evm_bytecode_decommit::<super::ShadowedFastVm>();
320+
}
321+
322+
#[test]
323+
fn real_emulator_basics() {
324+
test_real_emulator_basics::<super::ShadowedFastVm>();
325+
}
326+
327+
#[test]
328+
fn real_emulator_code_hash() {
329+
test_real_emulator_code_hash::<super::ShadowedFastVm>();
330+
}
331+
332+
#[test]
333+
fn real_emulator_block_info() {
334+
test_real_emulator_block_info::<super::ShadowedFastVm>();
335+
}
336+
337+
#[test]
338+
fn real_emulator_msg_info() {
339+
test_real_emulator_msg_info::<super::ShadowedFastVm>();
340+
}
341+
342+
#[test]
343+
fn real_emulator_gas_management() {
344+
test_real_emulator_gas_management::<super::ShadowedFastVm>();
345+
}
346+
347+
#[test]
348+
fn real_emulator_recursion() {
349+
test_real_emulator_recursion::<super::ShadowedFastVm>();
350+
}
351+
352+
#[test]
353+
fn real_emulator_deployment() {
354+
test_real_emulator_deployment::<super::ShadowedFastVm>();
355+
}
356+
357+
#[test]
358+
fn deployment_with_partial_reverts() {
359+
test_deployment_with_partial_reverts::<super::ShadowedFastVm>();
360+
}
361+
362+
#[test]
363+
fn era_vm_deployment_after_evm_execution() {
364+
test_era_vm_deployment_after_evm_execution::<super::ShadowedFastVm>();
365+
}
366+
367+
#[test]
368+
fn era_vm_deployment_after_evm_deployment() {
369+
test_era_vm_deployment_after_evm_deployment::<super::ShadowedFastVm>();
370+
}
371+
372+
#[test]
373+
fn calling_era_contract_from_evm() {
374+
test_calling_era_contract_from_evm::<super::ShadowedFastVm>();
375+
}
376+
377+
#[test]
378+
fn far_calls_from_evm_contract() {
379+
test_far_calls_from_evm_contract::<super::ShadowedFastVm>();
380+
}
381+
382+
#[test]
383+
fn calling_sha256_precompile() {
384+
test_calling_sha256_precompile::<super::ShadowedFastVm>();
385+
}
386+
387+
#[test]
388+
fn calling_ecrecover_precompile() {
389+
test_calling_ecrecover_precompile::<super::ShadowedFastVm>();
390+
}
391+
}
392+
393+
mod mock_evm {
295394
use test_casing::{test_casing, Product};
296395

297-
use crate::versions::testonly::evm_emulator::*;
396+
use crate::versions::testonly::mock_evm::*;
298397

299398
#[test]
300399
fn tracing_evm_contract_deployment() {

core/lib/multivm/src/versions/testonly/account_validation_rules.rs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ enum TestCase {
2222
RecursiveOutOfGas = 4,
2323
PlainOutOfGas = 5,
2424
PlainOutOfGasWithCatch = 6,
25+
ReadFromMappings = 7,
26+
DisallowedReadFromLayeredMapping = 8,
27+
DisallowedReadFromMappingWithOffset = 9,
28+
ReadFromMappingWithLargeOffset = 10,
2529
}
2630

2731
/// Checks that every limitation imposed on account validation results in an appropriate error.
@@ -72,6 +76,30 @@ pub(crate) fn test_account_validation_rules<VM: TestedVm + TestedVmForValidation
7276
Some(ViolatedValidationRule::TookTooManyComputationalGas(_))
7377
);
7478
}
79+
80+
let (result, violated_rule) = test_rule::<VM>(u32::MAX, TestCase::ReadFromMappings);
81+
assert!(!result.result.is_failed(), "{result:#?}");
82+
assert_matches!(violated_rule, None);
83+
84+
for test_case in [
85+
TestCase::DisallowedReadFromLayeredMapping,
86+
TestCase::DisallowedReadFromMappingWithOffset,
87+
TestCase::ReadFromMappingWithLargeOffset,
88+
] {
89+
println!("Testing case: {test_case:?}");
90+
91+
let (result, violated_rule) = test_rule::<VM>(u32::MAX, test_case);
92+
assert_matches!(
93+
&result.result,
94+
ExecutionResult::Halt {
95+
reason: Halt::TracerCustom(_)
96+
}
97+
);
98+
assert_matches!(
99+
violated_rule,
100+
Some(ViolatedValidationRule::TouchedDisallowedStorageSlots(_, _))
101+
);
102+
}
75103
}
76104

77105
fn test_rule<VM: TestedVmForValidation>(
@@ -94,14 +122,31 @@ fn test_rule<VM: TestedVmForValidation>(
94122
);
95123

96124
let bytecode = TestContract::validation_test().bytecode.to_vec();
125+
let mut contracts = vec![ContractToDeploy::account(bytecode, aa_address).funded()];
126+
127+
if matches!(
128+
test_case,
129+
TestCase::ReadFromMappings
130+
| TestCase::DisallowedReadFromLayeredMapping
131+
| TestCase::DisallowedReadFromMappingWithOffset
132+
| TestCase::ReadFromMappingWithLargeOffset
133+
) {
134+
let token_address = Address::repeat_byte(0x23);
135+
let bytecode = TestContract::validation_test_mock_token().bytecode.to_vec();
136+
contracts.push(ContractToDeploy::new(bytecode, token_address));
137+
// Set the mock token address in the AA contract.
138+
storage_with_rule_break_set.set_value(
139+
StorageKey::new(AccountTreeId::new(aa_address), H256::from_low_u64_be(2)),
140+
address_to_h256(&token_address),
141+
);
142+
}
143+
97144
let mut vm = VmTesterBuilder::new()
98145
.with_system_env(SystemEnv {
99146
default_validation_computational_gas_limit: validation_gas_limit,
100147
..default_system_env()
101148
})
102-
.with_custom_contracts(vec![
103-
ContractToDeploy::account(bytecode, aa_address).funded()
104-
])
149+
.with_custom_contracts(contracts)
105150
.with_storage(storage_with_rule_break_set)
106151
.with_execution_mode(TxExecutionMode::VerifyExecute)
107152
.with_rich_accounts(1)

core/lib/multivm/src/versions/testonly/bootloader.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub(crate) fn test_dummy_bootloader<VM: TestedVm>() {
99
base_system_contracts.bootloader = get_bootloader("dummy");
1010

1111
let mut vm = VmTesterBuilder::new()
12-
.with_empty_in_memory_storage()
1312
.with_base_system_smart_contracts(base_system_contracts)
1413
.with_execution_mode(TxExecutionMode::VerifyExecute)
1514
.build::<VM>();
@@ -27,7 +26,6 @@ pub(crate) fn test_bootloader_out_of_gas<VM: TestedVm>() {
2726
base_system_contracts.bootloader = get_bootloader("dummy");
2827

2928
let mut vm = VmTesterBuilder::new()
30-
.with_empty_in_memory_storage()
3129
.with_base_system_smart_contracts(base_system_contracts)
3230
.with_bootloader_gas_limit(10)
3331
.with_execution_mode(TxExecutionMode::VerifyExecute)

core/lib/multivm/src/versions/testonly/bytecode_publishing.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub(crate) fn test_bytecode_publishing<VM: TestedVm>() {
1010
// In this test, we aim to ensure that the contents of the compressed bytecodes
1111
// are included as part of the L2->L1 long messages
1212
let mut vm = VmTesterBuilder::new()
13-
.with_empty_in_memory_storage()
1413
.with_execution_mode(TxExecutionMode::VerifyExecute)
1514
.with_rich_accounts(1)
1615
.build::<VM>();

0 commit comments

Comments
 (0)