Skip to content

Commit

Permalink
Merge pull request #2208 from iron-fish/staging
Browse files Browse the repository at this point in the history
STAGING -> MASTER
  • Loading branch information
NullSoldier authored Sep 19, 2022
2 parents 46d759c + 7800033 commit 0efb836
Show file tree
Hide file tree
Showing 43 changed files with 1,289 additions and 569 deletions.
6 changes: 3 additions & 3 deletions ironfish-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ironfish",
"version": "0.1.46",
"version": "0.1.47",
"description": "CLI for running and interacting with an Iron Fish node",
"author": "Iron Fish <[email protected]> (https://ironfish.network)",
"main": "build/src/index.js",
Expand Down Expand Up @@ -55,8 +55,8 @@
},
"dependencies": {
"@aws-sdk/client-s3": "3.127.0",
"@ironfish/rust-nodejs": "0.1.13",
"@ironfish/sdk": "0.0.23",
"@ironfish/rust-nodejs": "0.1.14",
"@ironfish/sdk": "0.0.24",
"@oclif/core": "1.16.1",
"@oclif/plugin-help": "5.1.12",
"@oclif/plugin-not-found": "2.3.1",
Expand Down
7 changes: 7 additions & 0 deletions ironfish-rust-nodejs/Cargo.lock

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

12 changes: 6 additions & 6 deletions ironfish-rust-nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@

/* auto-generated by NAPI-RS */

export class ExternalObject<T> {
readonly '': {
readonly '': unique symbol
[K: symbol]: T
}
}
export const KEY_LENGTH: number
export const NONCE_LENGTH: number
export function randomBytes(bytesLength: number): Uint8Array
Expand Down Expand Up @@ -40,6 +34,12 @@ export class BoxKeyPair {
get publicKey(): Buffer
get secretKey(): Buffer
}
export type NativeRollingFilter = RollingFilter
export class RollingFilter {
constructor(items: number, rate: number)
add(value: Buffer): void
test(value: Buffer): boolean
}
export type NativeNoteEncrypted = NoteEncrypted
export class NoteEncrypted {
constructor(jsBytes: Buffer)
Expand Down
3 changes: 2 additions & 1 deletion ironfish-rust-nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,15 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

const { KEY_LENGTH, NONCE_LENGTH, BoxKeyPair, randomBytes, boxMessage, unboxMessage, NoteEncrypted, Note, TransactionPosted, Transaction, verifyTransactions, generateKey, generateNewPublicAddress, initializeSapling, FoundBlockResult, ThreadPoolHandler, isValidPublicAddress } = nativeBinding
const { KEY_LENGTH, NONCE_LENGTH, BoxKeyPair, randomBytes, boxMessage, unboxMessage, RollingFilter, NoteEncrypted, Note, TransactionPosted, Transaction, verifyTransactions, generateKey, generateNewPublicAddress, initializeSapling, FoundBlockResult, ThreadPoolHandler, isValidPublicAddress } = nativeBinding

module.exports.KEY_LENGTH = KEY_LENGTH
module.exports.NONCE_LENGTH = NONCE_LENGTH
module.exports.BoxKeyPair = BoxKeyPair
module.exports.randomBytes = randomBytes
module.exports.boxMessage = boxMessage
module.exports.unboxMessage = unboxMessage
module.exports.RollingFilter = RollingFilter
module.exports.NoteEncrypted = NoteEncrypted
module.exports.Note = Note
module.exports.TransactionPosted = TransactionPosted
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-darwin-arm64",
"version": "0.1.13",
"version": "0.1.14",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-darwin-x64",
"version": "0.1.13",
"version": "0.1.14",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/linux-arm64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-linux-arm64-gnu",
"version": "0.1.13",
"version": "0.1.14",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/linux-arm64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-linux-arm64-musl",
"version": "0.1.13",
"version": "0.1.14",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-linux-x64-gnu",
"version": "0.1.13",
"version": "0.1.14",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/linux-x64-musl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-linux-x64-musl",
"version": "0.1.13",
"version": "0.1.14",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs-win32-x64-msvc",
"version": "0.1.13",
"version": "0.1.14",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/rust-nodejs",
"version": "0.1.13",
"version": "0.1.14",
"description": "Node.js bindings for Rust code required by the Iron Fish SDK",
"main": "index.js",
"types": "index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions ironfish-rust-nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use ironfish_rust::mining;
use ironfish_rust::sapling_bls12;

pub mod nacl;
pub mod rolling_filter;
pub mod structs;

#[napi(object)]
Expand Down
35 changes: 35 additions & 0 deletions ironfish-rust-nodejs/src/rolling_filter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use ironfish_rust::rolling_filter::RollingFilter;
use napi::JsBuffer;
use napi_derive::napi;

#[napi(js_name = "RollingFilter")]
pub struct NativeRollingFilter {
inner: RollingFilter,
}

#[napi]
impl NativeRollingFilter {
#[napi(constructor)]
#[allow(clippy::new_without_default)]
pub fn new(items: u32, rate: f64) -> Self {
Self {
inner: RollingFilter::new(items, rate),
}
}

#[napi]
pub fn add(&mut self, value: JsBuffer) {
let v = value.into_value().unwrap();
self.inner.add(v.as_ref())
}

#[napi]
pub fn test(&self, value: JsBuffer) -> bool {
let v = value.into_value().unwrap();
self.inner.test(v.as_ref())
}
}
12 changes: 5 additions & 7 deletions ironfish-rust-nodejs/src/structs/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use ironfish_rust::{MerkleNoteHash, ProposedTransaction, PublicAddress, SaplingK
use napi::{bindgen_prelude::*, JsBuffer};
use napi_derive::napi;

use ironfish_rust::sapling_bls12::SAPLING;

use super::note::NativeNote;
use super::spend_proof::NativeSpendProof;
use super::witness::JsWitness;
Expand All @@ -27,8 +25,8 @@ impl NativeTransactionPosted {
pub fn new(js_bytes: JsBuffer) -> Result<NativeTransactionPosted> {
let bytes = js_bytes.into_value()?;

let transaction = Transaction::read(SAPLING.clone(), bytes.as_ref())
.map_err(|err| Error::from_reason(err.to_string()))?;
let transaction =
Transaction::read(bytes.as_ref()).map_err(|err| Error::from_reason(err.to_string()))?;

Ok(NativeTransactionPosted { transaction })
}
Expand Down Expand Up @@ -160,7 +158,7 @@ impl NativeTransaction {
#[napi(constructor)]
pub fn new() -> NativeTransaction {
NativeTransaction {
transaction: ProposedTransaction::new(SAPLING.clone()),
transaction: ProposedTransaction::new(),
}
}

Expand Down Expand Up @@ -271,11 +269,11 @@ pub fn verify_transactions(serialized_transactions: Vec<Buffer>) -> bool {
let mut transactions: Vec<Transaction> = vec![];

for tx_bytes in serialized_transactions {
match Transaction::read(SAPLING.clone(), &mut tx_bytes.as_ref()) {
match Transaction::read(&mut tx_bytes.as_ref()) {
Ok(tx) => transactions.push(tx),
Err(_) => return false,
}
}

batch_verify_transactions(SAPLING.clone(), transactions.iter()).is_ok()
batch_verify_transactions(transactions.iter()).is_ok()
}
7 changes: 7 additions & 0 deletions ironfish-rust/Cargo.lock

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

3 changes: 2 additions & 1 deletion ironfish-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ default = []
native = ["bellman/multicore", "zcash_proofs/multicore"]

[dependencies]
bellman = { version = "0.13.1", default-features = false, features = ["groth16"]}
bellman = { version = "0.13.1", default-features = false, features = ["groth16"] }
blake2b_simd = "1.0.0"
blake2s_simd = "1.0.0"
blake3 = "1.3.1"
Expand All @@ -29,6 +29,7 @@ libc = "0.2.126" # sub-dependency that needs a pinned version until a new releas
rand = "0.8.5"
rust-crypto-wasm = "0.3.1" # in favor of rust-crypto as this one is wasm friendly
tiny-bip39 = "0.8"
xxhash-rust = { version = "0.8.5", features = ["xxh3"] }
zcash_primitives = "0.7.0"
zcash_proofs = "0.7.1"

Expand Down
1 change: 1 addition & 0 deletions ironfish-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod mining;
pub mod nacl;
pub mod note;
pub mod receiving;
pub mod rolling_filter;
pub mod sapling_bls12;
pub mod spending;
pub mod transaction;
Expand Down
26 changes: 10 additions & 16 deletions ironfish-rust/src/receiving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use super::{errors, keys::SaplingKey, merkle_note::MerkleNote, note::Note, Sapling};
use crate::sapling_bls12::SAPLING;

use super::{errors, keys::SaplingKey, merkle_note::MerkleNote, note::Note};
use bellman::groth16;
use bls12_381::{Bls12, Scalar};
use group::Curve;
Expand All @@ -11,16 +13,12 @@ use rand::{rngs::OsRng, thread_rng, Rng};
use zcash_primitives::sapling::ValueCommitment;
use zcash_proofs::circuit::sapling::Output;

use std::{io, sync::Arc};
use std::io;

/// Parameters used when constructing proof that a new note exists. The owner
/// of this note is the recipient of funds in a transaction. The note is signed
/// with the owners public key so only they can read it.
pub struct ReceiptParams {
/// Parameters for a Jubjub BLS12 curve. This is essentially just a global
/// value.
pub(crate) sapling: Arc<Sapling>,

/// Proof that the output circuit was valid and successful
pub(crate) proof: groth16::Proof<Bls12>,

Expand All @@ -35,7 +33,6 @@ pub struct ReceiptParams {
impl ReceiptParams {
/// Construct the parameters for proving a new specific note
pub(crate) fn new(
sapling: Arc<Sapling>,
spender_key: &SaplingKey,
note: &Note,
) -> Result<ReceiptParams, errors::SaplingProofError> {
Expand All @@ -61,10 +58,9 @@ impl ReceiptParams {
esk: Some(diffie_hellman_keys.0),
};
let proof =
groth16::create_random_proof(output_circuit, &sapling.receipt_params, &mut OsRng)?;
groth16::create_random_proof(output_circuit, &SAPLING.receipt_params, &mut OsRng)?;

let receipt_proof = ReceiptParams {
sapling,
proof,
value_commitment_randomness,
merkle_note,
Expand All @@ -85,7 +81,7 @@ impl ReceiptParams {
proof: self.proof.clone(),
merkle_note: self.merkle_note.clone(),
};
receipt_proof.verify_proof(&self.sapling)?;
receipt_proof.verify_proof()?;

Ok(receipt_proof)
}
Expand Down Expand Up @@ -134,11 +130,11 @@ impl ReceiptProof {

/// Verify that the proof demonstrates knowledge that a note exists with
/// the value_commitment, public_key, and note_commitment on this proof.
pub fn verify_proof(&self, sapling: &Sapling) -> Result<(), errors::SaplingProofError> {
pub fn verify_proof(&self) -> Result<(), errors::SaplingProofError> {
self.verify_value_commitment()?;

match groth16::verify_proof(
&sapling.receipt_verifying_key,
&SAPLING.receipt_verifying_key,
&self.proof,
&self.public_inputs()[..],
) {
Expand Down Expand Up @@ -200,24 +196,22 @@ mod test {
use crate::{
keys::SaplingKey,
note::{Memo, Note},
sapling_bls12,
};
use ff::PrimeField;
use group::Curve;
use jubjub::ExtendedPoint;

#[test]
fn test_receipt_round_trip() {
let sapling = &*sapling_bls12::SAPLING;
let spender_key: SaplingKey = SaplingKey::generate_key();
let note = Note::new(spender_key.generate_public_address(), 42, Memo::default());

let receipt = ReceiptParams::new(sapling.clone(), &spender_key, &note)
let receipt = ReceiptParams::new(&spender_key, &note)
.expect("should be able to create receipt proof");
let proof = receipt
.post()
.expect("Should be able to post receipt proof");
proof.verify_proof(sapling).expect("proof should check out");
proof.verify_proof().expect("proof should check out");

// test serialization
let mut serialized_proof = vec![];
Expand Down
Loading

0 comments on commit 0efb836

Please sign in to comment.