Skip to content

Commit

Permalink
chore: Remove unused isInternal flag in contract classes
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Mar 22, 2024
1 parent 4733d25 commit 4aca2f5
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ function serializeContractClassPublic(contractClass: Omit<ContractClassPublic, '
numToUInt8(contractClass.version),
contractClass.artifactHash,
contractClass.publicFunctions.length,
contractClass.publicFunctions?.map(f =>
serializeToBuffer(f.selector, f.bytecode.length, f.bytecode, f.isInternal),
) ?? [],
contractClass.publicFunctions?.map(f => serializeToBuffer(f.selector, f.bytecode.length, f.bytecode)) ?? [],
contractClass.privateFunctions.length,
contractClass.privateFunctions.map(serializePrivateFunction),
contractClass.unconstrainedFunctions.length,
Expand All @@ -85,7 +83,6 @@ function serializePrivateFunction(fn: ExecutablePrivateFunctionWithMembershipPro
return serializeToBuffer(
fn.selector,
fn.vkHash,
fn.isInternal,
fn.bytecode.length,
fn.bytecode,
fn.functionMetadataHash,
Expand Down Expand Up @@ -120,7 +117,6 @@ function deserializeContractClassPublic(buffer: Buffer): Omit<ContractClassPubli
fromBuffer: reader => ({
selector: reader.readObject(FunctionSelector),
bytecode: reader.readBuffer(),
isInternal: reader.readBoolean(),
}),
}),
privateFunctions: reader.readVector({ fromBuffer: deserializePrivateFunction }),
Expand All @@ -135,7 +131,6 @@ function deserializePrivateFunction(buffer: Buffer | BufferReader): ExecutablePr
return {
selector: reader.readObject(FunctionSelector),
vkHash: reader.readObject(Fr),
isInternal: reader.readBoolean(),
bytecode: reader.readBuffer(),
functionMetadataHash: reader.readObject(Fr),
artifactMetadataHash: reader.readObject(Fr),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('ArtifactHash', () => {
it('calculates the artifact hash', () => {
const artifact = getSampleContractArtifact();
expect(computeArtifactHash(artifact).toString()).toMatchInlineSnapshot(
`"0x1d1e8f03c63b76d26cfd04ce728586c014768cec6765fdb8f3f24cb931b5ec17"`,
`"0x19dcd971117d72ceed658023cf16036d912de56c75a54da414d2d6bd645c99f2"`,
);
});
});
25 changes: 20 additions & 5 deletions yarn-project/circuits.js/src/contract/contract_class.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import { FunctionSelector, FunctionType } from '@aztec/foundation/abi';
import { Fr } from '@aztec/foundation/fields';
import { toFriendlyJSON } from '@aztec/foundation/serialize';
import { setupCustomSnapshotSerializers } from '@aztec/foundation/testing';

import { getSampleContractArtifact } from '../tests/fixtures.js';
import { getContractClassFromArtifact } from './contract_class.js';

describe('ContractClass', () => {
setupCustomSnapshotSerializers(expect);
it('creates a contract class from a contract compilation artifact', () => {
const artifact = getSampleContractArtifact();
const contractClass = getContractClassFromArtifact({
...getSampleContractArtifact(),
...artifact,
artifactHash: Fr.fromString('0x1234'),
});
expect(toFriendlyJSON(contractClass)).toMatchSnapshot();

// Assert bytecode has a reasonable length
expect(contractClass.packedBytecode.length).toBeGreaterThan(100);
contractClass.publicFunctions.forEach(publicFunction => {
expect(publicFunction.bytecode.length).toBeGreaterThan(100);
});

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

expect(new Set(contractClass.publicFunctions.map(fn => fn.selector))).toEqual(new Set(publicFunctionSelectors));
expect(new Set(contractClass.privateFunctions.map(fn => fn.selector))).toEqual(new Set(privateFunctionSelectors));
});
});
2 changes: 0 additions & 2 deletions yarn-project/circuits.js/src/contract/contract_class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export function getContractClassFromArtifact(
.map(f => ({
selector: FunctionSelector.fromNameAndParameters(f.name, f.parameters),
bytecode: f.bytecode,
isInternal: f.isInternal,
}))
.sort(cmpFunctionArtifacts);

Expand All @@ -49,7 +48,6 @@ export function getContractClassPrivateFunctionFromArtifact(
return {
selector: FunctionSelector.fromNameAndParameters(f.name, f.parameters),
vkHash: computeVerificationKeyHash(f.verificationKey!),
isInternal: f.isInternal,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ describe('ContractClass', () => {
{
selector: FunctionSelector.fromString('0x12345678'),
vkHash: Fr.fromString('0x1234'),
isInternal: false,
},
],
publicFunctions: [
{
selector: FunctionSelector.fromString('0x12345678'),
bytecode: Buffer.from('123456789012345678901234567890', 'hex'),
isInternal: false,
},
],
};
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ export class PrivateFunctionBroadcastedEvent {
}

export class BroadcastedPrivateFunction implements PrivateFunction {
// TODO: Deleteme
public isInternal = false;

constructor(
/** Selector of the function. Calculated as the hash of the method name and parameters. The specification of this is not enforced by the protocol. */
public readonly selector: FunctionSelector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { computePrivateFunctionsRoot, computePrivateFunctionsTree } from './priv
describe('PrivateFunction', () => {
setupCustomSnapshotSerializers(expect);
const privateFunctions: PrivateFunction[] = [
{ selector: makeSelector(1), vkHash: fr(2), isInternal: false },
{ selector: makeSelector(3), vkHash: fr(4), isInternal: false },
{ selector: makeSelector(1), vkHash: fr(2) },
{ selector: makeSelector(3), vkHash: fr(4) },
];

it('computes merkle tree', () => {
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuits.js/src/contract/public_bytecode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { FUNCTION_SELECTOR_NUM_BYTES } from '../constants.gen.js';
*/
export function packBytecode(publicFns: ContractClass['publicFunctions']): Buffer {
return serializeArrayOfBufferableToVector(
publicFns.map(fn => serializeToBuffer(fn.selector, fn.isInternal, numToInt32BE(fn.bytecode.length), fn.bytecode)),
publicFns.map(fn => serializeToBuffer(fn.selector, numToInt32BE(fn.bytecode.length), fn.bytecode)),
);
}

Expand All @@ -28,7 +28,6 @@ export function unpackBytecode(buffer: Buffer): ContractClass['publicFunctions']
return reader.readVector({
fromBuffer: (reader: BufferReader) => ({
selector: FunctionSelector.fromBuffer(reader.readBytes(FUNCTION_SELECTOR_NUM_BYTES)),
isInternal: reader.readBoolean(),
bytecode: reader.readBuffer(),
}),
});
Expand Down
3 changes: 0 additions & 3 deletions yarn-project/circuits.js/src/tests/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,6 @@ export function makeExecutablePrivateFunctionWithMembershipProof(
functionMetadataHash: fr(seed + 5),
unconstrainedFunctionsArtifactTreeRoot: fr(seed + 6),
vkHash: fr(seed + 7),
isInternal: false,
};
}

Expand Down Expand Up @@ -1333,7 +1332,6 @@ function makeContractClassPublicFunction(seed = 0): PublicFunction {
return {
selector: FunctionSelector.fromField(fr(seed + 1)),
bytecode: makeBytes(100, seed + 2),
isInternal: false,
};
}

Expand All @@ -1342,7 +1340,6 @@ function makeContractClassPrivateFunction(seed = 0): PrivateFunction {
return {
selector: FunctionSelector.fromField(fr(seed + 1)),
vkHash: fr(seed + 2),
isInternal: false,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe('Data generation for noir tests', () => {
publicKeysHash: new Fr(45678),
salt: new Fr(56789),
privateFunctions: [
{ selector: FunctionSelector.fromField(new Fr(1010101)), isInternal: false, vkHash: new Fr(0) },
{ selector: FunctionSelector.fromField(new Fr(2020202)), isInternal: true, vkHash: new Fr(0) },
{ selector: FunctionSelector.fromField(new Fr(1010101)), vkHash: new Fr(0) },
{ selector: FunctionSelector.fromField(new Fr(2020202)), vkHash: new Fr(0) },
],
toString: () => 'defaultContract',
};
Expand All @@ -44,7 +44,7 @@ describe('Data generation for noir tests', () => {
packedBytecode: Buffer.from([3, 4, 3, 4]),
publicKeysHash: new Fr(4545),
salt: new Fr(5656),
privateFunctions: [{ selector: FunctionSelector.fromField(new Fr(334455)), isInternal: false, vkHash: new Fr(0) }],
privateFunctions: [{ selector: FunctionSelector.fromField(new Fr(334455)), vkHash: new Fr(0) }],
toString: () => 'parentContract',
};

Expand Down
11 changes: 0 additions & 11 deletions yarn-project/types/src/contracts/contract_class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ export interface PrivateFunction {
selector: FunctionSelector;
/** Hash of the verification key associated to this private function. */
vkHash: Fr;
/**
* Whether the function is internal.
* @deprecated To be reimplemented as an app-level macro.
*/
isInternal: boolean;
}

/** Public function definition within a contract class. */
Expand All @@ -40,12 +35,6 @@ export interface PublicFunction {
selector: FunctionSelector;
/** Public bytecode. */
bytecode: Buffer;
/**
* Whether the function is internal.
* @deprecated To be reimplemented as an app-level macro.
* TODO(@spalladino) Remove this
*/
isInternal: boolean;
}

/** Unconstrained function definition. */
Expand Down

0 comments on commit 4aca2f5

Please sign in to comment.