Skip to content

Commit

Permalink
Merge pull request #4657 from iron-fish/staging
Browse files Browse the repository at this point in the history
STAGING -> MASTER
  • Loading branch information
hughy authored Feb 1, 2024
2 parents a12ebdd + 517e702 commit 4fab80d
Show file tree
Hide file tree
Showing 104 changed files with 1,590 additions and 1,077 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

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": "1.18.0",
"version": "1.19.0",
"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 @@ -62,8 +62,8 @@
"@aws-sdk/client-s3": "3",
"@aws-sdk/client-secrets-manager": "3",
"@aws-sdk/s3-request-presigner": "3",
"@ironfish/rust-nodejs": "1.15.0",
"@ironfish/sdk": "1.18.0",
"@ironfish/rust-nodejs": "1.16.0",
"@ironfish/sdk": "1.19.0",
"@oclif/core": "1.23.1",
"@oclif/plugin-help": "5.1.12",
"@oclif/plugin-not-found": "2.3.1",
Expand Down
8 changes: 7 additions & 1 deletion ironfish-cli/src/commands/miners/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Miner extends IronfishCommand {
...RemoteFlags,
threads: Flags.integer({
char: 't',
default: -1,
default: 1,
description:
'Number of CPU threads to use for mining. -1 will auto-detect based on number of CPU cores.',
}),
Expand All @@ -52,6 +52,11 @@ export class Miner extends IronfishCommand {
description: 'Connect to pool over tls',
allowNo: true,
}),
fishHashFull: Flags.boolean({
description: 'Instantiate the full 4.6GB fish hash context in every thread',
default: false,
allowNo: true,
}),
}

async start(): Promise<void> {
Expand Down Expand Up @@ -145,6 +150,7 @@ export class Miner extends IronfishCommand {
logger: this.logger,
batchSize,
rpc,
fishHashFullContext: flags.fishHashFull,
})

miner.start()
Expand Down
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
23 changes: 14 additions & 9 deletions ironfish-rust-nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

/* auto-generated by NAPI-RS */

export interface SigningCommitments {
export interface Commitment {
hiding: string
binding: string
}
export function roundOne(keyPackage: string, seed: number): SigningCommitments
export function roundTwo(signingPackage: string, keyPackage: string, publicKeyRandomness: string, seed: number): string
export interface IdentifierCommitment {
identifier: string
commitment: Commitment
}
export function createSigningCommitment(keyPackage: string, seed: number): Commitment
export function createSigningShare(signingPackage: string, keyPackage: string, publicKeyRandomness: string, seed: number): string
export function splitSecret(coordinatorSaplingKey: string, minSigners: number, maxSigners: number, identifiers: Array<string>): TrustedDealerKeyPackages
export function contribute(inputPath: string, outputPath: string, seed?: string | undefined | null): Promise<string>
export function verifyTransform(paramsPath: string, newParamsPath: string): Promise<string>
Expand Down Expand Up @@ -62,7 +66,7 @@ export interface IdentiferKeyPackage {
}
export interface TrustedDealerKeyPackages {
verifyingKey: string
proofGenerationKey: string
proofAuthorizingKey: string
viewKey: string
incomingViewKey: string
outgoingViewKey: string
Expand All @@ -86,7 +90,7 @@ export interface Key {
incomingViewKey: string
outgoingViewKey: string
publicAddress: string
proofGenerationKey: string
proofAuthorizingKey: string
}
export function generateKey(): Key
export function spendingKeyToWords(privateKey: string, languageCode: LanguageCode): string
Expand Down Expand Up @@ -238,15 +242,16 @@ 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, publicAddressStr: 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
export class UnsignedTransaction {
constructor(jsBytes: Buffer)
serialize(): Buffer
publicKeyRandomness(): string
signingPackage(nativeCommitments: Record<string, SigningCommitments>): string
signingPackage(nativeIdentiferCommitments: Array<IdentifierCommitment>): string
sign(spenderHexKey: string): Buffer
signFrost(publicKeyPackageStr: string, signingPackageStr: string, signatureSharesMap: Record<string, string>): Buffer
}
export class FoundBlockResult {
Expand All @@ -255,8 +260,8 @@ export class FoundBlockResult {
constructor(randomness: string, miningRequestId: number)
}
export class ThreadPoolHandler {
constructor(threadCount: number, batchSize: number, pauseOnSuccess: boolean)
newWork(headerBytes: Buffer, target: Buffer, miningRequestId: number): void
constructor(threadCount: number, batchSize: number, pauseOnSuccess: boolean, useFishHash: boolean, fishHashFullContext: boolean)
newWork(headerBytes: Buffer, target: Buffer, miningRequestId: number, fishHash: boolean): void
stop(): void
pause(): void
getFoundBlock(): FoundBlockResult | null
Expand Down
6 changes: 3 additions & 3 deletions ironfish-rust-nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,11 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

const { FishHashContext, roundOne, roundTwo, ParticipantSecret, ParticipantIdentity, splitSecret, contribute, verifyTransform, KEY_LENGTH, NONCE_LENGTH, BoxKeyPair, randomBytes, boxMessage, unboxMessage, RollingFilter, initSignalHandler, triggerSegfault, ASSET_ID_LENGTH, ASSET_METADATA_LENGTH, ASSET_NAME_LENGTH, ASSET_LENGTH, Asset, NOTE_ENCRYPTION_KEY_LENGTH, MAC_LENGTH, ENCRYPTED_NOTE_PLAINTEXT_LENGTH, ENCRYPTED_NOTE_LENGTH, NoteEncrypted, PUBLIC_ADDRESS_LENGTH, RANDOMNESS_LENGTH, MEMO_LENGTH, AMOUNT_VALUE_LENGTH, DECRYPTED_NOTE_LENGTH, Note, PROOF_LENGTH, TRANSACTION_SIGNATURE_LENGTH, TRANSACTION_PUBLIC_KEY_RANDOMNESS_LENGTH, TRANSACTION_EXPIRATION_LENGTH, TRANSACTION_FEE_LENGTH, LATEST_TRANSACTION_VERSION, TransactionPosted, Transaction, verifyTransactions, UnsignedTransaction, LanguageCode, generateKey, spendingKeyToWords, wordsToSpendingKey, generateKeyFromPrivateKey, initializeSapling, FoundBlockResult, ThreadPoolHandler, isValidPublicAddress } = nativeBinding
const { FishHashContext, createSigningCommitment, createSigningShare, ParticipantSecret, ParticipantIdentity, splitSecret, contribute, verifyTransform, KEY_LENGTH, NONCE_LENGTH, BoxKeyPair, randomBytes, boxMessage, unboxMessage, RollingFilter, initSignalHandler, triggerSegfault, ASSET_ID_LENGTH, ASSET_METADATA_LENGTH, ASSET_NAME_LENGTH, ASSET_LENGTH, Asset, NOTE_ENCRYPTION_KEY_LENGTH, MAC_LENGTH, ENCRYPTED_NOTE_PLAINTEXT_LENGTH, ENCRYPTED_NOTE_LENGTH, NoteEncrypted, PUBLIC_ADDRESS_LENGTH, RANDOMNESS_LENGTH, MEMO_LENGTH, AMOUNT_VALUE_LENGTH, DECRYPTED_NOTE_LENGTH, Note, PROOF_LENGTH, TRANSACTION_SIGNATURE_LENGTH, TRANSACTION_PUBLIC_KEY_RANDOMNESS_LENGTH, TRANSACTION_EXPIRATION_LENGTH, TRANSACTION_FEE_LENGTH, LATEST_TRANSACTION_VERSION, TransactionPosted, Transaction, verifyTransactions, UnsignedTransaction, LanguageCode, generateKey, spendingKeyToWords, wordsToSpendingKey, generateKeyFromPrivateKey, initializeSapling, FoundBlockResult, ThreadPoolHandler, isValidPublicAddress } = nativeBinding

module.exports.FishHashContext = FishHashContext
module.exports.roundOne = roundOne
module.exports.roundTwo = roundTwo
module.exports.createSigningCommitment = createSigningCommitment
module.exports.createSigningShare = createSigningShare
module.exports.ParticipantSecret = ParticipantSecret
module.exports.ParticipantIdentity = ParticipantIdentity
module.exports.splitSecret = splitSecret
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": "1.15.0",
"version": "1.16.0",
"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": "1.15.0",
"version": "1.16.0",
"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": "1.15.0",
"version": "1.16.0",
"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": "1.15.0",
"version": "1.16.0",
"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": "1.15.0",
"version": "1.16.0",
"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": "1.15.0",
"version": "1.16.0",
"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": "1.15.0",
"version": "1.16.0",
"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": "1.15.0",
"version": "1.16.0",
"description": "Node.js bindings for Rust code required by the Iron Fish SDK",
"main": "index.js",
"types": "index.d.ts",
Expand Down
33 changes: 21 additions & 12 deletions ironfish-rust-nodejs/src/frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,47 @@ use crate::{
structs::{IdentiferKeyPackage, TrustedDealerKeyPackages},
to_napi_err,
};
use ironfish::keys::ProofGenerationKeySerializable;
use ironfish::{
frost::{keys::KeyPackage, round2::Randomizer, Identifier, SigningPackage},
frost_utils::split_spender_key::split_spender_key,
frost_utils::{round_one::round_one as round_one_rust, round_two::round_two as round_two_rust},
frost_utils::{
signing_commitment::create_signing_commitment as create_signing_commitment_rust,
signing_share::create_signing_share as create_signing_share_rust,
},
participant::{Identity, Secret},
serializing::{bytes_to_hex, hex_to_bytes, hex_to_vec_bytes},
serializing::{bytes_to_hex, fr::FrSerializable, hex_to_bytes, hex_to_vec_bytes},
SaplingKey,
};
use napi::{bindgen_prelude::*, JsBuffer};
use napi_derive::napi;
use rand::thread_rng;

#[napi(object, js_name = "SigningCommitments")]
pub struct NativeSigningCommitments {
#[napi(object, js_name = "Commitment")]
pub struct NativeCommitment {
pub hiding: String,
pub binding: String,
}

#[napi(object, js_name = "IdentifierCommitment")]
pub struct NativeIdentifierCommitment {
pub identifier: String,
pub commitment: NativeCommitment,
}

#[napi]
pub fn round_one(key_package: String, seed: u32) -> Result<NativeSigningCommitments> {
pub fn create_signing_commitment(key_package: String, seed: u32) -> Result<NativeCommitment> {
let key_package =
KeyPackage::deserialize(&hex_to_vec_bytes(&key_package).map_err(to_napi_err)?)
.map_err(to_napi_err)?;
let (_, commitment) = round_one_rust(&key_package, seed as u64);
Ok(NativeSigningCommitments {
let (_, commitment) = create_signing_commitment_rust(&key_package, seed as u64);
Ok(NativeCommitment {
hiding: bytes_to_hex(&commitment.hiding().serialize()),
binding: bytes_to_hex(&commitment.binding().serialize()),
})
}

#[napi]
pub fn round_two(
pub fn create_signing_share(
signing_package: String,
key_package: String,
public_key_randomness: String,
Expand All @@ -54,8 +62,9 @@ pub fn round_two(
Randomizer::deserialize(&hex_to_bytes(&public_key_randomness).map_err(to_napi_err)?)
.map_err(to_napi_err)?;

let signature_share = round_two_rust(signing_package, key_package, randomizer, seed as u64)
.map_err(to_napi_err)?;
let signature_share =
create_signing_share_rust(signing_package, key_package, randomizer, seed as u64)
.map_err(to_napi_err)?;

Ok(bytes_to_hex(&signature_share.serialize()))
}
Expand Down Expand Up @@ -167,7 +176,7 @@ pub fn split_secret(

Ok(TrustedDealerKeyPackages {
verifying_key: bytes_to_hex(&t.verifying_key),
proof_generation_key: t.proof_generation_key.hex_key(),
proof_authorizing_key: t.proof_authorizing_key.hex_key(),
view_key: t.view_key.hex_key(),
incoming_view_key: t.incoming_view_key.hex_key(),
outgoing_view_key: t.outgoing_view_key.hex_key(),
Expand Down
32 changes: 25 additions & 7 deletions ironfish-rust-nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::fmt::Display;

use ironfish::keys::Language;
use ironfish::keys::ProofGenerationKeySerializable;
use ironfish::serializing::bytes_to_hex;
use ironfish::PublicAddress;
use ironfish::SaplingKey;

Expand Down Expand Up @@ -65,7 +65,7 @@ pub struct Key {
pub incoming_view_key: String,
pub outgoing_view_key: String,
pub public_address: String,
pub proof_generation_key: String,
pub proof_authorizing_key: String,
}

#[napi]
Expand All @@ -78,7 +78,9 @@ pub fn generate_key() -> Key {
incoming_view_key: sapling_key.incoming_view_key().hex_key(),
outgoing_view_key: sapling_key.outgoing_view_key().hex_key(),
public_address: sapling_key.public_address().hex_public_address(),
proof_generation_key: sapling_key.sapling_proof_generation_key().hex_key(),
proof_authorizing_key: bytes_to_hex(
&sapling_key.sapling_proof_generation_key().nsk.to_bytes(),
),
}
}

Expand All @@ -105,7 +107,9 @@ pub fn generate_key_from_private_key(private_key: String) -> Result<Key> {
incoming_view_key: sapling_key.incoming_view_key().hex_key(),
outgoing_view_key: sapling_key.outgoing_view_key().hex_key(),
public_address: sapling_key.public_address().hex_public_address(),
proof_generation_key: sapling_key.sapling_proof_generation_key().hex_key(),
proof_authorizing_key: bytes_to_hex(
&sapling_key.sapling_proof_generation_key().nsk.to_bytes(),
),
})
}

Expand All @@ -127,20 +131,34 @@ pub struct ThreadPoolHandler {
#[napi]
impl ThreadPoolHandler {
#[napi(constructor)]
pub fn new(thread_count: u32, batch_size: u32, pause_on_success: bool) -> Self {
pub fn new(
thread_count: u32,
batch_size: u32,
pause_on_success: bool,
use_fish_hash: bool,
fish_hash_full_context: bool,
) -> Self {
ThreadPoolHandler {
threadpool: mining::threadpool::ThreadPool::new(
thread_count as usize,
batch_size,
pause_on_success,
use_fish_hash,
fish_hash_full_context,
),
}
}

#[napi]
pub fn new_work(&mut self, header_bytes: Buffer, target: Buffer, mining_request_id: u32) {
pub fn new_work(
&mut self,
header_bytes: Buffer,
target: Buffer,
mining_request_id: u32,
fish_hash: bool,
) {
self.threadpool
.new_work(&header_bytes, &target, mining_request_id)
.new_work(&header_bytes, &target, mining_request_id, fish_hash)
}

#[napi]
Expand Down
2 changes: 1 addition & 1 deletion ironfish-rust-nodejs/src/structs/key_packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct IdentiferKeyPackage {

pub struct TrustedDealerKeyPackages {
pub verifying_key: String,
pub proof_generation_key: String,
pub proof_authorizing_key: String,
pub view_key: String,
pub incoming_view_key: String,
pub outgoing_view_key: String,
Expand Down
Loading

0 comments on commit 4fab80d

Please sign in to comment.