Skip to content

Commit 56dfee2

Browse files
authored
validates the point of failure for signing tx with wrong key (#5601)
adds a test that signs a transaction with a different key than the key used to generate proofs for the transaction the test confirms that signing the transaction with the wrong key succeeds, but the transaction does not verify
1 parent fd381cf commit 56dfee2

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

ironfish-rust/src/transaction/tests.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,58 @@ fn test_sign_simple() {
812812
verify_transaction(&signed_transaction).expect("should be able to verify transaction");
813813
}
814814

815+
#[test]
816+
fn test_sign_key_mismatch_failure() {
817+
let spender_key = SaplingKey::generate_key();
818+
let receiver_key = SaplingKey::generate_key();
819+
let sender_key = SaplingKey::generate_key();
820+
821+
let in_note = Note::new(
822+
spender_key.public_address(),
823+
42,
824+
"",
825+
NATIVE_ASSET,
826+
sender_key.public_address(),
827+
);
828+
let out_note = Note::new(
829+
receiver_key.public_address(),
830+
40,
831+
"",
832+
NATIVE_ASSET,
833+
spender_key.public_address(),
834+
);
835+
let witness = make_fake_witness(&in_note);
836+
837+
// create transaction, add spend and output
838+
let mut transaction = ProposedTransaction::new(TransactionVersion::latest());
839+
transaction
840+
.add_spend(in_note, &witness)
841+
.expect("should be able to add a spend");
842+
transaction
843+
.add_output(out_note)
844+
.expect("should be able to add an output");
845+
846+
// build transaction, generate proofs
847+
let unsigned_transaction = transaction
848+
.build(
849+
spender_key.proof_authorizing_key,
850+
spender_key.view_key().clone(),
851+
spender_key.outgoing_view_key().clone(),
852+
1,
853+
Some(spender_key.public_address()),
854+
)
855+
.expect("should be able to build unsigned transaction");
856+
857+
// sign with different, mismatched key
858+
let signer_key = SaplingKey::generate_key();
859+
let signed_transaction = unsigned_transaction
860+
.sign(&signer_key)
861+
.expect("should be able to sign transaction");
862+
863+
// verify transaction
864+
verify_transaction(&signed_transaction).expect_err("should not be able to verify transaction");
865+
}
866+
815867
#[test]
816868
fn test_aggregate_signature_shares() {
817869
let spender_key = SaplingKey::generate_key();

0 commit comments

Comments
 (0)