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

feat(feature_branch): Private Kernel Circuit #2740

Merged
merged 54 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
1ec82f1
add noir-private-kernel yarn member
kevaundray Oct 9, 2023
1faa513
add initial private kernel circuit implementation
kevaundray Oct 9, 2023
380bd94
move bugs/devex files out of noir project subfolder
kevaundray Oct 9, 2023
6896db8
feat: Use constants_gen for constants (#2742)
sirasistant Oct 9, 2023
a572645
chore: Add barebones executeCircuit method for init circuit (#2747)
kevaundray Oct 9, 2023
64590fa
chore: Workspace integration for the noir private kernel (#2753)
sirasistant Oct 10, 2023
71d543a
chore: Initial code to generate ts code from Noir ABI (#2750)
kevaundray Oct 10, 2023
d5a14eb
feat: convert params to noir types (Noir private kernel) (#2760)
sirasistant Oct 10, 2023
c6c8e4b
feat: Add return type parsing for noir private kernel circuit (#2762)
sirasistant Oct 10, 2023
de628ee
chore: Use Noir javascript packages to execute the private kernel cir…
kevaundray Oct 11, 2023
523d96a
chore: enable noir private kernel circuit init (#2781)
kevaundray Oct 11, 2023
9cb2063
fix: adding missing pieces for PKC in noir (#2782)
sirasistant Oct 11, 2023
9cb188d
make init have valid inputs
kevaundray Oct 14, 2023
14917f7
add read_request_root_from_siblings wrapper method
kevaundray Oct 14, 2023
26b92b1
BROKEN BROKEN NOIR BUG:
kevaundray Oct 14, 2023
554df95
BUG BUG BUG SIMPLIFIED
kevaundray Oct 14, 2023
4488ca1
WORKAROUND FOR BUG NOTED IN PREVIOUS COMMIT
kevaundray Oct 14, 2023
4f18be3
update comment about reexporting tests
kevaundray Oct 14, 2023
4c1b7b8
Add a from_u32 method for FunctionSelector
kevaundray Oct 14, 2023
bcc2b5c
add interop tests
kevaundray Oct 14, 2023
4e4fe98
uncomment code as bug has been committed
kevaundray Oct 14, 2023
f0e2be6
add l2_to_l1_hash interop tests
kevaundray Oct 14, 2023
362247b
chore: Change private-kernel init to use BoundedVec (#2800)
kevaundray Oct 18, 2023
9235015
fix: mismatch in hashing for block hash
sirasistant Oct 18, 2023
d186c33
fix: comment out membership checks and fixed the remaining issues (#2…
sirasistant Oct 18, 2023
01e16d7
Merge branch 'master' into feature_branch/private-kernel
sirasistant Oct 19, 2023
ba02adb
fix: update types for pending rr
sirasistant Oct 19, 2023
f310e2c
feat: inner private kernel in noir (#2931)
sirasistant Oct 19, 2023
79c61fb
Merge branch 'master' into feature_branch/private-kernel
sirasistant Oct 23, 2023
3c4282a
fix: rename private data tree after merge
sirasistant Oct 23, 2023
f1b938d
feat: Ordering circuit in noir (#2979)
sirasistant Oct 23, 2023
f494dd2
Merge branch 'master' into feature_branch/private-kernel
sirasistant Oct 25, 2023
e11a333
Merge branch 'master' into feature_branch/private-kernel
sirasistant Oct 25, 2023
c51ad01
feat: update to pedersen hash
sirasistant Oct 25, 2023
d460f9b
test: use snapshots
sirasistant Oct 25, 2023
1979116
test: bump timeouts
sirasistant Oct 25, 2023
ca7c408
test: fix block building test
sirasistant Oct 25, 2023
a3a8811
test: bump bench timeout further
sirasistant Oct 25, 2023
28ec608
fix: use pedersen for addr nullifier (#3027)
sirasistant Oct 25, 2023
e79724e
feat: uncomment read request membership check
sirasistant Oct 25, 2023
8ebdec5
feat: fix contract membership check (#3034)
sirasistant Oct 25, 2023
845c6bd
Merge branch 'master' into feature_branch/private-kernel
sirasistant Oct 25, 2023
b4aa42e
refactor: removed functions for bit decomposition
sirasistant Oct 25, 2023
c15c8d6
test: add smoke test for noir PKC
sirasistant Oct 26, 2023
cb245e7
Merge branch 'master' into feature_branch/private-kernel
sirasistant Oct 26, 2023
a491ab6
restore cpp kernel circuits
sirasistant Oct 26, 2023
c6f3c9b
chore: mock vks also in cpp
sirasistant Oct 26, 2023
ef78ae0
fix: revert vk hash changes
sirasistant Oct 26, 2023
6e029f1
refactor: cleaned up some todos and unused fns
sirasistant Oct 26, 2023
495bccc
chore: undo boxes changes
sirasistant Oct 26, 2023
cc3871f
Merge branch 'master' into feature_branch/private-kernel
sirasistant Oct 26, 2023
67f4fd4
Merge branch 'master' into feature_branch/private-kernel
sirasistant Oct 26, 2023
81a2aac
style: fix formatting from master
sirasistant Oct 26, 2023
b3aff3f
Merge branch 'master' into feature_branch/private-kernel
sirasistant Oct 27, 2023
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
2 changes: 2 additions & 0 deletions circuits/cpp/src/aztec3/circuits/abis/packers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ struct GeneratorIndexPacker {
int SIGNED_TX_REQUEST = GeneratorIndex::SIGNED_TX_REQUEST;
int GLOBAL_VARIABLES = GeneratorIndex::GLOBAL_VARIABLES;
int PARTIAL_ADDRESS = GeneratorIndex::PARTIAL_ADDRESS;
int BLOCK_HASH = GeneratorIndex::BLOCK_HASH;
int TX_REQUEST = GeneratorIndex::TX_REQUEST;
int SIGNATURE_PAYLOAD = GeneratorIndex::SIGNATURE_PAYLOAD;
int VK = GeneratorIndex::VK;
Expand Down Expand Up @@ -166,6 +167,7 @@ struct GeneratorIndexPacker {
SIGNED_TX_REQUEST,
GLOBAL_VARIABLES,
PARTIAL_ADDRESS,
BLOCK_HASH,
TX_REQUEST,
SIGNATURE_PAYLOAD,
VK,
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec-nr/aztec/src/constants_gen.nr
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ global GENERATOR_INDEX__PUBLIC_DATA_LEAF = 24;
global GENERATOR_INDEX__SIGNED_TX_REQUEST = 25;
global GENERATOR_INDEX__GLOBAL_VARIABLES = 26;
global GENERATOR_INDEX__PARTIAL_ADDRESS = 27;
global GENERATOR_INDEX__BLOCK_HASH = 28;
global GENERATOR_INDEX__TX_REQUEST = 33;
global GENERATOR_INDEX__SIGNATURE_PAYLOAD = 34;
global GENERATOR_INDEX__VK = 41;
Expand Down
1 change: 1 addition & 0 deletions yarn-project/circuits.js/src/cbind/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export enum GeneratorIndex {
SIGNED_TX_REQUEST = 25,
GLOBAL_VARIABLES = 26,
PARTIAL_ADDRESS = 27,
BLOCK_HASH = 28,
TX_REQUEST = 33,
SIGNATURE_PAYLOAD = 34,
VK = 41,
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/noir-compiler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export { generateNoirContractInterface } from './contract-interface-gen/noir.js'
export { generateTypescriptContractInterface } from './contract-interface-gen/typescript.js';
export { generateAztecAbi };

export * from './noir_artifact.js';

/**
* Compile Aztec.nr contracts in project path using a nargo binary available in the shell.
* @param projectPath - Path to project.
Expand Down
18 changes: 17 additions & 1 deletion yarn-project/noir-compiler/src/noir_artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ABIParameter, ABIType, DebugFileMap, DebugInfo } from '@aztec/foundatio
type NoirFunctionType = 'Open' | 'Secret' | 'Unconstrained';

/** The ABI of an Aztec.nr function. */
interface NoirFunctionAbi {
export interface NoirFunctionAbi {
/** The parameters of the function. */
parameters: ABIParameter[];
/** The witness indices of the parameters. Indexed by parameter name. */
Expand Down Expand Up @@ -47,6 +47,22 @@ export interface NoirCompiledContract {
functions: NoirFunctionEntry[];
}

/**
* The compilation result of an Aztec.nr contract.
*/
export interface NoirCompiledCircuit {
/** The hash of the circuit. */
hash: number;
/** Compilation backend. */
backend: string;
/**
* The ABI of the function.
*/
abi: NoirFunctionAbi;
/** The bytecode of the circuit in base64. */
bytecode: string;
}

/**
* The debug metadata of an Aztec.nr contract.
*/
Expand Down
1 change: 1 addition & 0 deletions yarn-project/noir-private-kernel/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@aztec/foundation/eslint');
3 changes: 3 additions & 0 deletions yarn-project/noir-private-kernel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
proofs/
Prover.toml
Verifier.toml
3 changes: 3 additions & 0 deletions yarn-project/noir-private-kernel/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src/crates
src/target
src/types
1 change: 1 addition & 0 deletions yarn-project/noir-private-kernel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Noir Private Kernel
Copy link
Contributor

Choose a reason for hiding this comment

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

sir!!

58 changes: 58 additions & 0 deletions yarn-project/noir-private-kernel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@aztec/noir-private-kernel",
"version": "0.1.0",
"type": "module",
"exports": {
".": "./dest/index.js",
"./types": "./dest/types/index.js"
},
"scripts": {
"build": "yarn clean && tsc -b",
"build:dev": "tsc -b --watch",
"clean": "rm -rf ./dest .tsbuildinfo",
"formatting": "run -T prettier --check ./src && run -T eslint ./src",
"formatting:fix": "run -T prettier -w ./src",
"noir:build": "cd src && nargo compile",
"noir:types": "yarn ts-node --esm src/scripts/generate_ts_from_abi.ts",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests"
},
"inherits": [
"../package.common.json"
],
"jest": {
"preset": "ts-jest/presets/default-esm",
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.m?js$": "$1"
},
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
"rootDir": "./src"
},
"dependencies": {
"@aztec/circuits.js": "workspace:^",
"@aztec/foundation": "workspace:^",
"@aztec/noir-compiler": "workspace:^",
"@noir-lang/acvm_js": "^0.28.0",
"@noir-lang/backend_barretenberg": "^0.7.10",
"@noir-lang/noir_js": "^0.16.0",
"tslib": "^2.4.0"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
"@rushstack/eslint-patch": "^1.1.4",
"@types/jest": "^29.5.0",
"@types/node": "^18.7.23",
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
},
"files": [
"dest",
"src",
"!*.test.*"
],
"types": "./dest/index.d.ts",
"engines": {
"node": ">=18"
}
}
7 changes: 7 additions & 0 deletions yarn-project/noir-private-kernel/src/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[workspace]
members = [
"crates/private-kernel-lib",
"crates/private-kernel-init",
"crates/private-kernel-ordering",
"crates/private-kernel-inner",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add a is_zero and is_one method to field for devex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
array.len() should return a u64
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
When an array is passed in, it is copied in and so if it is written to and not read from,
we should get an error saying:

array written to, but never read.

This may prompt the developer to change fn foo(x : [Field ; 2]) to fn foo(x : &mut [Field ; 2]) or to return it
fn foo(x : [Field ; 2]) -> [Field ;2]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
document parameters for to_le_bits and to_le_bytes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Could allow for u128 , but then just make it really slow
so u128 addition would be slow because internally the compiler will be
decomposing them.
Probably possible to just have a u128 struct or something of the kind
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Ability to template println and assert statements.

assert(foo == bar, "foo was equal to {}, but bar was equal to {}", foo, bar);

and:

fn foo(foo: Field, bar : Field, msg : string) {
assert(foo == bar, msg)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn foo() -> [Field ;2] {
[0,0]
}

Would be a nice devex to be able to do:

let [a, b] = foo();
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Santiago mentioned the ability to automatically deref an Address into a Field.

I believe I mentioned something like #[transparent]. The issue with this is
that you lose type safety, though perhaps its fine if you opt-in to it, and its
only usecase would be to make the part where you input values to the abi smoother.

Not a hard push on this, I just saw a forced usecase for this a minute ago.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
convert slice to array needs a for loop, not important but would be good to have
a method in stdlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Would be good to have #[test(ignore)]

to ignore the test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
fn main(){
// This compiles
let x : Foo<Field> = Foo {
x : 12
};

// TurboFish not allowed
let x = Foo::<Field> {
x : 12
};
}

struct Foo<N> {
x : N,
}

struct Bar {
x : FooField,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Would be cool if the error message included the type alias
// that they came from.
//
If I do use X as Y;
And I have an error when initializing Y. The error message speaks about X.
This is the same with Rust, whether we do it depends on the complexity it adds.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[abi(export)]
unconstrained fn abi__compute_hash() {

}

#[abi(export)]
unconstrained fn abi__compute_block_hash() {
abis::compute_hash()
}

The above allows us to export noir methods to be called from cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// This is here because x[index] = value is not working in Noir right now
// when x is &mut
fn noir_array_set<N>(x : &mut [Field; N], index : u64, value : Field) {
// x[index] = value;
}

error: Expected type an array, found type &mut [Field; N]
┌─ lib.nr:95:15
95 │ x[index] = value;
│ -----



// This is here because x[index] is not working in Noir right now
// when x is &mut
fn noir_array_get<N>(x : &mut [Field; N], index : u64) -> Field {
x[index]
}

error: Expected type Array, found type &mut [Field; N]
┌─ lib.nr:100:4
100 │ x[index]
│ -
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test(should_fail_with("array has reached maximum capacit"))]
fn smoke_test_array_push_capacity(){

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fn array_push_field<T>(mut array : &mut [Field; T], value_to_push : Field) {
let mut found_empty_slot = false;
for elem in array {
if (elem == 0) && (found_empty_slot == false) {
found_empty_slot = true;
*elem = value_to_push;
}
}
assert(found_empty_slot);
}

error: Variable elem must be mutable to be assigned to
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
util = { path = "../utils" }

If utils does not exist,

It will say:

Cannot read file /mnt/user-data/kev/private-kernel/pki/crates/util/Nargo.toml - does it exist?

It would be good if it also said which package is trying to access that file
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let num_bytes : Field = 64;

let input = [0;num_bytes];


error: Cannot find a global or generic type parameter named `plain::num_bytes`
┌─ hash.nr:163:20
163 │ let input = [0;num_bytes];
│ --------- Only globals or generic type parameters are allowed to be used as an array type's length
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
mod Foo {
struct NewType{}
}


mod Bar {
use crate::Foo::NewType as BarStruct;
use crate::Foo::NewType;
}

mod Baz {
use crate::Bar::BarStruct;
use crate::Bar::NewType;
}

// Baz is unable to find the Bar re-exports
// error: Could not resolve 'NewType' in path
// error: Could not resolve 'BarStruct' in path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
check re-exports to shorten use path
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

struct Foo<N> {
x : N,
}

type FooField = Foo<Field>;
type Foou32 = Foo<u32>;

// These two impls should work since the `hash1` implementations
// are in different "namespaces".
impl FooField {
fn hash1(self) {}
}
impl Foou32 {
fn hash1(self) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
struct Foo<N> {
x : N,
}

// Expected: constant provided when a type was expected
type FooField = Foo<12>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
If I have a println in a test and then an assert follows it.

I get constraint failed, though I do not get the println output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// missing typechain similar to aztec contract to ts stuff?
Loading