Skip to content

Commit

Permalink
re-order steps of verification
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jan 30, 2025
1 parent 0aabcc4 commit 667d9f3
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,24 @@ pub trait ContractVerify<SealDef: RgbSealDef>: ContractApi<SealDef> {
closed_seals.push(seal);
}

// We need to check that all seal definitions strictly match operation-defined destructible cells
let defined = header
.operation
.destructible
.iter()
.map(|cell| cell.auth.to_byte_array())
.collect::<BTreeSet<_>>();
let sealed = header
.defined_seals
.values()
.map(|seal| seal.auth_token().to_byte_array())
.collect::<BTreeSet<_>>();
// It is a subset and not equal set since some of the seals might be unknown to us: we know their
// commitment auth token, but do not know definition.
if !sealed.is_subset(&defined) {
return Err(VerificationError::SealsDefinitionMismatch(opid));
}

// This convoluted logic happens since we use a state machine which ensures the client can't lie to
// the verifier
let mut witness_count = 0usize;
Expand Down Expand Up @@ -148,24 +166,6 @@ pub trait ContractVerify<SealDef: RgbSealDef>: ContractApi<SealDef> {
witness_count += 1;
}

// We need to check that all seal definitions strictly match operation-defined destructible cells
let defined = header
.operation
.destructible
.iter()
.map(|cell| cell.auth.to_byte_array())
.collect::<BTreeSet<_>>();
let sealed = header
.defined_seals
.values()
.map(|seal| seal.auth_token().to_byte_array())
.collect::<BTreeSet<_>>();
// It is a subset and not equal set since some of the seals might be unknown to us: we know their
// commitment auth token, but do not know definition.
if !sealed.is_subset(&defined) {
return Err(VerificationError::SealsDefinitionMismatch(opid));
}

if !closed_seals.is_empty() && witness_count == 0 {
return Err(VerificationError::NoWitness(opid));
}
Expand Down

0 comments on commit 667d9f3

Please sign in to comment.