Skip to content

Commit

Permalink
Merge pull request #844 from input-output-hk/catalyst-fund9-gold-prod
Browse files Browse the repository at this point in the history
revert(reintroduce witness checks): witness perf checks complete
  • Loading branch information
cong-or authored Jan 16, 2024
2 parents b5c4148 + ba6fe2e commit 2b75dd9
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions chain-impl-mockchain/src/ledger/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1878,33 +1878,48 @@ fn match_identifier_witness<'a>(

fn input_single_account_verify<'a>(
mut ledger: account::Ledger,
_block0_hash: &HeaderId,
_sign_data_hash: &TransactionSignDataHash,
block0_hash: &HeaderId,
sign_data_hash: &TransactionSignDataHash,
account: &account::Identifier,
_witness: &'a account::Witness,
witness: &'a account::Witness,
spending_counter: account::SpendingCounter,
value: Value,
) -> Result<account::Ledger, Error> {
// .remove_value() check if there's enough value and if not, returns a Err.
let new_ledger = ledger.remove_value(account, spending_counter, value)?;
ledger = new_ledger;

let tidsc = WitnessAccountData::new(block0_hash, sign_data_hash, spending_counter);
let verified = witness.verify(account.as_ref(), &tidsc);
if verified == chain_crypto::Verification::Failed {
return Err(Error::AccountInvalidSignature {
account: account.clone(),
witness: Witness::Account(spending_counter, witness.clone()),
});
};

Ok(ledger)
}

fn input_multi_account_verify<'a>(
mut ledger: multisig::Ledger,
_block0_hash: &HeaderId,
_sign_data_hash: &TransactionSignDataHash,
block0_hash: &HeaderId,
sign_data_hash: &TransactionSignDataHash,
account: &multisig::Identifier,
_witness: &'a multisig::Witness,
witness: &'a multisig::Witness,
spending_counter: account::SpendingCounter,
value: Value,
) -> Result<multisig::Ledger, Error> {
// .remove_value() check if there's enough value and if not, returns a Err.
let (new_ledger, _declaration) = ledger.remove_value(account, spending_counter, value)?;
let (new_ledger, declaration) = ledger.remove_value(account, spending_counter, value)?;

// TODO verify sig(pub_key,data)
let data_to_verify = WitnessMultisigData::new(block0_hash, sign_data_hash, spending_counter);
if !witness.verify(declaration, &data_to_verify) {
return Err(Error::MultisigInvalidSignature {
multisig: account.clone(),
witness: Witness::Multisig(spending_counter, witness.clone()),
});
}

ledger = new_ledger;
Ok(ledger)
Expand Down

0 comments on commit 2b75dd9

Please sign in to comment.