Skip to content
Draft
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
804 changes: 496 additions & 308 deletions stealthdrop/bun.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions stealthdrop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
"packages/*"
],
"scripts": {
"dev": "bun run --elide-lines 0 --filter @stealthdrop/webapp dev",
"build": "bun run --elide-lines 0 --filter @stealthdrop/webapp build",
"preview": "bun run --elide-lines 0 --filter @stealthdrop/webapp preview",
"dev": "bun run --elide-lines=0 --filter @stealthdrop/webapp dev",
"build": "bun run --elide-lines=0 --filter @stealthdrop/webapp build",
"preview": "bun run --elide-lines=0 --filter @stealthdrop/webapp preview",
"node": "cd packages/ethereum && npx hardhat node",
"test": "bun run --elide-lines 0 --filter @stealthdrop/ethereum test",
"deploy": "bun run --elide-lines 0 --filter @stealthdrop/ethereum deploy",
"test": "bun run --elide-lines=0 --filter @stealthdrop/ethereum test",
"deploy": "bun run --elide-lines=0 --filter @stealthdrop/ethereum deploy",
"gen": "bun run utils/generateAddresses.ts"
},
"dependencies": {
"@aztec/bb.js": "0.67.0",
"@aztec/bb.js": "0.84.0",
"@nomicfoundation/hardhat-network-helpers": "1.0.12",
"@nomicfoundation/hardhat-toolbox-viem": "3.0.0",
"@nomicfoundation/hardhat-viem": "2.0.6",
"@zk-kit/lean-imt": "^2.2.2",
"hardhat": "^2.18.1",
"hardhat-gas-reporter": "^1.0.8",
"hardhat-plugin-noir": "0.3.0-next.0",
"hardhat-plugin-noir": "0.4.0",
"react": "^18.2.0",
"solidity-coverage": "^0.8.1",
"ts-node": "^10.9.1",
Expand Down
7 changes: 2 additions & 5 deletions stealthdrop/packages/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"deploy": "hardhat vars set holesky ${DEPLOYER_PK} && hardhat deploy --network holesky"
},
"dependencies": {
"@aztec/bb.js": "0.67.0",
"@noir-lang/noir_js": "1.0.0-beta.1",
"@aztec/bb.js": "0.84.0",
"@noir-lang/noir_js": "1.0.0-beta.6",
"@nomicfoundation/hardhat-toolbox-viem": "^3.0.0",
"@zk-kit/lean-imt": "^2.2.2",
"hardhat": "^2.18.1",
Expand All @@ -20,9 +20,6 @@
"chai": "^4.3.10",
"typescript": "^5.0.0"
},
"resolutions": {
"@aztec/bb.js": "0.67.0"
},
"trustedDependencies": [
"plume-sig"
]
Expand Down
6 changes: 3 additions & 3 deletions stealthdrop/packages/ethereum/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ProofData } from '@noir-lang/types';
import { expect } from 'chai';
import pkg from '../../const.cts';
const { MESSAGE_TO_HASH } = pkg;
import { computeAllInputs } from 'plume-sig';
import { curves } from 'plume-sig';
import { HardhatNetworkHDAccountsConfig } from 'hardhat/types';

const bbSync = await BarretenbergSync.new();
Expand Down Expand Up @@ -126,7 +126,7 @@ const getClaimInputs = async ({
// message to hash is above
const messageBytes = MESSAGE_TO_HASH.split('').map((s, i) => MESSAGE_TO_HASH.charCodeAt(i));
const privateKey = userAccount!.getHdKey().privateKey!;
const plume = await computeAllInputs(Uint8Array.from(messageBytes), privateKey);
const plume = await curves.secp256k1.computeAllInputs(Uint8Array.from(messageBytes), privateKey);

const proof = merkleTree.generateProof(index);
const pubKey = userAccount!.publicKey.slice(2);
Expand Down Expand Up @@ -154,7 +154,7 @@ const getClaimInputs = async ({
describe('Eligible user', () => {
let proof: ProofData;

it('Generates a valid claim - off-chain', async () => {
it.only('Generates a valid claim - off-chain', async () => {
const merkleTree = LeanIMT.import(poseidon, primedMerkleTree.export());
merkleTree.update(0, BigInt(user0.account!.address));

Expand Down
2 changes: 1 addition & 1 deletion stealthdrop/packages/hardhat.config.cts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const config: HardhatUserConfig = {
noir: './noir',
},
noir: {
version: '1.0.0-beta.1',
version: '1.0.0-beta.6'
},
mocha: {
timeout: 1000000,
Expand Down
12 changes: 5 additions & 7 deletions stealthdrop/packages/noir/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ authors = [""]

[dependencies]
trees = { git = "https://github.com/privacy-scaling-explorations/zk-kit.noir", tag = "main", directory = "packages/merkle-trees" }
ecrecover = { tag = "main", git = "https://github.com/colinnielsen/ecrecover-noir" }
# plume = { tag = "main", git = "https://github.com/signorecello/zk-nullifier-sig", directory = "circuits/noir/plume" }
noir_bigcurve = { tag = "zkpedro/for_plume", git = "https://github.com/noir-lang/noir_bigcurve" }
bignum = { tag = "main", git = "https://github.com/noir-lang/noir-bignum" }
nodash = { tag = "main", git = "https://github.com/olehmisar/nodash" }

plume = { path = "../../../zk-nullifier-sig/circuits/noir" }
plume = { tag = "main", git = "https://github.com/signorecello/zk-nullifier-sig", directory = "circuits/noir" }
noir_bigcurve = { tag = "v0.9.0", git = "https://github.com/noir-lang/noir_bigcurve" }
bignum = { tag = "v0.7.3", git = "https://github.com/noir-lang/noir-bignum" }
array_helpers = { tag = "v0.30.0", git = "https://github.com/colinnielsen/noir-array-helpers" }
keccak256 = { tag = "v0.1.0", git = "https://github.com/noir-lang/keccak256" }
44 changes: 30 additions & 14 deletions stealthdrop/packages/noir/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
use ecrecover::secp256k1::PubKey;
use noir_bigcurve::curves::secp256k1::{Secp256k1, Secp256k1Fq, Secp256k1Scalar};
use noir_bigcurve::scalar_field::ScalarField;
use noir_bigcurve::curves::secp256k1::{Secp256k1, Secp256k1_Fq, Secp256k1Scalar};
use noir_bigcurve::scalar_field::{ScalarField, ScalarFieldTrait};

use array_helpers::u8_32_to_u8_64;
// use plume::plume_v2;
use plume::Plume;
use bignum::BigNum;
use plume::{Plume, PlumeVerifier};
use plume::curves::secp256k1::hash_to_curve;
use std::hash::poseidon2::Poseidon2::hash;
use trees::merkle::MerkleTree;
use trees::types::{MembershipProver, MT_Creator};
use keccak256::keccak256;

type BN = Secp256k1Fq;
global DEPTH: u32 = 12;


fn to_eth_address(pub_key_x: [u8; 32], pub_key_y: [u8; 32]) -> Field {
let pub_key = array_helpers::u8_32_to_u8_64(pub_key_x, pub_key_y);
let hashed_pub_key = keccak256(pub_key, 64);

let mut addr: Field = 0;
for i in 0..20 {
// shift left by 8 and add the new value
addr = (addr * 256) + hashed_pub_key[i + 12] as Field;
}

addr
}

fn hasher(leaves: [Field; 2]) -> Field {
hash(leaves, 2)
}
Expand All @@ -27,29 +44,28 @@ fn main(
eligible_index: Field,
claimer_priv: Field,
) -> pub Field {
let c_bn = Secp256k1Fq::from_be_bytes(c);
let c_bn = Secp256k1_Fq::from_be_bytes(c);
let scalar_c: Secp256k1Scalar = ScalarField::from_bignum(c_bn);

let s_bn = Secp256k1Fq::from_be_bytes(s);
let s_bn = Secp256k1_Fq::from_be_bytes(s);
let scalar_s: Secp256k1Scalar = ScalarField::from_bignum(s_bn);

let pubkey_bg = Secp256k1 {
x: Secp256k1Fq::from_be_bytes(pub_key_x),
y: Secp256k1Fq::from_be_bytes(pub_key_y),
x: Secp256k1_Fq::from_be_bytes(pub_key_x),
y: Secp256k1_Fq::from_be_bytes(pub_key_y),
is_infinity: false,
};

let nullifier = Secp256k1 {
x: Secp256k1Fq::from_be_bytes(nullifier_x),
y: Secp256k1Fq::from_be_bytes(nullifier_y),
x: Secp256k1_Fq::from_be_bytes(nullifier_x),
y: Secp256k1_Fq::from_be_bytes(nullifier_y),
is_infinity: false,
};

let plume = Plume::new(message, scalar_c, scalar_s, pubkey_bg, nullifier);
let plume = Plume::new(message, scalar_c, scalar_s, pubkey_bg, nullifier, hash_to_curve);

let (_, _) = plume.plume_v2();
let pubkey = PubKey::from_xy(pub_key_x, pub_key_y);
let address = pubkey.to_eth_address();
let address = to_eth_address(pub_key_x, pub_key_y);

let mut mt = MerkleTree::from(eligible_root, hasher);
mt.membership(address, eligible_index, eligible_path);
Expand Down
2 changes: 1 addition & 1 deletion stealthdrop/packages/noir/target/stealthdrop.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions stealthdrop/packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"gen": "bun run utils/mt/generateAddresses.ts"
},
"dependencies": {
"@aztec/bb.js": "0.67.0",
"@noir-lang/noir_js": "1.0.0-beta.1",
"@aztec/bb.js": "0.84.0",
"@noir-lang/noir_js": "1.0.0-beta.6",
"@nomicfoundation/hardhat-network-helpers": "1.0.12",
"@nomicfoundation/hardhat-toolbox-viem": "3.0.0",
"@nomicfoundation/hardhat-viem": "2.0.6",
Expand Down
4 changes: 2 additions & 2 deletions stealthdrop/packages/vite/src/hooks/usePlume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export function usePlume() {
MESSAGE_TO_HASH.charCodeAt(i),
);

const { computeAllInputs } = await import('plume-sig');
const plume = await computeAllInputs(Uint8Array.from(messageBytes), privateKey);
const { curves } = await import('plume-sig');
const plume = await curves.secp256k1.computeAllInputs(Uint8Array.from(messageBytes), privateKey);

setPlume({
nullifier: plume.nullifier,
Expand Down
9 changes: 0 additions & 9 deletions stealthdrop/packages/vite/src/hooks/useProver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ export type ProofData = {
proof: Uint8Array;
};

// @ts-ignore
import acvm from '@noir-lang/acvm_js/web/acvm_js_bg.wasm?url';
// @ts-ignore
import noirc from '@noir-lang/noirc_abi/web/noirc_abi_wasm_bg.wasm?url';
import initNoirC from '@noir-lang/noirc_abi';
import initACVM from '@noir-lang/acvm_js';

export function useProver() {
const [proof, setProof] = useState<ProofData>();
Expand All @@ -26,9 +20,6 @@ export function useProver() {
setStatus('executing');
const stealthdropCircuit = await import('../../../noir/target/stealthdrop.json');

// @ts-ignore
await Promise.all([initACVM(fetch(acvm)), initNoirC(fetch(noirc))]);

const { UltraHonkBackend } = await import('@aztec/bb.js');

// @ts-ignore
Expand Down
21 changes: 20 additions & 1 deletion stealthdrop/packages/vite/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfig } from 'vite';
import { defineConfig, searchForWorkspaceRoot } from 'vite';
import react from '@vitejs/plugin-react-swc';

import tailwindcss from '@tailwindcss/vite';
Expand All @@ -7,6 +7,21 @@ export default defineConfig({
plugins: [react(), tailwindcss()],
server: {
allowedHosts: true,
// Headers needed for bb WASM to work in multithreaded mode
headers: {
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
},
// Allow vite to serve files from these directories, since they are symlinked
// These are the protocol circuit artifacts and noir/bb WASMs.
// ONLY REQUIRED TO RUN FROM THE MONOREPO
fs: {
allow: [
searchForWorkspaceRoot(process.cwd()),
"../../node_modules/@noir-lang/noirc_abi/web",
"../../node_modules/@noir-lang/acvm_js/web",
],
},
Comment on lines +18 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this is required

},
build: {
target: 'esnext',
Expand All @@ -23,5 +38,9 @@ export default defineConfig({
esbuildOptions: {
target: 'esnext',
},
// Exclude WASM packages from optimization to avoid MIME type issues
exclude: ['@noir-lang/noirc_abi', '@noir-lang/acvm_js', '@aztec/bb.js'],
},
// Ensure WASM files are served with correct MIME type
assetsInclude: ['**/*.wasm'],
});