Skip to content

Commit

Permalink
Ferry fix - prevent ferrying deposits that were already executed (#820)
Browse files Browse the repository at this point in the history
- **fix cancel rights settlement**
- **Feature/upgrades (#811)**
- **do not allow for ferry deposits that were already ferried**
  • Loading branch information
mateuszaaa authored Sep 27, 2024
2 parents c2529bb + 2e95e3d commit 26de25a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pallets/rolldown/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ pub mod pallet {
MintError,
AssetRegistrationProblem,
UpdateHashMishmatch,
AlreadyExecuted,
}

#[pallet::config]
Expand Down Expand Up @@ -1631,6 +1632,10 @@ impl<T: Config> Pallet<T> {
) -> Result<(), Error<T>> {
let deposit_hash = deposit.abi_encode_hash();

if deposit.requestId.id <= LastProcessedRequestOnL2::<T>::get(chain) {
return Err(Error::<T>::AlreadyExecuted);
}

let amount = deposit
.amount
.checked_sub(deposit.ferryTip)
Expand Down
39 changes: 39 additions & 0 deletions pallets/rolldown/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3246,3 +3246,42 @@ fn test_reproduce_bug_with_sequencer_being_able_to_get_more_cancel_rights_than_h
);
});
}

#[test]
#[serial]
fn ferry_already_executed_deposit_fails() {
ExtBuilder::new()
.issue(ALICE, ETH_TOKEN_ADDRESS_MGX, MILLION)
.execute_with_default_mocks(|| {
forward_to_block::<Test>(10);
let deposit = messages::Deposit {
requestId: RequestId::new(Origin::L1, 1u128),
depositRecipient: DummyAddressConverter::convert_back(CHARLIE),
tokenAddress: ETH_TOKEN_ADDRESS,
amount: sp_core::U256::from(MILLION),
timeStamp: sp_core::U256::from(1),
ferryTip: sp_core::U256::from(0),
};
let update =
L1UpdateBuilder::default().with_requests(vec![deposit.clone().into()]).build();

Rolldown::update_l2_from_l1_unsafe(RuntimeOrigin::signed(ALICE), update).unwrap();
assert_eq!(LastProcessedRequestOnL2::<Test>::get(Chain::Ethereum), 0u128);
forward_to_block::<Test>(16);
assert_eq!(LastProcessedRequestOnL2::<Test>::get(Chain::Ethereum), 1u128);

assert_err!(
Rolldown::ferry_deposit_unsafe(
RuntimeOrigin::signed(ALICE),
consts::CHAIN,
deposit.requestId,
deposit.depositRecipient,
deposit.tokenAddress,
deposit.amount.try_into().unwrap(),
deposit.timeStamp.try_into().unwrap(),
deposit.ferryTip.try_into().unwrap(),
),
Error::<Test>::AlreadyExecuted
);
});
}

0 comments on commit 26de25a

Please sign in to comment.