diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index 7212e0e9ed2..5bae443fe86 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -5,13 +5,14 @@ contract Test { abis::private_circuit_public_inputs::PrivateCircuitPublicInputs, address::{AztecAddress, EthAddress}, constants::{MAX_READ_REQUESTS_PER_CALL, MAX_NOTES_PER_PAGE}, hash::hash_args - }; + }; // docs:start:unencrypted_import use dep::aztec::log::emit_unencrypted_log; // docs:end:unencrypted_import use dep::aztec::{ - context::{Context, inputs::private_context_inputs::PrivateContextInputs}, hash::pedersen_hash, + context::{Context, inputs::private_context_inputs::PrivateContextInputs}, + hash::{pedersen_hash, compute_secret_hash}, context::PrivateContext, note::{ note_header::NoteHeader, utils as note_utils, lifecycle::{create_note, destroy_note}, @@ -20,7 +21,7 @@ contract Test { }, deploy::{deploy_contract as aztec_deploy_contract}, oracle::{get_public_key::get_public_key as get_public_key_oracle, context::get_portal_address, rand::rand}, - state_vars::PrivateImmutable, log::emit_unencrypted_log_from_private + state_vars::{PrivateImmutable, PrivateSet}, log::emit_unencrypted_log_from_private }; use dep::token_portal_content_hash_lib::{get_mint_private_content_hash, get_mint_public_content_hash}; use dep::field_note::field_note::FieldNote; @@ -33,6 +34,7 @@ contract Test { struct Storage { example_constant: PrivateImmutable, + example_set: PrivateSet, } // TODO(@spalladino): Delete all empty constructors @@ -356,6 +358,17 @@ contract Test { aztec_deploy_contract(&mut context, target); } + #[aztec(private)] + // Adapted from TokenContract#redeem_shield but without an initcheck so it can be run in simulator/src/client/private_execution.test.ts + fn consume_note_from_secret(secret: Field) { + let notes_set = storage.example_set; + let secret_hash = compute_secret_hash(secret); + let options = NoteGetterOptions::new().select(0, secret_hash, Option::none()).set_limit(1); + let notes = notes_set.get_notes(options); + let note = notes[0].unwrap_unchecked(); + notes_set.remove(note); + } + unconstrained fn get_constant() -> pub Field { let constant = storage.example_constant.view_note(); constant.value diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 3619434b346..157c50ec129 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -19,12 +19,7 @@ import { nonEmptySideEffects, sideEffectArrayToValueArray, } from '@aztec/circuits.js'; -import { - computeCommitmentNonce, - computeMessageSecretHash, - computeVarArgsHash, - siloNoteHash, -} from '@aztec/circuits.js/hash'; +import { computeCommitmentNonce, computeMessageSecretHash, computeVarArgsHash } from '@aztec/circuits.js/hash'; import { makeContractDeploymentData, makeHeader } from '@aztec/circuits.js/testing'; import { FunctionArtifact, @@ -50,7 +45,6 @@ import { PendingCommitmentsContractArtifact, StatefulTestContractArtifact, TestContractArtifact, - TokenContractArtifact, } from '@aztec/noir-contracts.js'; import { jest } from '@jest/globals'; @@ -787,20 +781,12 @@ describe('Private Execution test suite', () => { }); }); - // TODO(@spalladino): Reenable this test by migrating the redeem_shield to the test contract and removing the init check. - // Doing so is currently triggering a noir compiler error that I need to dig further into, so I'm skipping the test for now. - // 'internal error: entered unreachable code: TypeVariable::bind, cannot bind bound var 3 to 1' - it.skip('Should be able to consume a dummy public to private message', async () => { - const amount = 100n; - const artifact = getFunctionArtifact(TokenContractArtifact, 'redeem_shield'); - + it('Should be able to consume a dummy public to private message', async () => { + const artifact = getFunctionArtifact(TestContractArtifact, 'consume_note_from_secret'); const secret = new Fr(1n); const secretHash = computeMessageSecretHash(secret); - const note = new Note([new Fr(amount), secretHash]); - const noteHash = hashFields(note.items); + const note = new Note([secretHash]); const storageSlot = new Fr(5); - const innerNoteHash = hashFields([storageSlot, noteHash]); - const siloedNoteHash = siloNoteHash(contractAddress, innerNoteHash); oracle.getNotes.mockResolvedValue([ { contractAddress, @@ -813,10 +799,7 @@ describe('Private Execution test suite', () => { }, ]); - const result = await runSimulator({ - artifact, - args: [recipient, amount, secret], - }); + const result = await runSimulator({ artifact, args: [secret] }); // Check a nullifier has been inserted. const newNullifiers = sideEffectArrayToValueArray( @@ -831,7 +814,6 @@ describe('Private Execution test suite', () => { ); expect(readRequests).toHaveLength(1); - expect(readRequests[0]).toEqual(siloedNoteHash); }); });