Skip to content

Commit

Permalink
Remove additional notes which are not strictly necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
neithanmo committed Jan 7, 2025
1 parent e18ca0e commit d6afe9d
Showing 1 changed file with 21 additions and 36 deletions.
57 changes: 21 additions & 36 deletions app/rust/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,20 +36,25 @@ 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);

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();
Expand All @@ -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();
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit d6afe9d

Please sign in to comment.