Skip to content

Commit 72018b0

Browse files
committed
Avoid state root mismatch with scilla deltas
1 parent ba7c3b6 commit 72018b0

6 files changed

Lines changed: 42 additions & 26 deletions

File tree

z2/resources/chain-specs/zq2-mainnet.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ consensus.contract_upgrades = { deposit_v5 = { height = 0, reinitialise_params =
2323
consensus.new_view_broadcast_interval = { secs = 30, nanos = 0 }
2424

2525
api_servers = [{ default_quota = { balance = 500, period = 1 }, port = 4201, enabled_apis = [{ namespace = "eth", apis = ["blockNumber"] }] }, { port = 4202, enabled_apis = ["admin", "debug", "erigon", "eth", "net", "ots", "trace", "txpool", "web3", "zilliqa"] }]
26-
consensus.genesis_fork = { at_height = 0, executable_blocks = false, call_mode_1_sets_caller_to_parent_caller = true, failed_scilla_call_from_gas_exempt_caller_causes_revert = true, scilla_messages_can_call_evm_contracts = true, scilla_contract_creation_increments_account_balance = true, scilla_json_preserve_order = true, scilla_call_respects_evm_state_changes = true, only_mutated_accounts_update_state = true, scilla_call_gas_exempt_addrs = [], scilla_block_number_returns_current_block = true, scilla_maps_are_encoded_correctly = true, transfer_gas_fee_to_zero_account = true, apply_state_changes_only_if_transaction_succeeds = true, apply_scilla_delta_when_evm_succeeded = true, scilla_deduct_funds_from_actual_sender = true, fund_accounts_from_zero_account = [], scilla_delta_maps_are_applied_correctly = false, scilla_server_unlimited_response_size = false, scilla_failed_txn_correct_balance_deduction = false, scilla_transition_proper_order = false, evm_to_scilla_value_transfer_zero = false, restore_xsgd_contract = false, evm_exec_failure_causes_scilla_precompile_to_fail = false, revert_restore_xsgd_contract = false, scilla_fix_contract_code_removal_on_evm_tx = false, restore_ignite_wallet_contracts = false, prevent_zil_transfer_from_evm_to_scilla_contract = false, scilla_failed_txn_correct_gas_fee_charged = false, check_minimum_gas_price = false, inject_access_list = false, use_max_gas_priority_fee = false, failed_zil_transfers_to_eoa_proper_fee_deduction = false, validator_jailing = false, scilla_empty_maps_are_encoded_correctly = false, cancun_active = false, scilla_call_gas_exempt_addrs_v2 = [], randao_support = false, evm_to_scilla_strings_encoded_properly = false }
26+
consensus.genesis_fork = { at_height = 0, executable_blocks = false, call_mode_1_sets_caller_to_parent_caller = true, failed_scilla_call_from_gas_exempt_caller_causes_revert = true, scilla_messages_can_call_evm_contracts = true, scilla_contract_creation_increments_account_balance = true, scilla_json_preserve_order = true, scilla_call_respects_evm_state_changes = true, only_mutated_accounts_update_state = true, scilla_call_gas_exempt_addrs = [], scilla_block_number_returns_current_block = true, scilla_maps_are_encoded_correctly = true, transfer_gas_fee_to_zero_account = true, apply_state_changes_only_if_transaction_succeeds = true, apply_scilla_delta_when_evm_succeeded = true, scilla_deduct_funds_from_actual_sender = true, fund_accounts_from_zero_account = [], scilla_delta_maps_are_applied_correctly = false, scilla_server_unlimited_response_size = false, scilla_failed_txn_correct_balance_deduction = false, scilla_transition_proper_order = false, evm_to_scilla_value_transfer_zero = false, restore_xsgd_contract = false, evm_exec_failure_causes_scilla_precompile_to_fail = false, revert_restore_xsgd_contract = false, scilla_fix_contract_code_removal_on_evm_tx = false, restore_ignite_wallet_contracts = false, prevent_zil_transfer_from_evm_to_scilla_contract = false, scilla_failed_txn_correct_gas_fee_charged = false, check_minimum_gas_price = false, inject_access_list = false, use_max_gas_priority_fee = false, failed_zil_transfers_to_eoa_proper_fee_deduction = false, validator_jailing = false, scilla_empty_maps_are_encoded_correctly = false, cancun_active = false, scilla_call_gas_exempt_addrs_v2 = [], randao_support = false, evm_to_scilla_strings_encoded_properly = false, dont_overwrite_evm_accounts_from_stale_scilla_state = false }
2727
consensus.forks = [
2828
{ at_height = 4770088, executable_blocks = true },
2929
{ at_height = 4854500, scilla_delta_maps_are_applied_correctly = true },
@@ -40,4 +40,5 @@ consensus.forks = [
4040
{ at_height = 19486411, cancun_active = true },
4141
{ at_height = 19486411, scilla_call_gas_exempt_addrs_v2 = ["0x0F8aeCCaCA7FEE297cC2aBf7fFC9a81e7122A727"] },
4242
{ at_height = 25905600, randao_support = true, evm_to_scilla_strings_encoded_properly = true },
43+
{ at_height = 27081150, dont_overwrite_evm_accounts_from_stale_scilla_state = true },
4344
]

z2/resources/chain-specs/zq2-testnet.toml

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,19 @@ consensus.genesis_deposits = [
2525
"0x0000000000000000000000000000000000000000",
2626
"0x214695413d1ea6a4a4453cd24ffd151fbc95496a"
2727
],
28-
[
29-
"ae776c587e6869d41331529c6dd0f59c31d1ef4c47f8b5ecb1acc54fa7452d9b2ba6f56bdad08a606d25761c8522b367",
30-
"12D3KooWJyH1r2UfcFPiHbEFBYB3xWufR1va8cRK3veMwfUunfRD",
31-
"20_000_000_000_000_000_000_000_000",
32-
"0x0000000000000000000000000000000000000000",
33-
"0x214695413d1ea6a4a4453cd24ffd151fbc95496a"
34-
],
3528
[
3629
"95de7dae002295bba9c4cffd1b0df70a7ccd0cc68e6b10da06b1b91f8a7e9b305e19431fc42b7413c65a8ab6959e41c6",
3730
"12D3KooWM5L182sQtJuARf5Xfg517xVqZRaPM9583BsmLcv5Ma2o",
3831
"20_000_000_000_000_000_000_000_000",
3932
"0x0000000000000000000000000000000000000000",
4033
"0x214695413d1ea6a4a4453cd24ffd151fbc95496a"
4134
],
42-
[
43-
"ae96338209ec4f1ad446a131e687bde02506207b750465cbc43d1ea4f5b32daa51ff060e8451c903d6de7f1c89951b1d",
44-
"12D3KooWQpAM4F19CwJAAhHFgeD7feyQLHDTxzKu2hsVH4BQceSQ",
45-
"20_000_000_000_000_000_000_000_000",
46-
"0x0000000000000000000000000000000000000000",
47-
"0x214695413d1ea6a4a4453cd24ffd151fbc95496a"
48-
],
4935
[
5036
"a3a2419fba7962021d730f4e1eb087b5bf0d66140ef7d4ba758348b13fb2ffa9a75afbdbef988c65ce625544360dea42",
5137
"12D3KooWAWoMVZAXJDkuhyzyBJHGHn2gYFyTbbdZGhHs4BuEN5Fe",
5238
"20_000_000_000_000_000_000_000_000",
5339
"0x0000000000000000000000000000000000000000",
5440
"0x214695413d1ea6a4a4453cd24ffd151fbc95496a"
55-
],
56-
[
57-
"8093ea6fa4720ca0975559a5f9d3a2694c6ab8e63a8c54e986d11a28f9e958f006420e30a8d6f04d6b2df63fe6e0563d",
58-
"12D3KooWNqZxaW4ZirvWUNj9KSRgTp55RsZHSFumDeRdCLZAjNNA",
59-
"20_000_000_000_000_000_000_000_000",
60-
"0x0000000000000000000000000000000000000000",
61-
"0x214695413d1ea6a4a4453cd24ffd151fbc95496a"
6241
]
6342
]
6443

@@ -73,7 +52,7 @@ consensus.contract_upgrades = { deposit_v5 = { height = 0, reinitialise_params =
7352
consensus.new_view_broadcast_interval = { secs = 30, nanos = 0 }
7453

7554
api_servers = [{ default_quota = { balance = 500, period = 1 }, port = 4201, enabled_apis = [{ namespace = "eth", apis = ["blockNumber"] }] }, { port = 4202, enabled_apis = ["admin", "debug", "erigon", "eth", "net", "ots", "trace", "txpool", "web3", "zilliqa"] }]
76-
consensus.genesis_fork = { at_height = 0, executable_blocks = false, call_mode_1_sets_caller_to_parent_caller = true, failed_scilla_call_from_gas_exempt_caller_causes_revert = true, scilla_messages_can_call_evm_contracts = true, scilla_contract_creation_increments_account_balance = true, scilla_json_preserve_order = true, scilla_call_respects_evm_state_changes = true, only_mutated_accounts_update_state = true, scilla_call_gas_exempt_addrs = [], scilla_block_number_returns_current_block = true, scilla_maps_are_encoded_correctly = true, transfer_gas_fee_to_zero_account = true, apply_state_changes_only_if_transaction_succeeds = true, apply_scilla_delta_when_evm_succeeded = true, scilla_deduct_funds_from_actual_sender = true, fund_accounts_from_zero_account = [], scilla_delta_maps_are_applied_correctly = false, scilla_server_unlimited_response_size = false, scilla_failed_txn_correct_balance_deduction = false, scilla_transition_proper_order = false, evm_to_scilla_value_transfer_zero = false, restore_xsgd_contract = false, evm_exec_failure_causes_scilla_precompile_to_fail = false, revert_restore_xsgd_contract = false, scilla_fix_contract_code_removal_on_evm_tx = false, restore_ignite_wallet_contracts = false, prevent_zil_transfer_from_evm_to_scilla_contract = false, scilla_failed_txn_correct_gas_fee_charged = false, check_minimum_gas_price = false, inject_access_list = false, use_max_gas_priority_fee = false, failed_zil_transfers_to_eoa_proper_fee_deduction = false, validator_jailing = false, scilla_empty_maps_are_encoded_correctly = false, cancun_active = false, scilla_call_gas_exempt_addrs_v2 = [], randao_support = false, evm_to_scilla_strings_encoded_properly = false }
55+
consensus.genesis_fork = { at_height = 0, executable_blocks = false, call_mode_1_sets_caller_to_parent_caller = true, failed_scilla_call_from_gas_exempt_caller_causes_revert = true, scilla_messages_can_call_evm_contracts = true, scilla_contract_creation_increments_account_balance = true, scilla_json_preserve_order = true, scilla_call_respects_evm_state_changes = true, only_mutated_accounts_update_state = true, scilla_call_gas_exempt_addrs = [], scilla_block_number_returns_current_block = true, scilla_maps_are_encoded_correctly = true, transfer_gas_fee_to_zero_account = true, apply_state_changes_only_if_transaction_succeeds = true, apply_scilla_delta_when_evm_succeeded = true, scilla_deduct_funds_from_actual_sender = true, fund_accounts_from_zero_account = [], scilla_delta_maps_are_applied_correctly = false, scilla_server_unlimited_response_size = false, scilla_failed_txn_correct_balance_deduction = false, scilla_transition_proper_order = false, evm_to_scilla_value_transfer_zero = false, restore_xsgd_contract = false, evm_exec_failure_causes_scilla_precompile_to_fail = false, revert_restore_xsgd_contract = false, scilla_fix_contract_code_removal_on_evm_tx = false, restore_ignite_wallet_contracts = false, prevent_zil_transfer_from_evm_to_scilla_contract = false, scilla_failed_txn_correct_gas_fee_charged = false, check_minimum_gas_price = false, inject_access_list = false, use_max_gas_priority_fee = false, failed_zil_transfers_to_eoa_proper_fee_deduction = false, validator_jailing = false, scilla_empty_maps_are_encoded_correctly = false, cancun_active = false, scilla_call_gas_exempt_addrs_v2 = [], randao_support = false, evm_to_scilla_strings_encoded_properly = false, dont_overwrite_evm_accounts_from_stale_scilla_state = false }
7756
consensus.forks = [
7857
{ at_height = 8099088, executable_blocks = true },
7958
{ at_height = 8371376, scilla_delta_maps_are_applied_correctly = true },
@@ -94,4 +73,5 @@ consensus.forks = [
9473
{ at_height = 23685219, scilla_call_gas_exempt_addrs_v2 = [] },
9574
{ at_height = 28281600, randao_support = true },
9675
{ at_height = 29230131, evm_to_scilla_strings_encoded_properly = true },
76+
{ at_height = 999999999, dont_overwrite_evm_accounts_from_stale_scilla_state = true },
9777
]

z2/src/chain.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ impl Chain {
201201
"scilla_call_gas_exempt_addrs_v2": [],
202202
"randao_support": false,
203203
"evm_to_scilla_strings_encoded_properly": false,
204+
"dont_overwrite_evm_accounts_from_stale_scilla_state": false,
204205
})),
205206
Chain::Zq2Mainnet => Some(json!({
206207
"at_height": 0,
@@ -242,6 +243,7 @@ impl Chain {
242243
"scilla_call_gas_exempt_addrs_v2": [],
243244
"randao_support": false,
244245
"evm_to_scilla_strings_encoded_properly": false,
246+
"dont_overwrite_evm_accounts_from_stale_scilla_state": false,
245247
})),
246248
_ => None,
247249
}
@@ -300,6 +302,7 @@ impl Chain {
300302
}),
301303
json!({ "at_height": 28281600, "randao_support": true}),
302304
json!({ "at_height": 29230131, "evm_to_scilla_strings_encoded_properly": true}),
305+
json!({ "at_height": 999999999, "dont_overwrite_evm_accounts_from_stale_scilla_state": true}),
303306
]),
304307
Chain::Zq2Mainnet => Some(vec![
305308
json!({ "at_height": 4770088, "executable_blocks": true }),
@@ -356,6 +359,7 @@ impl Chain {
356359
],
357360
}),
358361
json!({ "at_height": 25905600, "randao_support": true, "evm_to_scilla_strings_encoded_properly": true}),
362+
json!({ "at_height": 27081150, "dont_overwrite_evm_accounts_from_stale_scilla_state": true}),
359363
]),
360364
_ => None,
361365
}

z2/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![recursion_limit = "256"]
2+
13
mod address;
24
pub mod chain;
35
pub mod collector;

zilliqa/src/cfg.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,9 @@ impl Forks {
719719
ForkName::ScillaCallGasExemptAddrsV2 => {
720720
fork.scilla_call_gas_exempt_addrs_v2.length() != 0
721721
}
722+
ForkName::DontOverwriteAccountsFromStaleScillaState => {
723+
fork.dont_overwrite_evm_accounts_from_stale_scilla_state
724+
}
722725
} {
723726
return Some(fork.at_height);
724727
}
@@ -768,6 +771,7 @@ pub struct Fork {
768771
pub scilla_call_gas_exempt_addrs_v2: Vec<Address>,
769772
pub randao_support: bool,
770773
pub evm_to_scilla_strings_encoded_properly: bool,
774+
pub dont_overwrite_evm_accounts_from_stale_scilla_state: bool,
771775
}
772776

773777
pub enum ForkName {
@@ -795,6 +799,7 @@ pub enum ForkName {
795799
UseMaxGasPriorityFee,
796800
ValidatorJailing,
797801
ScillaCallGasExemptAddrsV2,
802+
DontOverwriteAccountsFromStaleScillaState,
798803
}
799804

800805
#[derive(Clone, Debug, Serialize, Deserialize)]
@@ -918,6 +923,8 @@ pub struct ForkDelta {
918923
pub randao_support: Option<bool>,
919924
/// if true, strings passed from EVM to Scilla via interop are properly JSON-encoded
920925
pub evm_to_scilla_strings_encoded_properly: Option<bool>,
926+
/// If true, addresses modified also by EVM are skipped while applying the Scilla state delta
927+
pub dont_overwrite_evm_accounts_from_stale_scilla_state: Option<bool>,
921928
}
922929

923930
impl Fork {
@@ -1033,6 +1040,9 @@ impl Fork {
10331040
evm_to_scilla_strings_encoded_properly: delta
10341041
.evm_to_scilla_strings_encoded_properly
10351042
.unwrap_or(self.evm_to_scilla_strings_encoded_properly),
1043+
dont_overwrite_evm_accounts_from_stale_scilla_state: delta
1044+
.dont_overwrite_evm_accounts_from_stale_scilla_state
1045+
.unwrap_or(self.dont_overwrite_evm_accounts_from_stale_scilla_state),
10361046
}
10371047
}
10381048
}
@@ -1139,6 +1149,7 @@ pub fn genesis_fork_default() -> Fork {
11391149
scilla_call_gas_exempt_addrs_v2: vec![],
11401150
randao_support: true,
11411151
evm_to_scilla_strings_encoded_properly: true,
1152+
dont_overwrite_evm_accounts_from_stale_scilla_state: true,
11421153
}
11431154
}
11441155

@@ -1318,6 +1329,7 @@ mod tests {
13181329
scilla_call_gas_exempt_addrs_v2: vec![],
13191330
randao_support: None,
13201331
evm_to_scilla_strings_encoded_properly: None,
1332+
dont_overwrite_evm_accounts_from_stale_scilla_state: None,
13211333
}],
13221334
..Default::default()
13231335
};
@@ -1379,6 +1391,7 @@ mod tests {
13791391
scilla_call_gas_exempt_addrs_v2: vec![],
13801392
randao_support: Some(false),
13811393
evm_to_scilla_strings_encoded_properly: None,
1394+
dont_overwrite_evm_accounts_from_stale_scilla_state: None,
13821395
},
13831396
ForkDelta {
13841397
at_height: 20,
@@ -1420,6 +1433,7 @@ mod tests {
14201433
scilla_call_gas_exempt_addrs_v2: vec![],
14211434
randao_support: None,
14221435
evm_to_scilla_strings_encoded_properly: None,
1436+
dont_overwrite_evm_accounts_from_stale_scilla_state: None,
14231437
},
14241438
],
14251439
..Default::default()
@@ -1498,6 +1512,7 @@ mod tests {
14981512
scilla_call_gas_exempt_addrs_v2: vec![],
14991513
randao_support: None,
15001514
evm_to_scilla_strings_encoded_properly: None,
1515+
dont_overwrite_evm_accounts_from_stale_scilla_state: None,
15011516
},
15021517
ForkDelta {
15031518
at_height: 10,
@@ -1539,6 +1554,7 @@ mod tests {
15391554
scilla_call_gas_exempt_addrs_v2: vec![],
15401555
randao_support: None,
15411556
evm_to_scilla_strings_encoded_properly: None,
1557+
dont_overwrite_evm_accounts_from_stale_scilla_state: None,
15421558
},
15431559
],
15441560
..Default::default()
@@ -1605,6 +1621,7 @@ mod tests {
16051621
scilla_call_gas_exempt_addrs_v2: vec![],
16061622
randao_support: true,
16071623
evm_to_scilla_strings_encoded_properly: true,
1624+
dont_overwrite_evm_accounts_from_stale_scilla_state: true,
16081625
},
16091626
forks: vec![],
16101627
..Default::default()
@@ -1659,6 +1676,7 @@ mod tests {
16591676
scilla_call_gas_exempt_addrs_v2: vec![],
16601677
randao_support: None,
16611678
evm_to_scilla_strings_encoded_properly: None,
1679+
dont_overwrite_evm_accounts_from_stale_scilla_state: None,
16621680
},
16631681
ForkDelta {
16641682
at_height: 20,
@@ -1700,6 +1718,7 @@ mod tests {
17001718
scilla_call_gas_exempt_addrs_v2: vec![],
17011719
randao_support: None,
17021720
evm_to_scilla_strings_encoded_properly: None,
1721+
dont_overwrite_evm_accounts_from_stale_scilla_state: None,
17031722
},
17041723
],
17051724
..Default::default()

zilliqa/src/exec.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ impl State {
866866
.apply_state_changes_only_if_transaction_succeeds;
867867

868868
if !update_state_only_if_transaction_succeeds || result.success {
869-
self.apply_delta_scilla(&state, current_block.number)?;
869+
self.apply_delta_scilla(&state, None, current_block.number)?;
870870
} else {
871871
// If the transaction rejected, we must update the nonce and balance of the sender account.
872872
let from_account = state
@@ -920,10 +920,10 @@ impl State {
920920

921921
if apply_scilla_delta_when_evm_succeeded {
922922
if let ExecutionResult::Success { .. } = result {
923-
self.apply_delta_scilla(&scilla_state, current_block.number)?;
923+
self.apply_delta_scilla(&scilla_state, Some(&state), current_block.number)?;
924924
}
925925
} else {
926-
self.apply_delta_scilla(&scilla_state, current_block.number)?;
926+
self.apply_delta_scilla(&scilla_state, Some(&state), current_block.number)?;
927927
}
928928

929929
Ok(TransactionApplyResult::Evm(ResultAndState {
@@ -937,15 +937,25 @@ impl State {
937937
fn apply_delta_scilla(
938938
&mut self,
939939
state: &HashMap<Address, PendingAccount>,
940+
evm_state: Option<&EvmState>,
940941
current_block_number: u64,
941942
) -> Result<()> {
942943
let fork = self.forks.get(current_block_number);
943944
let only_mutated_accounts_update_state = fork.only_mutated_accounts_update_state;
944945
let scilla_delta_maps_are_applied_correctly = fork.scilla_delta_maps_are_applied_correctly;
946+
let dont_overwrite_evm_accounts_from_stale_scilla_state =
947+
fork.dont_overwrite_evm_accounts_from_stale_scilla_state;
945948
for (&address, account) in state {
946949
if only_mutated_accounts_update_state && !account.touched {
947950
continue;
948951
}
952+
// Modified addresses by EVM are skipped
953+
if dont_overwrite_evm_accounts_from_stale_scilla_state
954+
&& let Some(evm) = evm_state
955+
&& evm.contains_key(&address)
956+
{
957+
continue;
958+
}
949959

950960
// We shouldn't mutate accounts that were from EVM.
951961
assert!(!account.from_evm);

0 commit comments

Comments
 (0)