Skip to content

Commit

Permalink
Added validation of moved funds sweep proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Dec 20, 2023
1 parent 3f7d6b3 commit c9d4587
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions solidity/contracts/bridge/WalletProposalValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ contract WalletProposalValidator {
uint256 movingFundsTxFee;
}

/// @notice Helper structure representing a moved funds sweep proposal.
struct MovedFundsSweepProposal {
// 20-byte public key hash of the wallet.
bytes20 walletPubKeyHash;
// Proposed BTC fee for the entire transaction.
uint256 movedFundsSweepTxFee;
}

/// @notice Helper structure representing a heartbeat proposal.
struct HeartbeatProposal {
// 20-byte public key hash of the target wallet.
Expand Down Expand Up @@ -662,6 +670,37 @@ contract WalletProposalValidator {
return true;
}

function validateMovedFundsSweepProposal(
MovedFundsSweepProposal calldata proposal
) external view returns (bool) {
Wallets.Wallet memory wallet = bridge.wallets(
proposal.walletPubKeyHash
);

// Make sure the wallet is in Live or MovingFunds state.
require(
wallet.state == Wallets.WalletState.Live ||
wallet.state == Wallets.WalletState.MovingFunds,
"Source wallet is not in Live or MovingFunds state"
);

// Make sure the proposed fee is valid.
(, , , , , , , uint64 movedFundsSweepTxMaxTotalFee, , , ) = bridge
.movingFundsParameters();

require(
proposal.movedFundsSweepTxFee > 0,
"Proposed transaction fee cannot be zero"
);

require(
proposal.movedFundsSweepTxFee <= movedFundsSweepTxMaxTotalFee,
"Proposed transaction fee is too high"
);

return true;
}

/// @notice View function encapsulating the main rules of a valid heartbeat
/// proposal. This function is meant to facilitate the off-chain
/// validation of the incoming proposals. Thanks to it, most
Expand Down

0 comments on commit c9d4587

Please sign in to comment.