Skip to content

Commit

Permalink
feat: Migrate the init kernel CPP tests to noir (#3091)
Browse files Browse the repository at this point in the history
Please provide a paragraph or two giving a summary of the change,
including relevant motivation and context.

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [ ] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [ ] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [ ] Every change is related to the PR description.
- [ ] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to relevant issues (if any exist).
  • Loading branch information
sirasistant authored Oct 27, 2023
1 parent ebda5fc commit 906429f
Show file tree
Hide file tree
Showing 13 changed files with 9,810 additions and 3 deletions.
5 changes: 5 additions & 0 deletions yarn-project/noir-private-kernel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"formatting:fix": "run -T prettier -w ./src",
"noir:build": "cd src && nargo compile --no-backend && rm -rf ./target/debug_*",
"noir:types": "yarn ts-node --esm src/scripts/generate_ts_from_abi.ts",
"noir:test": "cd src && nargo test",
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests"
},
"inherits": [
Expand All @@ -38,11 +39,15 @@
"tslib": "^2.4.0"
},
"devDependencies": {
"@aztec/merkle-tree": "workspace:^",
"@aztec/types": "workspace:^",
"@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",
"levelup": "^5.1.1",
"memdown": "^6.1.1",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
Expand Down
4,399 changes: 4,399 additions & 0 deletions yarn-project/noir-private-kernel/src/__snapshots__/noir_test_gen.test.ts.snap

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ mod private_kernel_init;
mod private_kernel_inner;
mod private_kernel_ordering;

mod tests;

use abis::kernel_circuit_public_inputs::{ KernelCircuitPublicInputs, KernelCircuitPublicInputsFinal };
use private_kernel_init::PrivateKernelInputsInit;
use private_kernel_inner::PrivateKernelInputsInner;
use private_kernel_ordering::PrivateKernelInputsOrdering;

// Hmm
// PrivateCircuitPublicInputs vs CombinedAccumulatedData (Duplicated fields)
// ?Que es la diferencia entre contract_address y storage_address?

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod testing_harness;
mod apps;
mod read_requests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod deposit;
mod constructor;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::{
abis::private_circuit_public_inputs::PrivateCircuitPublicInputs,
tests::testing_harness::{PrivateCircuitPublicInputsBuilder, PrivateAppInputs},
utils::uint128::U128,
hash::NUM_FIELDS_PER_SHA256,
};

struct ConstructorParams {}

pub fn constructor_app(inputs: PrivateAppInputs, params: ConstructorParams) -> PrivateCircuitPublicInputs {
PrivateCircuitPublicInputsBuilder::new(inputs).finish()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::{
abis::private_circuit_public_inputs::PrivateCircuitPublicInputs,
tests::testing_harness::{PrivateCircuitPublicInputsBuilder, PrivateAppInputs},
utils::uint128::U128,
hash::NUM_FIELDS_PER_SHA256,
};

global BALANCES_SLOT = 1;

struct DepositParams {
amount: Field,
asset_id: Field,
memo: Field,
encrypted_logs_hash : [U128; NUM_FIELDS_PER_SHA256],
unencrypted_logs_hash : [U128; NUM_FIELDS_PER_SHA256],
encrypted_log_preimages_length : Field,
unencrypted_log_preimages_length : Field,
}

pub fn deposit_app(inputs: PrivateAppInputs, params: DepositParams) -> PrivateCircuitPublicInputs {
let msg_sender = inputs.call_context.msg_sender;

let mut context = PrivateCircuitPublicInputsBuilder::new(inputs);


let user_balance_slot = dep::std::hash::pedersen_hash([BALANCES_SLOT, params.asset_id, msg_sender.to_field()]);

let commitment = dep::std::hash::pedersen_hash([user_balance_slot, params.amount, msg_sender.to_field(), params.memo]);

context.new_commitments.push(commitment);

context.encrypted_logs_hash = params.encrypted_logs_hash.map(|uint: U128| uint.to_field());
context.unencrypted_logs_hash = params.unencrypted_logs_hash.map(|uint: U128| uint.to_field());

context.encrypted_log_preimages_length = params.encrypted_log_preimages_length;
context.unencrypted_log_preimages_length = params.unencrypted_log_preimages_length;

context.finish()
}

Large diffs are not rendered by default.

Loading

0 comments on commit 906429f

Please sign in to comment.