Skip to content

Commit

Permalink
auction(ah): sequence continuity check in withdraw DA
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed Apr 17, 2024
1 parent 85ee4a9 commit 51aeb7e
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ impl ActionHandler for ActionDutchAuctionWithdraw {
self.seq
);

ensure!(
self.seq < u64::MAX,
"the sequence number maximum is `u64::MAX`"
);

Ok(())
}

async fn check_and_execute<S: StateWrite>(&self, state: S) -> Result<()> {
let auction_id = self.auction_id;

// Check that the auction exists and is a Dutch auction.
let auction_state = state
.get_dutch_auction_by_id(auction_id)
.await
Expand All @@ -33,6 +39,15 @@ impl ActionHandler for ActionDutchAuctionWithdraw {
bail!("no auction found for id {auction_id}")
};

// Check that sequence number is incremented by one.
ensure!(
self.seq == auction_state.state.sequence.saturating_add(1),
"the action sequence number MUST be incremented by one (previous: {}, action: {})",
self.seq,
auction_state.state.sequence
);

// Check that the reported balance commitment, match the recorded reserves.
let auction_input_reserves = Value {
amount: auction_state.state.input_reserves,
asset_id: auction_state.description.input.asset_id,
Expand Down

0 comments on commit 51aeb7e

Please sign in to comment.