Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rahul/ifl 2146 replace pgk on build with proof authorizing key #4650

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ironfish-rust-nodejs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ironfish = { path = "../ironfish-rust" }
ironfish_mpc = { path = "../ironfish-mpc" }
napi = { version = "2.13.2", features = ["napi6"] }
napi-derive = "2.13.0"
jubjub = { git = "https://github.com/iron-fish/jubjub.git", branch = "blstrs" }
rand = "0.8.5"

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class Transaction {
* aka: self.value_balance - intended_transaction_fee - change = 0
*/
post(spenderHexKey: string, changeGoesTo: string | undefined | null, intendedTransactionFee: bigint): Buffer
build(proofGenerationKeyStr: string, viewKeyStr: string, outgoingViewKeyStr: string, intendedTransactionFee: bigint, changeGoesTo?: string | undefined | null): Buffer
build(proofAuthorizingKeyStr: string, viewKeyStr: string, outgoingViewKeyStr: string, intendedTransactionFee: bigint, changeGoesTo?: string | undefined | null): Buffer
setExpiration(sequence: number): void
}
export type NativeUnsignedTransaction = UnsignedTransaction
Expand Down
11 changes: 6 additions & 5 deletions ironfish-rust-nodejs/src/structs/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use ironfish::frost::round1::SigningCommitments;
use ironfish::frost::round2::SignatureShare;
use ironfish::frost::Identifier;
use ironfish::frost::SigningPackage;
use ironfish::serializing::fr::FrSerializable;
use ironfish::serializing::hex_to_vec_bytes;
use ironfish::serializing::{bytes_to_hex, hex_to_bytes};
use ironfish::transaction::unsigned::UnsignedTransaction;
Expand All @@ -22,7 +23,6 @@ use ironfish::transaction::{
TRANSACTION_FEE_SIZE, TRANSACTION_PUBLIC_KEY_SIZE, TRANSACTION_SIGNATURE_SIZE,
};
use ironfish::{
keys::proof_generation_key::{ProofGenerationKey, ProofGenerationKeySerializable},
MerkleNoteHash, OutgoingViewKey, ProposedTransaction, PublicAddress, SaplingKey, Transaction,
ViewKey,
};
Expand Down Expand Up @@ -327,7 +327,7 @@ impl NativeTransaction {
#[napi]
pub fn build(
&mut self,
proof_generation_key_str: String,
proof_authorizing_key_str: String,
view_key_str: String,
outgoing_view_key_str: String,
intended_transaction_fee: BigInt,
Expand All @@ -336,16 +336,17 @@ impl NativeTransaction {
let view_key = ViewKey::from_hex(&view_key_str).map_err(to_napi_err)?;
let outgoing_view_key =
OutgoingViewKey::from_hex(&outgoing_view_key_str).map_err(to_napi_err)?;
let proof_generation_key = ProofGenerationKey::from_hex(&proof_generation_key_str)
.map_err(|_| to_napi_err("PublicKeyPackage hex to bytes failed"))?;
let proof_authorizing_key = jubjub::Fr::from_hex(&proof_authorizing_key_str)
.map_err(|_| to_napi_err("PublicKeyPackage authorizing key hex to bytes failed"))?;

let change_address = match change_goes_to {
Some(address) => Some(PublicAddress::from_hex(&address).map_err(to_napi_err)?),
None => None,
};
let unsigned_transaction = self
.transaction
.build(
proof_generation_key,
proof_authorizing_key,
view_key,
outgoing_view_key,
intended_transaction_fee.get_i64().0,
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/tests/unsigned.test.slow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("UnsignedTransaction", () => {
const proposedTx = new Transaction(2);
proposedTx.mint(asset, 5n);
const unsignedTxBuffer = proposedTx.build(
key.viewKey.slice(0, 64) + key.proofAuthorizingKey, //todo(rahul): change this to accept just proof authorizing key when the interface changes
key.proofAuthorizingKey,
key.viewKey,
key.outgoingViewKey,
0n
Expand Down
11 changes: 8 additions & 3 deletions ironfish-rust/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,19 @@ impl ProposedTransaction {

pub fn build(
&mut self,
proof_generation_key: ProofGenerationKey,
proof_authorizing_key: jubjub::Fr,
view_key: ViewKey,
outgoing_view_key: OutgoingViewKey,
intended_transaction_fee: i64,
change_goes_to: Option<PublicAddress>,
) -> Result<UnsignedTransaction, IronfishError> {
let public_address = view_key.public_address()?;

let proof_generation_key = ProofGenerationKey {
ak: view_key.authorizing_key,
nsk: proof_authorizing_key,
};

// skip adding change notes if this is special case of a miners fee transaction
let is_miners_fee = self.outputs.iter().any(|output| output.get_is_miners_fee());
if !is_miners_fee {
Expand Down Expand Up @@ -337,7 +342,7 @@ impl ProposedTransaction {
let i64_fee = i64::try_from(intended_transaction_fee)?;

let unsigned = self.build(
spender_key.sapling_proof_generation_key(),
spender_key.proof_authorizing_key,
spender_key.view_key().clone(),
spender_key.outgoing_view_key().clone(),
i64_fee,
Expand Down Expand Up @@ -377,7 +382,7 @@ impl ProposedTransaction {
output.set_is_miners_fee();
}
let unsigned = self.build(
spender_key.sapling_proof_generation_key(),
spender_key.proof_authorizing_key,
spender_key.view_key().clone(),
spender_key.outgoing_view_key().clone(),
*self.value_balances.fee(),
Expand Down
6 changes: 3 additions & 3 deletions ironfish-rust/src/transaction/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ fn test_proposed_transaction_build() {

let unsigned_transaction = transaction
.build(
spender_key.sapling_proof_generation_key(),
spender_key.proof_authorizing_key,
spender_key.view_key().clone(),
spender_key.outgoing_view_key().clone(),
intended_fee,
Expand Down Expand Up @@ -685,7 +685,7 @@ fn test_sign_simple() {
// build transaction, generate proofs
let unsigned_transaction = transaction
.build(
spender_key.sapling_proof_generation_key(),
spender_key.proof_authorizing_key,
spender_key.view_key().clone(),
spender_key.outgoing_view_key().clone(),
1,
Expand Down Expand Up @@ -779,7 +779,7 @@ fn test_sign_frost() {
// build UnsignedTransaction without signing
let mut unsigned_transaction = transaction
.build(
key_packages.proof_generation_key,
key_packages.proof_generation_key.nsk,
key_packages.view_key,
key_packages.outgoing_view_key,
intended_fee,
Expand Down
4 changes: 2 additions & 2 deletions ironfish/src/primitives/rawTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ export class RawTransaction {
}

build(
proofGenerationKey: string,
proofAuthorizingKey: string,
viewKey: string,
outgoingViewKey: string,
): UnsignedTransaction {
const builder = this._build()

const serialized = builder.build(
proofGenerationKey,
proofAuthorizingKey,
viewKey,
outgoingViewKey,
this.fee,
Expand Down
6 changes: 1 addition & 5 deletions ironfish/src/testUtilities/fixtures/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ export async function useUnsignedTxFixture(
Assert.isNotNull(from.spendingKey)
const key = generateKeyFromPrivateKey(from.spendingKey)
const unsignedBuffer = raw
.build(
key.viewKey.slice(0, 64) + key.proofAuthorizingKey, //todo(rahul): change this to accept just proof authorizing key when the interface changes
key.viewKey,
key.outgoingViewKey,
)
.build(key.proofAuthorizingKey, key.viewKey, key.outgoingViewKey)
.serialize()
return new UnsignedTransaction(unsignedBuffer)
})
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/wallet/wallet.test.slow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ describe('Wallet', () => {
})

const unsignedTransaction = rawTransaction.build(
trustedDealerPackage.proofGenerationKey,
trustedDealerPackage.proofGenerationKey.slice(64, 128),
trustedDealerPackage.viewKey,
trustedDealerPackage.outgoingViewKey,
)
Expand Down
Loading