Skip to content

Commit

Permalink
Rahul/ifl 2093 add frost signature to unsigned spends and mints (#4532)
Browse files Browse the repository at this point in the history
* adding frost signature assignment

* moved sign_frost to unsignedMintDescription

* adding frost sign test for mints

* function name change

* running linter

* removing return type from add signature functions

* linting

* adding description return type

* removing extra key in test
  • Loading branch information
patnir authored Jan 11, 2024
1 parent 99763bb commit f116744
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
30 changes: 29 additions & 1 deletion ironfish-rust/src/transaction/mints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ impl UnsignedMintDescription {
Ok(self.description)
}

pub fn add_signature(mut self, signature: Signature) -> MintDescription {
self.description.authorizing_signature = signature;
self.description
}

pub fn read<R: io::Read>(
mut reader: R,
version: TransactionVersion,
Expand Down Expand Up @@ -356,7 +361,7 @@ impl MintDescription {
mod test {
use ff::Field;
use ironfish_zkp::{constants::SPENDING_KEY_GENERATOR, redjubjub};
use rand::thread_rng;
use rand::{random, thread_rng};

use crate::{
assets::asset::Asset,
Expand Down Expand Up @@ -670,4 +675,27 @@ mod test {
);
assert!(unsigned_mint.is_err());
}

#[test]
fn test_add_signature() {
let key = SaplingKey::generate_key();
let public_address = key.public_address();

let asset = Asset::new(public_address, "name", "").expect("should be able to create asset");
let public_key_randomness = jubjub::Fr::random(thread_rng());
let randomized_public_key = redjubjub::PublicKey(key.view_key.authorizing_key.into())
.randomize(public_key_randomness, *SPENDING_KEY_GENERATOR);
let value = random();
let builder = MintBuilder::new(asset, value);
// create a random private key and sign random message as placeholder
let private_key = redjubjub::PrivateKey(jubjub::Fr::random(thread_rng()));
let public_key = redjubjub::PublicKey::from_private(&private_key, *SPENDING_KEY_GENERATOR);
let msg = [0u8; 32];
let signature = private_key.sign(&msg, &mut thread_rng(), *SPENDING_KEY_GENERATOR);
let unsigned_spend_description = builder
.build(&key, &public_key_randomness, &randomized_public_key)
.expect("should be able to build proof");
unsigned_spend_description.add_signature(signature);
assert!(public_key.verify(&msg, &signature, *SPENDING_KEY_GENERATOR))
}
}
45 changes: 44 additions & 1 deletion ironfish-rust/src/transaction/spends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ impl UnsignedSpendDescription {
Ok(self.description)
}

pub fn add_signature(mut self, signature: Signature) -> SpendDescription {
self.description.authorizing_signature = signature;
self.description
}

pub fn read<R: io::Read>(mut reader: R) -> Result<Self, IronfishError> {
let public_key_randomness = read_scalar(&mut reader)?;
let description = SpendDescription::read(&mut reader)?;
Expand Down Expand Up @@ -409,7 +414,7 @@ mod test {
use ff::Field;
use group::Curve;
use ironfish_zkp::constants::SPENDING_KEY_GENERATOR;
use ironfish_zkp::redjubjub;
use ironfish_zkp::redjubjub::{self, PrivateKey, PublicKey};
use rand::prelude::*;
use rand::{thread_rng, Rng};

Expand Down Expand Up @@ -579,4 +584,42 @@ mod test {
.expect("should be able to serialize proof again");
assert_eq!(serialized_proof, serialized_again);
}

#[test]
fn test_add_signature() {
let key = SaplingKey::generate_key();
let public_address = key.public_address();
let sender_key = SaplingKey::generate_key();

let note_randomness = random();

let note = Note::new(
public_address,
note_randomness,
"",
NATIVE_ASSET,
sender_key.public_address(),
);
let witness = make_fake_witness(&note);
let public_key_randomness = jubjub::Fr::random(thread_rng());
let randomized_public_key = redjubjub::PublicKey(key.view_key.authorizing_key.into())
.randomize(public_key_randomness, *SPENDING_KEY_GENERATOR);

let builder = SpendBuilder::new(note, &witness);
// create a random private key and sign random message as placeholder
let private_key = PrivateKey(jubjub::Fr::random(thread_rng()));
let public_key = PublicKey::from_private(&private_key, *SPENDING_KEY_GENERATOR);
let msg = [0u8; 32];
let signature = private_key.sign(&msg, &mut thread_rng(), *SPENDING_KEY_GENERATOR);
let unsigned_spend_description = builder
.build(
&key.sapling_proof_generation_key(),
key.view_key(),
&public_key_randomness,
&randomized_public_key,
)
.expect("should be able to build proof");
unsigned_spend_description.add_signature(signature);
assert!(public_key.verify(&msg, &signature, *SPENDING_KEY_GENERATOR))
}
}

0 comments on commit f116744

Please sign in to comment.