Skip to content

Commit

Permalink
Merge pull request #1812 from mintlayer/fix/frozen_token_in_htlc
Browse files Browse the repository at this point in the history
Forbid frozen tokens in htlc outputs
  • Loading branch information
azarovh authored Sep 17, 2024
2 parents ae1567b + 49eb57f commit 109d9a1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
32 changes: 32 additions & 0 deletions chainstate/test-suite/src/tests/fungible_tokens_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3995,6 +3995,8 @@ fn token_issue_mint_and_data_deposit_not_enough_fee(#[case] seed: Seed) {
#[trace]
#[case(Seed::from_entropy())]
fn check_freezable_supply(#[case] seed: Seed) {
use common::chain::htlc::{HashedTimelockContract, HtlcSecret};

utils::concurrency::model(move || {
let mut rng = make_seedable_rng(seed);
let mut tf = TestFramework::builder(&mut rng).build();
Expand Down Expand Up @@ -4198,6 +4200,36 @@ fn check_freezable_supply(#[case] seed: Seed) {
))
);

// Try to spend with htlc
let htlc = HashedTimelockContract {
secret_hash: HtlcSecret::new_from_rng(&mut rng).hash(),
spend_key: Destination::AnyoneCanSpend,
refund_timelock: OutputTimeLock::ForSeconds(200),
refund_key: Destination::AnyoneCanSpend,
};
let result = tf
.make_block_builder()
.add_transaction(
TransactionBuilder::new()
.add_input(
TxInput::from_utxo(mint_tx_id.into(), 0),
InputWitness::NoSignature(None),
)
.add_output(TxOutput::Htlc(
OutputValue::TokenV1(token_id, amount_to_mint),
Box::new(htlc),
))
.build(),
)
.build_and_process(&mut rng);

assert_eq!(
result.unwrap_err(),
ChainstateError::ProcessBlockError(BlockError::StateUpdateFailed(
ConnectTransactionError::AttemptToSpendFrozenToken(token_id)
))
);

// Unfreeze the token
let unfreeze_tx = TransactionBuilder::new()
.add_input(
Expand Down
4 changes: 2 additions & 2 deletions chainstate/tx-verifier/src/transaction_verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,8 @@ where
match output {
TxOutput::Transfer(output_value, _)
| TxOutput::Burn(output_value)
| TxOutput::LockThenTransfer(output_value, _, _) => {
| TxOutput::LockThenTransfer(output_value, _, _)
| TxOutput::Htlc(output_value, _) => {
match output_value {
OutputValue::Coin(_) | OutputValue::TokenV0(_) => Ok(()),
OutputValue::TokenV1(ref token_id, _) => {
Expand Down Expand Up @@ -719,7 +720,6 @@ where
| TxOutput::IssueFungibleToken(_)
| TxOutput::IssueNft(_, _, _)
| TxOutput::DataDeposit(_)
| TxOutput::Htlc(_, _)
| TxOutput::AnyoneCanTake(_) => Ok(()),
}
})
Expand Down

0 comments on commit 109d9a1

Please sign in to comment.