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 31 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: 1 addition & 1 deletion circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ TEST(abi_tests, hash_constructor)

// Calculate the expected hash in-test
NT::fr const expected_hash =
NT::compress({ func_data.hash(), args_hash, constructor_vk_hash }, aztec3::GeneratorIndex::CONSTRUCTOR);
NT::hash({ func_data.hash(), args_hash, constructor_vk_hash }, aztec3::GeneratorIndex::CONSTRUCTOR);

// Confirm cbind output == expected hash
EXPECT_EQ(got_hash, expected_hash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ template <typename NCT> struct FunctionLeafPreimage {
std::vector<fr> const inputs = {
selector.value, fr(is_internal), fr(is_private), vk_hash, acir_hash,
};
return NCT::compress(inputs, GeneratorIndex::FUNCTION_LEAF);
return NCT::hash(inputs, GeneratorIndex::FUNCTION_LEAF);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ template <typename NCT> struct NewContractData {
fr(function_tree_root),
};

return NCT::compress(inputs, GeneratorIndex::CONTRACT_LEAF);
return NCT::hash(inputs, GeneratorIndex::CONTRACT_LEAF);
}

void conditional_select(const boolean& condition, const NewContractData<NCT>& other)
Expand Down
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 @@ -131,6 +131,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 @@ -168,6 +169,7 @@ struct GeneratorIndexPacker {
SIGNED_TX_REQUEST,
GLOBAL_VARIABLES,
PARTIAL_ADDRESS,
BLOCK_HASH,
TX_REQUEST,
SIGNATURE_PAYLOAD,
VK,
Expand Down
2 changes: 1 addition & 1 deletion circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ template <typename NCT> struct PublicDataRead {
value,
};

return NCT::compress(inputs, GeneratorIndex::PUBLIC_DATA_READ);
return NCT::hash(inputs, GeneratorIndex::PUBLIC_DATA_READ);
}

void set_public()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ template <typename NCT> struct PublicDataUpdateRequest {
new_value,
};

return NCT::compress(inputs, GeneratorIndex::PUBLIC_DATA_UPDATE_REQUEST);
return NCT::hash(inputs, GeneratorIndex::PUBLIC_DATA_UPDATE_REQUEST);
}

void set_public()
Expand Down
2 changes: 1 addition & 1 deletion circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ template <typename NCT> struct TxContext {
version,
};

return NCT::compress(inputs, GeneratorIndex::TX_CONTEXT);
return NCT::hash(inputs, GeneratorIndex::TX_CONTEXT);
}
};

Expand Down
2 changes: 1 addition & 1 deletion circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ template <typename NCT> struct TxRequest {
inputs.push_back(args_hash);
inputs.push_back(tx_context.hash());

return NCT::compress(inputs, GeneratorIndex::TX_REQUEST);
return NCT::hash(inputs, GeneratorIndex::TX_REQUEST);
}
};

Expand Down
8 changes: 4 additions & 4 deletions circuits/cpp/src/aztec3/circuits/hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ template <typename NCT> typename NCT::fr compute_constructor_hash(FunctionData<N
constructor_vk_hash,
};

return NCT::compress(inputs, aztec3::GeneratorIndex::CONSTRUCTOR);
return NCT::hash(inputs, aztec3::GeneratorIndex::CONSTRUCTOR);
}

template <typename NCT> typename NCT::fr compute_partial_address(typename NCT::fr const& contract_address_salt,
Expand Down Expand Up @@ -122,7 +122,7 @@ typename NCT::fr silo_nullifier(typename NCT::address const& contract_address, t
};

// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1475): use hash here (everywhere?)
return NCT::compress(inputs, aztec3::GeneratorIndex::OUTER_NULLIFIER);
return NCT::hash(inputs, aztec3::GeneratorIndex::OUTER_NULLIFIER);
}


Expand All @@ -140,7 +140,7 @@ template <typename NCT> typename NCT::fr compute_block_hash(typename NCT::fr con
contract_tree_root, l1_to_l2_data_tree_root, public_data_tree_root,
};

return NCT::compress(inputs, aztec3::GeneratorIndex::BLOCK_HASH);
return NCT::hash(inputs, aztec3::GeneratorIndex::BLOCK_HASH);
}

template <typename NCT>
Expand All @@ -158,7 +158,7 @@ typename NCT::fr compute_block_hash_with_globals(abis::GlobalVariables<NCT> cons
contract_tree_root, l1_to_l2_data_tree_root, public_data_tree_root,
};

return NCT::compress(inputs, aztec3::GeneratorIndex::BLOCK_HASH);
return NCT::hash(inputs, aztec3::GeneratorIndex::BLOCK_HASH);
}

template <typename NCT> typename NCT::fr compute_globals_hash(abis::GlobalVariables<NCT> const& globals)
Expand Down
2 changes: 1 addition & 1 deletion circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ TEST_F(base_rollup_tests, native_contract_leaf_inserted_in_non_empty_snapshot_tr
inputs.new_contracts_subtree_sibling_path = sibling_path;

// create expected end contract tree snapshot
auto expected_contract_leaf = crypto::pedersen_commitment::compress_native(
auto expected_contract_leaf = crypto::pedersen_commitment::lookup::compress_native(
{ new_contract.contract_address, new_contract.portal_contract_address, new_contract.function_tree_root },
GeneratorIndex::CONTRACT_LEAF);

Expand Down
38 changes: 38 additions & 0 deletions circuits/cpp/src/aztec3/utils/array.test.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#include "array.hpp"

#include "aztec3/circuits/hash.hpp"
#include "aztec3/utils/dummy_circuit_builder.hpp"

#include <gtest/gtest.h>

#include <array>
#include <cstddef>
#include <cstdint>
#include <sstream>
#include <string>

namespace aztec3::utils {
Expand All @@ -22,6 +25,41 @@ void rearrange_and_check(std::array<fr, N>& input, std::array<fr, N> const& expe
}
};

TEST(hash_tests, noir_l2_l1_interop_hashing)
{
// This is an annoying hack to convert the field into a hex string
// We should add a to_hex and from_hex method to field class
auto to_hex = [](const NT::fr& value) -> std::string {
std::stringstream field_as_hex_stream;
field_as_hex_stream << value;
return field_as_hex_stream.str();
};

// All zeroes case
auto address = NT::address(0);
auto res = circuits::compute_l2_to_l1_hash<NT>(address, fr(0), fr(0), fr(0), fr(0));
auto res_as_hex = to_hex(res);
ASSERT_EQ(res_as_hex, "0x2266ac2f9f0c19c015239ef5ea85862fc6fac00db73779b220a4d49c4856c2e1");

// Non-zero case
address = NT::address(1);
res = circuits::compute_l2_to_l1_hash<NT>(address, fr(2), fr(3), fr(4), fr(5));
res_as_hex = to_hex(res);
ASSERT_EQ(res_as_hex, "0x0f24729168d4450a5681beafa5e3a899ac28bd17bf5a4877dab37bcd834e1634");

// Smoke test that sha256_to_field is also the same in Noir
// For an l2_to_l1 hash the maximum size of the buffer that will be sha256'd is 160 bytes
size_t max_buffer_size = 160;
std::vector<uint8_t> buffer(max_buffer_size); // Creating a vector of size 160
for (size_t i = 0; i < 160; ++i) {
buffer[i] = static_cast<uint8_t>(i);
}

res = sha256::sha256_to_field(buffer);
res_as_hex = to_hex(res);
ASSERT_EQ(res_as_hex, "0x142a6d57007171f6eaa33d55976d9dbe739c889c8e920f115f7808dea184c718");
}

TEST(utils_array_tests, rearrange_test_vector1)
{
std::array<fr, 5> test_vec{ fr(2), fr(4), fr(0), fr(12), fr(0) };
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 @@ -102,6 +102,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
70 changes: 35 additions & 35 deletions yarn-project/circuits.js/src/abis/__snapshots__/abis.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ CompleteAddress {

exports[`abis wasm bindings computes a function leaf 1`] = `
Fr {
"value": 16977277925454205296890617263907769463254781689473762721237698889614686866498n,
"value": 11464606379677897655841837765481150958925254400943302278940297281867381781406n,
}
`;

Expand All @@ -82,13 +82,13 @@ Fr {

exports[`abis wasm bindings computes contract leaf 1`] = `
Fr {
"value": 14753252017424563237038015065402454919037294146339173328174383872613705551896n,
"value": 4215437441630701912471521208281831379118238768967605324016661064011479515427n,
}
`;

exports[`abis wasm bindings computes function tree root 1`] = `
Fr {
"value": 10347099364184817470749359182712341488544005132594679915946302065868679911885n,
"value": 6913428931557499069967495171242326455519902431197956487857751337970681394459n,
}
`;

Expand All @@ -100,7 +100,7 @@ Fr {

exports[`abis wasm bindings computes siloed nullifier 1`] = `
Fr {
"value": 4957445512951137590281746823314455197982530036508465893793736233926551006579n,
"value": 18523829990807403875392701649621519624514099923446053518613884494755019137311n,
}
`;

Expand Down Expand Up @@ -153,46 +153,46 @@ exports[`abis wasm bindings hashes VK 1`] = `
exports[`abis wasm bindings hashes a tx request 1`] = `
{
"data": [
32,
25,
83,
68,
20,
2,
71,
30,
241,
52,
99,
157,
202,
119,
186,
154,
22,
122,
199,
176,
121,
16,
203,
183,
91,
212,
69,
118,
215,
85,
13,
228,
82,
129,
89,
153,
16,
156,
209,
239,
77,
6,
1,
196,
110,
152,
176,
110,
97,
68,
38,
190,
149,
170,
169,
131,
233,
177,
68,
140,
237,
237,
],
"type": "Buffer",
}
`;

exports[`abis wasm bindings hashes constructor info 1`] = `
Fr {
"value": 11423915673915198290300367851881125996395433281184245872633888457016608552774n,
"value": 16807036221916272668165173999731456176118187870505447532689806512445943708574n,
}
`;

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 @@ -104,6 +104,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
7 changes: 7 additions & 0 deletions yarn-project/circuits.js/src/structs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ export * from '@aztec/foundation/eth-address';
export * from '@aztec/foundation/fields';
export * from '@aztec/foundation/aztec-address';
export { FunctionSelector } from '@aztec/foundation/abi';

// TODO(Kev): This is only exported so that tests in noir-private-kernel
// do not need to manually initialize their instance.
// This is not great as we are exporting from tests.
// Its okay for now and before merging into master, we should
// remove this line.
export * from '../tests/factories.js';
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ describe('benchmarks/publish_rollup', () => {
await pxe.stop();
await node.stop();
},
10 * 60_000,
10 * 70_000,
);
});
10 changes: 5 additions & 5 deletions yarn-project/end-to-end/src/e2e_deploy_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('e2e_deploy_contract', () => {
const contractAddress = receiptAfterMined.contractAddress!;
expect(await isContractDeployed(pxe, contractAddress)).toBe(true);
expect(await isContractDeployed(pxe, AztecAddress.random())).toBe(false);
}, 30_000);
}, 60_000);

/**
* Verify that we can produce multiple rollups.
Expand All @@ -68,7 +68,7 @@ describe('e2e_deploy_contract', () => {
const receipt = await tx.getReceipt();
expect(receipt.status).toBe(TxStatus.MINED);
}
}, 30_000);
}, 60_000);

/**
* Verify that we can deploy multiple contracts and interact with all of them.
Expand All @@ -84,7 +84,7 @@ describe('e2e_deploy_contract', () => {
logger(`Sending TX to contract ${index + 1}...`);
await contract.methods.get_public_key(accounts[0].address).send().wait();
}
}, 30_000);
}, 60_000);

/**
* Milestone 1.2.
Expand All @@ -110,7 +110,7 @@ describe('e2e_deploy_contract', () => {
/A settled tx with equal hash/,
);
}
}, 30_000);
}, 60_000);

it('should deploy a contract connected to a portal contract', async () => {
const deployer = new ContractDeployer(TestContractArtifact, wallet);
Expand All @@ -127,5 +127,5 @@ describe('e2e_deploy_contract', () => {
expect((await pxe.getExtendedContractData(contractAddress))?.contractData.portalContractAddress.toString()).toEqual(
portalContract.toString(),
);
});
}, 60_000);
});
8 changes: 4 additions & 4 deletions yarn-project/end-to-end/src/guides/up_quick_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
set -eux

# docs:start:declare-accounts
ALICE="0x25048e8c1b7dea68053d597ac2d920637c99523651edfb123d0632da785970d0"
BOB="0x115f123bbc6cc6af9890055821cfba23a7c4e8832377a32ccb719a1ba3a86483"
ALICE="0x281a2587d4bdf11a12bfb0c92d30060910b7ff5d882f67ce27519865db1c1881"
BOB="0x2b2794e0d7fd2dffb64fac6ec81669cdeb47f2b116ffeeaa76c731fe83aa9592"
ALICE_PRIVATE_KEY="0x2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281"
# docs:end:declare-accounts

Expand All @@ -15,9 +15,9 @@ aztec-cli deploy \
--salt 0 \
--args $ALICE

aztec-cli check-deploy --contract-address 0x2219e810bff6e04abdefce9f91c2d1dd1e4d52fafa602def3c90b77f4331feca
aztec-cli check-deploy --contract-address 0x24af0b78e803c66d36284dec93e6b64048e0fcad8fdf2ca99503e3b1c39dcde7

CONTRACT="0x2219e810bff6e04abdefce9f91c2d1dd1e4d52fafa602def3c90b77f4331feca"
CONTRACT="0x24af0b78e803c66d36284dec93e6b64048e0fcad8fdf2ca99503e3b1c39dcde7"
# docs:end:deploy

# docs:start:mint-private
Expand Down
Loading