Skip to content

Commit

Permalink
fix(mint): check sig flag even if no inputs included
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Aug 13, 2024
1 parent 14f23ab commit 2923b86
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions crates/cdk/src/mint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,11 +857,26 @@ impl Mint {
&self,
melt_request: &MeltBolt11Request,
) -> Result<MeltQuote, Error> {
let ys: Vec<PublicKey> = melt_request
let state = self
.localstore
.update_melt_quote_state(&melt_request.quote, MeltQuoteState::Pending)
.await?;

match state {
MeltQuoteState::Unpaid => (),
MeltQuoteState::Pending => {
return Err(Error::PendingQuote);
}
MeltQuoteState::Paid => {
return Err(Error::PaidQuote);
}
}

let ys = melt_request
.inputs
.iter()
.flat_map(|p| hash_to_curve(&p.secret.to_bytes()))
.collect();
.map(|p| hash_to_curve(&p.secret.to_bytes()))
.collect::<Result<Vec<PublicKey>, _>>()?;

// Ensure proofs are unique and not being double spent
if melt_request.inputs.len() != ys.iter().collect::<HashSet<_>>().len() {
Expand All @@ -877,21 +892,6 @@ impl Mint {
self.verify_proof(proof).await?;
}

let state = self
.localstore
.update_melt_quote_state(&melt_request.quote, MeltQuoteState::Pending)
.await?;

match state {
MeltQuoteState::Unpaid => (),
MeltQuoteState::Pending => {
return Err(Error::PendingQuote);
}
MeltQuoteState::Paid => {
return Err(Error::PaidQuote);
}
}

let quote = self
.localstore
.get_melt_quote(&melt_request.quote)
Expand Down Expand Up @@ -933,13 +933,13 @@ impl Mint {
keyset_units.insert(keyset.unit);
}

if let Some(outputs) = &melt_request.outputs {
let EnforceSigFlag { sig_flag, .. } = enforce_sig_flag(melt_request.inputs.clone());
let EnforceSigFlag { sig_flag, .. } = enforce_sig_flag(melt_request.inputs.clone());

if sig_flag.eq(&SigFlag::SigAll) {
return Err(Error::SigAllUsedInMelt);
}
if sig_flag.eq(&SigFlag::SigAll) {
return Err(Error::SigAllUsedInMelt);
}

if let Some(outputs) = &melt_request.outputs {
let output_keysets_ids: HashSet<Id> = outputs.iter().map(|b| b.keyset_id).collect();
for id in output_keysets_ids {
let keyset = self
Expand Down

0 comments on commit 2923b86

Please sign in to comment.