Skip to content

Commit

Permalink
Reenable test on simulator private-execution
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Feb 29, 2024
1 parent 350fe4b commit cbc257e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
19 changes: 16 additions & 3 deletions noir-projects/noir-contracts/contracts/test_contract/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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;
Expand All @@ -33,6 +34,7 @@ contract Test {

struct Storage {
example_constant: PrivateImmutable<FieldNote>,
example_set: PrivateSet<FieldNote>,
}

// TODO(@spalladino): Delete all empty constructors
Expand Down Expand Up @@ -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
Expand Down
28 changes: 5 additions & 23 deletions yarn-project/simulator/src/client/private_execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -50,7 +45,6 @@ import {
PendingCommitmentsContractArtifact,
StatefulTestContractArtifact,
TestContractArtifact,
TokenContractArtifact,
} from '@aztec/noir-contracts.js';

import { jest } from '@jest/globals';
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -831,7 +814,6 @@ describe('Private Execution test suite', () => {
);

expect(readRequests).toHaveLength(1);
expect(readRequests[0]).toEqual(siloedNoteHash);
});
});

Expand Down

0 comments on commit cbc257e

Please sign in to comment.