diff --git a/app/rust/src/ffi.rs b/app/rust/src/ffi.rs index c5a4738..690ca3f 100644 --- a/app/rust/src/ffi.rs +++ b/app/rust/src/ffi.rs @@ -10,7 +10,7 @@ mod check_signature { use penumbra_keys::FullViewingKey as PenFvk; use penumbra_proto::{DomainType, penumbra::core::transaction::v1::TransactionPlan as ProtoTxPlan}; use penumbra_tct::Tree; - use penumbra_transaction::{TransactionPlan, AuthorizationData, WitnessData}; + use penumbra_transaction::{TransactionPlan, AuthorizationData, WitnessData, ActionPlan}; use penumbra_asset::{Value, STAKING_TOKEN_ASSET_ID}; use penumbra_shielded_pool::{Note, OutputPlan, SpendPlan}; use penumbra_tct::Witness; @@ -36,13 +36,6 @@ mod check_signature { #[tokio::test] async fn check_signature() { - let plan_bytes = hex::decode(TRANSACTION_PLAN).unwrap(); - // first get the SpendAuthorization - // Record that note in an SCT, where we can generate an auth path. - let mut sct = Tree::new(); - - let plan = TransactionPlan::decode(&plan_bytes[..]).expect("Failed to decode protobuf message"); - assert_eq!(plan.actions.len(), 1); let spk_bytes: [u8; 32] = hex::decode(SPEND_KEY).unwrap().try_into().unwrap(); let spk_bytes = SpendKeyBytes(spk_bytes); @@ -50,6 +43,18 @@ mod check_signature { let sk = SpendKey::from(spk_bytes); let fvk = sk.full_viewing_key(); + // Generate two notes controlled by the test address. + // pub fn payment_address(&self, index: AddressIndex) -> (Address, fmd::DetectionKey) { + let address_index = AddressIndex::new(0); + let (address, _) = fvk.payment_address(address_index); + + let plan_bytes = hex::decode(TRANSACTION_PLAN).unwrap(); + + let mut sct = Tree::new(); + + let mut plan = TransactionPlan::decode(&plan_bytes[..]).expect("Failed to decode protobuf message"); + assert_eq!(plan.actions.len(), 1); + let effect_hash = plan.effect_hash(fvk).expect("Failed to get effect hash"); // The authorization data from the SDK let sdk_auth_data = plan.authorize(OsRng, &sk).unwrap(); @@ -60,36 +65,17 @@ mod check_signature { sdk_auth_data.effect_hash.unwrap().0 ); - assert!(sdk_auth_data.effect_hash.is_some()); - assert!(sdk_auth_data.delegator_vote_auths.is_empty()); + assert!(sdk_auth_data.effect_hash.is_some(), "Effect hash is not present"); + assert!(sdk_auth_data.delegator_vote_auths.is_empty(), "Delegator vote auths are not empty"); - // ************** Add stuff to the tree controlled by this address - // Generate two notes controlled by the test address. - // pub fn payment_address(&self, index: AddressIndex) -> (Address, fmd::DetectionKey) { - let address_index = AddressIndex::new(0); - let (address, _) = fvk.payment_address(address_index); - let value = Value { - amount: 100u64.into(), - asset_id: *STAKING_TOKEN_ASSET_ID, - }; - let note = Note::generate(&mut OsRng, &address, value); - let value2 = Value { - amount: 50u64.into(), - asset_id: *STAKING_TOKEN_ASSET_ID, - }; - let note2 = Note::generate(&mut OsRng, &address, value2); - for _ in 0..5 { - let random_note = Note::generate(&mut OsRng, &address, value); - sct.insert(Witness::Keep, random_note.commit()) - .unwrap(); + // Now at our decode note to the tree + // for a proof to be generated and used for signature verification + for action in plan.actions.iter_mut() { + if let ActionPlan::Spend(spend) = action { + sct.insert(Witness::Keep, spend.note.commit()).unwrap(); + } } - sct.insert(Witness::Keep, note.commit()).unwrap(); - sct.insert(Witness::Keep, note2.commit()).unwrap(); - - // Do we want to seal the SCT block here? - let auth_path = sct.witness(note.commit()).unwrap(); - let auth_path2 = sct.witness(note2.commit()).unwrap(); // Here try to create an AuthorizationData from the hardcoded // signatures let dev_effec_hash = hex::decode(EFFECT_HASH).unwrap(); @@ -118,7 +104,6 @@ mod check_signature { // bellow we use the parsed AuthorizationData to validate transaction signatures let tx = plan - // .build_concurrent(fvk, &witness_data, &sdk_auth_data) .build_concurrent(fvk, &witness_data, &dev_auth_data) .await .expect("can build transaction");