Skip to content

Commit

Permalink
refactor(reintroduce witness sig check): sig without spending counter
Browse files Browse the repository at this point in the history
  • Loading branch information
cong-or committed Dec 6, 2023
1 parent 6782a34 commit 746e12f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions chain-impl-mockchain/src/ledger/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1878,16 +1878,28 @@ fn match_identifier_witness<'a>(
fn input_single_account_verify<'a>(
mut ledger: account::Ledger,
_block0_hash: &HeaderId,
_sign_data_hash: &TransactionSignDataHash,
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 verified = witness.verify(
account.as_ref(),
&WitnessAccountData(sign_data_hash.as_ref().to_vec()),
);

if verified == chain_crypto::Verification::Failed {
return Err(Error::AccountInvalidSignature {
account: account.clone(),
witness: Witness::Account(spending_counter, witness.clone()),
});
};

// TODO verify sig(pub_key,data)
Ok(ledger)
}
Expand Down
2 changes: 1 addition & 1 deletion chain-impl-mockchain/src/transaction/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl AsRef<[u8]> for WitnessUtxoData {
}
}

pub struct WitnessAccountData(Vec<u8>);
pub struct WitnessAccountData(pub Vec<u8>);

impl WitnessAccountData {
pub fn new(
Expand Down

0 comments on commit 746e12f

Please sign in to comment.