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

refactor: purge secret and open keywords #6501

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ To summarize:
- _Public_ functions altering public state (updatable storage) must be executed at the current "head" of the chain, which only the sequencer can ensure, so these must be executed separately to the _private_ functions.
- _Private_ and _public_ functions within an Aztec transaction are therefore ordered such that first _private_ functions are executed, and then _public_.

A more comprehensive overview of the interplay between private and public functions and their ability to manipulate data is presented below. It is worth noting that all data reads performed by private functions are historical in nature, and that private functions are not capable of modifying public storage. Conversely, public functions have the capacity to manipulate private storage (e.g., inserting new note hashes, potentially as part of transferring funds from the public domain to the secret domain).
A more comprehensive overview of the interplay between private and public functions and their ability to manipulate data is presented below. It is worth noting that all data reads performed by private functions are historical in nature, and that private functions are not capable of modifying public storage. Conversely, public functions have the capacity to manipulate private storage (e.g., inserting new note hashes, potentially as part of transferring funds from the public domain to the private domain).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although secret domain is okay, I changed it here to have consistency with the rest.


<Image img={require("/img/com-abs-4.png")} />

Expand Down
8 changes: 4 additions & 4 deletions docs/docs/reference/smart_contract_reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The structure of a contract artifact is as follows:
"functions": [
{
"name": "constructor",
"functionType": "secret",
"functionType": "private",
"isInternal": false,
"parameters": [],
"returnTypes": [],
Expand All @@ -24,7 +24,7 @@ The structure of a contract artifact is as follows:
},
{
"name": "on_card_played",
"functionType": "open",
"functionType": "public",
"isInternal": true,
"parameters": [
{
Expand Down Expand Up @@ -75,8 +75,8 @@ A simple string that matches the name that the contract developer used for this
#### `function.functionType`
The function type can have one of the following values:

- Secret: The function is ran and proved locally by the clients, and its bytecode not published to the network.
- Open: The function is ran and proved by the sequencer, and its bytecode is published to the network.
- Private: The function is ran and proved locally by the clients, and its bytecode not published to the network.
- Public: The function is ran and proved by the sequencer, and its bytecode is published to the network.
- Unconstrained: The function is ran locally by the clients to generate digested information useful for the user. It's not meant to be transacted against.

#### `function.isInternal`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ contract ImportTest {
}

// Calls the emit_nullifier_public on the Test contract at the target address
// Used for testing calling an open function
// Used for testing calling a public function
// See yarn-project/end-to-end/src/e2e_nested_contract.test.ts
#[aztec(private)]
fn call_open_fn(target: AztecAddress) {
fn call_public_fn(target: AztecAddress) {
Test::at(target).emit_nullifier_public(1).enqueue(&mut context);
}

// Calls the emit_nullifier_public on the Test contract at the target address
// Used for testing calling an open function from another open function
// Used for testing calling a public function from another public function
// See yarn-project/end-to-end/src/e2e_nested_contract.test.ts
#[aztec(public)]
fn pub_call_open_fn(target: AztecAddress) {
fn pub_call_public_fn(target: AztecAddress) {
Test::at(target).emit_nullifier_public(1).call(&mut context);
}
}
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/contract/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Contract Class', () => {
{
name: 'bar',
isInitializer: false,
functionType: FunctionType.SECRET,
functionType: FunctionType.PRIVATE,
isInternal: false,
isStatic: false,
debugSymbols: '',
Expand All @@ -70,7 +70,7 @@ describe('Contract Class', () => {
name: 'baz',
isInitializer: false,
isStatic: false,
functionType: FunctionType.OPEN,
functionType: FunctionType.PUBLIC,
isInternal: false,
parameters: [],
returnTypes: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ export class ContractFunctionInteraction extends BaseContractInteraction {

const txRequest = await this.create();
// const from =
// this.functionDao.functionType == FunctionType.SECRET ? options.from ?? this.wallet.getAddress() : undefined;
// this.functionDao.functionType == FunctionType.PRIVATE ? options.from ?? this.wallet.getAddress() : undefined;

const simulatedTx = await this.wallet.simulateTx(txRequest, true, options?.from);

// As account entrypoints are private, for private functions we retrieve the return values from the first nested call
// since we're interested in the first set of values AFTER the account entrypoint
// For public functions we retrieve the first values directly from the public output.
const rawReturnValues =
this.functionDao.functionType == FunctionType.SECRET
this.functionDao.functionType == FunctionType.PRIVATE
? simulatedTx.privateReturnValues?.nested?.[0].values
: simulatedTx.publicOutput?.publicReturnValues?.values;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class DefaultMultiCallEntrypoint implements EntrypointInterface {
return {
name: 'entrypoint',
isInitializer: false,
functionType: 'secret',
functionType: 'private',
isInternal: false,
isStatic: false,
parameters: [
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/wallet/account_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class AccountWallet extends BaseWallet {
return {
name: 'approve_public_authwit',
isInitializer: false,
functionType: FunctionType.OPEN,
functionType: FunctionType.PUBLIC,
isInternal: true,
isStatic: false,
parameters: [
Expand All @@ -222,7 +222,7 @@ export class AccountWallet extends BaseWallet {
return {
name: 'cancel_authwit',
isInitializer: false,
functionType: FunctionType.SECRET,
functionType: FunctionType.PRIVATE,
isInternal: true,
isStatic: false,
parameters: [
Expand Down
8 changes: 0 additions & 8 deletions yarn-project/builder/src/fixtures/test_contract/Nargo.toml

This file was deleted.

11 changes: 0 additions & 11 deletions yarn-project/builder/src/fixtures/test_contract/src/main.nr

This file was deleted.

Binary file removed yarn-project/builder/src/fixtures/test_lib.zip
Binary file not shown.
7 changes: 0 additions & 7 deletions yarn-project/builder/src/fixtures/test_lib/Nargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion yarn-project/builder/src/fixtures/test_lib/src/lib.nr

This file was deleted.

1 change: 0 additions & 1 deletion yarn-project/builder/src/fixtures/test_lib/src/module.nr

This file was deleted.

3 changes: 0 additions & 3 deletions yarn-project/builder/src/fixtures/test_lib/src/module/foo.nr

This file was deleted.

2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/contract/artifact_hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function computeArtifactHash(
}

export function computeArtifactHashPreimage(artifact: ContractArtifact) {
const privateFunctionRoot = computeArtifactFunctionTreeRoot(artifact, FunctionType.SECRET);
const privateFunctionRoot = computeArtifactFunctionTreeRoot(artifact, FunctionType.PRIVATE);
const unconstrainedFunctionRoot = computeArtifactFunctionTreeRoot(artifact, FunctionType.UNCONSTRAINED);
const metadataHash = computeArtifactMetadataHash(artifact);
return { privateFunctionRoot, unconstrainedFunctionRoot, metadataHash };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('ContractAddress', () => {

it('computeInitializationHash', () => {
const mockInitFn: FunctionAbi = {
functionType: FunctionType.SECRET,
functionType: FunctionType.PRIVATE,
isInitializer: false,
isInternal: false,
isStatic: false,
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/contract/contract_class.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ describe('ContractClass', () => {

// Check function selectors match
const publicFunctionSelectors = artifact.functions
.filter(fn => fn.functionType === FunctionType.OPEN)
.filter(fn => fn.functionType === FunctionType.PUBLIC)
.map(fn => FunctionSelector.fromNameAndParameters(fn));
const privateFunctionSelectors = artifact.functions
.filter(fn => fn.functionType === FunctionType.SECRET)
.filter(fn => fn.functionType === FunctionType.PRIVATE)
.map(fn => FunctionSelector.fromNameAndParameters(fn));

expect(new Set(contractClass.publicFunctions.map(fn => fn.selector))).toEqual(new Set(publicFunctionSelectors));
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/contract/contract_class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function getContractClassFromArtifact(
): ContractClassWithId & ContractClassIdPreimage {
const artifactHash = 'artifactHash' in artifact ? artifact.artifactHash : computeArtifactHash(artifact);
const publicFunctions: ContractClass['publicFunctions'] = artifact.functions
.filter(f => f.functionType === FunctionType.OPEN)
.filter(f => f.functionType === FunctionType.PUBLIC)
.map(f => ({
selector: FunctionSelector.fromNameAndParameters(f.name, f.parameters),
bytecode: f.bytecode,
Expand All @@ -28,7 +28,7 @@ export function getContractClassFromArtifact(
const packedBytecode = packBytecode(publicFunctions);

const privateFunctions: ContractClass['privateFunctions'] = artifact.functions
.filter(f => f.functionType === FunctionType.SECRET)
.filter(f => f.functionType === FunctionType.PRIVATE)
.map(getContractClassPrivateFunctionFromArtifact)
.sort(cmpFunctionArtifacts);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('private_function_membership_proof', () => {
beforeAll(() => {
artifact = getBenchmarkContractArtifact();
contractClass = getContractClassFromArtifact(artifact);
privateFunction = artifact.functions.findLast(fn => fn.functionType === FunctionType.SECRET)!;
privateFunction = artifact.functions.findLast(fn => fn.functionType === FunctionType.PRIVATE)!;
vkHash = computeVerificationKeyHash(privateFunction.verificationKey!);
selector = FunctionSelector.fromNameAndParameters(privateFunction);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function createPrivateFunctionMembershipProof(

// Locate private function definition and artifact
const privateFunctions = artifact.functions
.filter(fn => fn.functionType === FunctionType.SECRET)
.filter(fn => fn.functionType === FunctionType.PRIVATE)
.map(getContractClassPrivateFunctionFromArtifact);
const privateFunction = privateFunctions.find(fn => fn.selector.equals(selector));
const privateFunctionArtifact = artifact.functions.find(fn => selector.equals(fn));
Expand All @@ -54,7 +54,7 @@ export function createPrivateFunctionMembershipProof(
// And the "artifact tree" captures function bytecode and metadata, and is used by the pxe to check that its executing the code it's supposed to be executing, but it never goes into circuits.
const functionMetadataHash = computeFunctionMetadataHash(privateFunctionArtifact);
const functionArtifactHash = computeFunctionArtifactHash({ ...privateFunctionArtifact, functionMetadataHash });
const artifactTree = computeArtifactFunctionTree(artifact, FunctionType.SECRET)!;
const artifactTree = computeArtifactFunctionTree(artifact, FunctionType.PRIVATE)!;
const artifactTreeLeafIndex = artifactTree.getIndex(functionArtifactHash.toBuffer());
const artifactTreeSiblingPath = artifactTree.getSiblingPath(artifactTreeLeafIndex).map(Fr.fromBuffer);

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/structs/function_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class FunctionData {
static fromAbi(abi: FunctionAbi | ContractFunctionDao): FunctionData {
return new FunctionData(
FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
abi.functionType === FunctionType.SECRET,
abi.functionType === FunctionType.PRIVATE,
abi.isStatic,
);
}
Expand Down
12 changes: 6 additions & 6 deletions yarn-project/end-to-end/src/e2e_nested_contract/importer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ describe('e2e_nested_contract manual', () => {
await importerContract.methods.call_no_args(testContract.address).send().wait();
});

it('calls an open function', async () => {
logger.info(`Calling openfn on importer contract`);
await importerContract.methods.call_open_fn(testContract.address).send().wait();
it('calls a public function', async () => {
logger.info(`Calling public_fn on importer contract`);
await importerContract.methods.call_public_fn(testContract.address).send().wait();
});

it('calls an open function from an open function', async () => {
logger.info(`Calling pub openfn on importer contract`);
await importerContract.methods.pub_call_open_fn(testContract.address).send().wait();
it('calls a public function from a public function', async () => {
logger.info(`Calling pub_public_fn on importer contract`);
await importerContract.methods.pub_call_public_fn(testContract.address).send().wait();
});
});
2 changes: 1 addition & 1 deletion yarn-project/entrypoints/src/account_entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
return {
name: 'entrypoint',
isInitializer: false,
functionType: 'secret',
functionType: 'private',
isInternal: false,
isStatic: false,
parameters: [
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/entrypoints/src/dapp_entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class DefaultDappEntrypoint implements EntrypointInterface {
return {
name: 'entrypoint',
isInitializer: false,
functionType: 'secret',
functionType: 'private',
isInternal: false,
isStatic: false,
parameters: [
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/foundation/src/abi/abi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ describe('abi', () => {
it('prefers functions based on type', () => {
const contract = {
functions: [
{ name: 'foo', isInitializer: true, functionType: FunctionType.OPEN },
{ name: 'bar', isInitializer: true, functionType: FunctionType.SECRET },
{ name: 'foo', isInitializer: true, functionType: FunctionType.PUBLIC },
{ name: 'bar', isInitializer: true, functionType: FunctionType.PRIVATE },
],
} as ContractArtifact;
expect(getDefaultInitializer(contract)?.name).toEqual('bar');
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/foundation/src/abi/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ export interface StructType extends BasicType<'struct'> {
* Aztec.nr function types.
*/
export enum FunctionType {
SECRET = 'secret',
OPEN = 'open',
PRIVATE = 'private',
PUBLIC = 'public',
UNCONSTRAINED = 'unconstrained',
}

Expand Down Expand Up @@ -404,7 +404,7 @@ export function getDefaultInitializer(contractArtifact: ContractArtifact): Funct
? initializers.find(f => f.name === 'constructor') ??
initializers.find(f => f.name === 'initializer') ??
initializers.find(f => f.parameters?.length === 0) ??
initializers.find(f => f.functionType === FunctionType.SECRET) ??
initializers.find(f => f.functionType === FunctionType.PRIVATE) ??
initializers[0]
: initializers[0];
}
Expand Down
16 changes: 8 additions & 8 deletions yarn-project/foundation/src/abi/encoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('abi/encoder', () => {
it('serializes fields as fields', () => {
const abi: FunctionAbi = {
name: 'constructor',
functionType: FunctionType.SECRET,
functionType: FunctionType.PRIVATE,
isInternal: false,
isInitializer: true,
isStatic: false,
Expand All @@ -32,7 +32,7 @@ describe('abi/encoder', () => {
const abi: FunctionAbi = {
name: 'constructor',
isInitializer: true,
functionType: FunctionType.SECRET,
functionType: FunctionType.PRIVATE,
isInternal: false,
isStatic: false,
parameters: [
Expand All @@ -57,7 +57,7 @@ describe('abi/encoder', () => {
const abi: FunctionAbi = {
name: 'constructor',
isInitializer: true,
functionType: FunctionType.SECRET,
functionType: FunctionType.PRIVATE,
isInternal: false,
isStatic: false,
parameters: [
Expand All @@ -83,7 +83,7 @@ describe('abi/encoder', () => {
const abi: FunctionAbi = {
name: 'constructor',
isInitializer: true,
functionType: FunctionType.SECRET,
functionType: FunctionType.PRIVATE,
isInternal: false,
isStatic: false,
parameters: [
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('abi/encoder', () => {
const abi: FunctionAbi = {
name: 'constructor',
isInitializer: true,
functionType: FunctionType.SECRET,
functionType: FunctionType.PRIVATE,
isInternal: false,
isStatic: false,
parameters: [
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('abi/encoder', () => {
const testFunctionAbi: FunctionAbi = {
name: 'constructor',
isInitializer: true,
functionType: FunctionType.SECRET,
functionType: FunctionType.PRIVATE,
isInternal: false,
isStatic: false,
parameters: [
Expand All @@ -174,7 +174,7 @@ describe('abi/encoder', () => {
const testFunctionAbi: FunctionAbi = {
name: 'constructor',
isInitializer: true,
functionType: FunctionType.SECRET,
functionType: FunctionType.PRIVATE,
isInternal: false,
isStatic: false,
parameters: [
Expand All @@ -200,7 +200,7 @@ describe('abi/encoder', () => {
const testFunctionAbi: FunctionAbi = {
name: 'constructor',
isInitializer: true,
functionType: FunctionType.SECRET,
functionType: FunctionType.PRIVATE,
isInternal: false,
isStatic: false,
parameters: [
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/simulator/src/client/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export class AcirSimulator {
contractAddress: AztecAddress,
msgSender = AztecAddress.ZERO,
): Promise<ExecutionResult> {
if (entryPointArtifact.functionType !== FunctionType.SECRET) {
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as secret`);
if (entryPointArtifact.functionType !== FunctionType.PRIVATE) {
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as private`);
}

if (request.origin !== contractAddress) {
Expand Down
Loading
Loading