Skip to content

Commit

Permalink
reject updates with wrong hash
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszaaa committed Sep 23, 2024
1 parent 247a5db commit e37b836
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pallets/rolldown/rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2021 Mangata team

// Copyright (C) 2021 Mangata team
use jsonrpsee::{
core::{async_trait, Error as JsonRpseeError, RpcResult},
proc_macros::rpc,
Expand Down
4 changes: 3 additions & 1 deletion pallets/rolldown/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ pub mod pallet {
FerryHashMismatch,
MintError,
AssetRegistrationProblem,
UpdateHashMishmatch,
}

#[pallet::config]
Expand Down Expand Up @@ -488,7 +489,8 @@ pub mod pallet {
) -> DispatchResult {
let sequencer = ensure_signed(origin)?;

let update_hash = requests.abi_encode_hash();
let hash = requests.abi_encode_hash();
ensure!( update_hash == hash, Error::<T>::UpdateHashMishmatch);

Self::update_impl(sequencer, requests)
}
Expand Down
19 changes: 19 additions & 0 deletions pallets/rolldown/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,25 @@ fn process_single_deposit() {
});
}


#[test]
#[serial]
fn test_reject_update_with_wrong_hash() {
ExtBuilder::new().execute_with_default_mocks(|| {
forward_to_block::<Test>(36);
let update = L1UpdateBuilder::default()
.with_requests(vec![L1UpdateRequest::Deposit(Default::default())])
.build();


assert_err!(
Rolldown::update_l2_from_l1(RuntimeOrigin::signed(ALICE), update, H256::zero()),
Error::<Test>::UpdateHashMishmatch
);

});
}

#[test]
#[serial]
fn l2_counter_updates_when_requests_are_processed() {
Expand Down

0 comments on commit e37b836

Please sign in to comment.