Skip to content

Commit

Permalink
Merge branch 'master' into sync-noir
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Apr 24, 2024
2 parents a3b62cb + f497c26 commit fabdcaf
Show file tree
Hide file tree
Showing 24 changed files with 225 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/protocol-circuits-gate-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:

- name: Compare gates reports
id: gates_diff
uses: TomAFrench/noir-gates-diff@df05f34e2ab275ddc4f2cac065df1c88f8a05e5d
uses: vezenovm/noir-gates-diff@acf12797860f237117e15c0d6e08d64253af52b6
with:
report: protocol_circuits_report.json
summaryQuantile: 0 # Display any diff in gate count
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/setup-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
group: start-builder-${{ inputs.runner_label }}
steps:
- name: Start EC2 runner
uses: AztecProtocol/ec2-action-builder@v0.14e
uses: AztecProtocol/ec2-action-builder@v0.15
with:
github_token: ${{ secrets.GH_SELF_HOSTED_RUNNER_TOKEN }}
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
echo '{"default-address-pools":[{"base":"172.17.0.0/12","size":20}, {"base":"10.99.0.0/12","size":20}, {"base":"192.168.0.0/16","size":24}]}' > /etc/docker/daemon.json
sudo service docker restart
# helps to not overuse space
docker system prune -f || true
docker system prune -f -a || true
echo "Configured docker daemon for making many networks."
# Run maybe_exit_spot.sh every minute
cp scripts/ci/spot_runner_graceful_exit.sh /run/spot_runner_graceful_exit.sh
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/api/abi.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { ContractArtifact, FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
export { loadContractArtifact } from '@aztec/types/abi';
export { loadContractArtifact, contractArtifactToBuffer, contractArtifactFromBuffer } from '@aztec/types/abi';
export { NoirCompiledContract } from '@aztec/types/noir';
2 changes: 2 additions & 0 deletions yarn-project/aztec.js/src/contract/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ describe('Contract Class', () => {
globals: {},
},
fileMap: {},
storageLayout: {},
notes: {},
};

beforeEach(() => {
Expand Down
38 changes: 8 additions & 30 deletions yarn-project/aztec.js/src/contract/contract_base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { type Fr, computePartialAddress } from '@aztec/circuits.js';
import { type ContractArtifact, type FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
import { computePartialAddress } from '@aztec/circuits.js';
import {
type ContractArtifact,
type ContractNote,
type FieldLayout,
type FunctionArtifact,
FunctionSelector,
} from '@aztec/foundation/abi';
import { type ContractInstanceWithAddress } from '@aztec/types/contracts';

import { type Wallet } from '../account/index.js';
Expand All @@ -16,34 +22,6 @@ export type ContractMethod = ((...args: any[]) => ContractFunctionInteraction) &
readonly selector: FunctionSelector;
};

/**
* Type representing a field layout in the storage of a contract.
*/
type FieldLayout = {
/**
* Slot in which the field is stored.
*/
slot: Fr;
/**
* Type being stored at the slot
*/
typ: string;
};

/**
* Type representing a note in use in the contract.
*/
type ContractNote = {
/**
* Note identifier
*/
id: Fr;
/**
* Type of the note
*/
typ: string;
};

/**
* Type representing the storage layout of a contract.
*/
Expand Down
4 changes: 4 additions & 0 deletions yarn-project/aztec/src/cli/cmds/start_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export const startNode = async (
nodeConfig.disableProver = true;
}

if (!nodeConfig.disableSequencer && nodeConfig.disableProver) {
throw new Error('Cannot run a sequencer without a prover');
}

// Create and start Aztec Node.
const node = await createAztecNode(nodeConfig);
const nodeServer = createAztecNodeRpcServer(node);
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"fs-extra": "^11.1.1",
"lodash.camelcase": "^4.3.0",
"lodash.capitalize": "^4.2.1",
"lodash.uniqby": "^4.7.0",
"memfs": "^4.6.0",
"pako": "^2.1.0",
"semver": "^7.5.4",
Expand All @@ -71,7 +70,6 @@
"@types/jest": "^29.5.0",
"@types/lodash.camelcase": "^4.3.7",
"@types/lodash.capitalize": "^4.2.7",
"@types/lodash.uniqby": "^4.7.9",
"@types/node": "^18.7.23",
"@types/pako": "^2.0.0",
"@types/semver": "^7.5.4",
Expand Down
71 changes: 29 additions & 42 deletions yarn-project/builder/src/contract-interface-gen/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import {
type ABIParameter,
type BasicValue,
type ContractArtifact,
type FunctionArtifact,
type IntegerValue,
type StructValue,
type TupleValue,
type TypedStructFieldValue,
getDefaultInitializer,
isAztecAddressStruct,
isEthAddressStruct,
isFunctionSelectorStruct,
isWrappedFieldStruct,
} from '@aztec/foundation/abi';

import uniqBy from 'lodash.uniqby';

/**
* Returns the corresponding typescript type for a given Noir type.
* @param type - The input Noir type.
Expand Down Expand Up @@ -192,64 +185,58 @@ function generateAbiStatement(name: string, artifactImportPath: string) {
* @param input - The contract artifact.
*/
function generateStorageLayoutGetter(input: ContractArtifact) {
const storage = input.outputs.globals.storage ? (input.outputs.globals.storage[0] as StructValue) : { fields: [] };
const storageFields = storage.fields as TypedStructFieldValue<StructValue>[];
const storageFieldsUnionType = storageFields.map(f => `'${f.name}'`).join(' | ');
const layout = storageFields
const entries = Object.entries(input.storageLayout);

if (entries.length === 0) {
return '';
}

const storageFieldsUnionType = entries.map(([name]) => `'${name}'`).join(' | ');
const layout = entries
.map(
({
name,
value: {
fields: [slot, typ],
},
}) =>
([name, { slot, typ }]) =>
`${name}: {
slot: new Fr(${(slot.value as IntegerValue).value}n),
typ: "${(typ.value as BasicValue<'string', string>).value}",
}
`,
slot: new Fr(${slot.toBigInt()}n),
typ: "${typ}",
}`,
)
.join(',\n');
return storageFields.length > 0
? `
public static get storage(): ContractStorageLayout<${storageFieldsUnionType}> {

return `public static get storage(): ContractStorageLayout<${storageFieldsUnionType}> {
return {
${layout}
} as ContractStorageLayout<${storageFieldsUnionType}>;
}
`
: '';
`;
}

/**
* Generates a getter for the contract notes
* @param input - The contract artifact.
*/
function generateNotesGetter(input: ContractArtifact) {
const notes = input.outputs.globals.notes
? uniqBy(input.outputs.globals.notes as TupleValue[], n => (n.fields[1] as BasicValue<'string', string>).value)
: [];
const notesUnionType = notes.map(n => `'${(n.fields[1] as BasicValue<'string', string>).value}'`).join(' | ');
const entries = Object.entries(input.notes);

const noteMetadata = notes
if (entries.length === 0) {
return '';
}

const notesUnionType = entries.map(([name]) => `'${name}'`).join(' | ');
const noteMetadata = entries
.map(
({ fields: [id, typ] }) =>
`${(typ as BasicValue<'string', string>).value}: {
id: new Fr(${(id as IntegerValue).value}n),
}
`,
([name, { id }]) =>
`${name}: {
id: new Fr(${id.toBigInt()}n),
}`,
)
.join(',\n');
return notes.length > 0
? `
public static get notes(): ContractNotes<${notesUnionType}> {
const notes = this.artifact.outputs.globals.notes ? (this.artifact.outputs.globals.notes as any) : [];

return `public static get notes(): ContractNotes<${notesUnionType}> {
return {
${noteMetadata}
} as ContractNotes<${notesUnionType}>;
}
`
: '';
`;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/circuit-types/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export const randomContractArtifact = (): ContractArtifact => ({
globals: {},
},
fileMap: {},
storageLayout: {},
notes: {},
});

export const randomContractInstanceWithAddress = (opts: { contractClassId?: Fr } = {}): ContractInstanceWithAddress =>
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/circuits.js/src/contract/artifact_hash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ describe('ArtifactHash', () => {
globals: {},
structs: {},
},
storageLayout: {},
notes: {},
};
expect(computeArtifactHash(emptyArtifact).toString()).toMatchInlineSnapshot(
`"0x0dea64e7fa0688017f77bcb7075485485afb4a5f1f8508483398869439f82fdf"`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ describe('PublicKernelCircuitPrivateInputs', () => {
expect(original).toEqual(serialized);
expect(original).not.toBe(serialized);
});

it('serializes to and deserializes from a string', () => {
const original = makePublicKernelCircuitPrivateInputs(123);
const serialized = PublicKernelCircuitPrivateInputs.fromString(original.toString());
expect(original).toEqual(serialized);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,47 @@ export class PublicKernelCircuitPrivateInputs {
public readonly publicCall: PublicCallData,
) {}

/**
* Serializes the object to a buffer.
* @returns - Buffer representation of the object.
*/
toBuffer() {
return serializeToBuffer(this.previousKernel, this.publicCall);
}

/**
* Serializes the object to a hex string.
* @returns - Hex string representation of the object.
*/
toString() {
return this.toBuffer().toString('hex');
}

/**
* Deserializes the object from a buffer.
* @param buffer - Buffer to deserialize.
* @returns - Deserialized object.
*/
static fromBuffer(buffer: BufferReader | Buffer) {
const reader = BufferReader.asReader(buffer);
const previousKernel = reader.readObject(PublicKernelData);
const publicCall = reader.readObject(PublicCallData);
return new PublicKernelCircuitPrivateInputs(previousKernel, publicCall);
}

/**
* Deserializes the object from a hex string.
* @param str - Hex string to deserialize.
* @returns - Deserialized object.
*/
static fromString(str: string) {
return PublicKernelCircuitPrivateInputs.fromBuffer(Buffer.from(str, 'hex'));
}

/**
* Clones the object.
* @returns - Cloned object.
*/
clone() {
return PublicKernelCircuitPrivateInputs.fromBuffer(this.toBuffer());
}
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/e2e_account_init_fees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ describe('e2e_fees_account_init', () => {
});

async function addTransparentNoteToPxe(owner: AztecAddress, amount: bigint, secretHash: Fr, txHash: TxHash) {
const storageSlot = new Fr(5); // The storage slot of `pending_shields` is 5.
const noteTypeId = new Fr(84114971101151129711410111011678111116101n); // TransparentNote
const storageSlot = bananaCoin.artifact.storageLayout['pending_shields'].slot;
const noteTypeId = bananaCoin.artifact.notes['TransparentNote'].id;

const note = new Note([new Fr(amount), secretHash]);
// this note isn't encrypted but we need to provide a registered public key
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/sample-dapp/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ async function mintPrivateFunds(pxe) {
const secretHash = await computeSecretHash(secret);
const receipt = await token.methods.mint_private(mintAmount, secretHash).send().wait();

const storageSlot = new Fr(5);
const noteTypeId = new Fr(84114971101151129711410111011678111116101n); // TransparentNote
const storageSlot = token.artifact.storageLayout['pending_shields'].slot;
const noteTypeId = token.artifact.notes['TransparentNote'].id;

const note = new Note([new Fr(mintAmount), secretHash]);
const extendedNote = new ExtendedNote(
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/end-to-end/src/sample-dapp/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('token', () => {
const secretHash = await computeSecretHash(secret);
const receipt = await token.methods.mint_private(initialBalance, secretHash).send().wait();

const storageSlot = new Fr(5);
const noteTypeId = new Fr(84114971101151129711410111011678111116101n); // TransparentNote
const storageSlot = token.artifact.storageLayout['pending_shields'].slot;
const noteTypeId = token.artifact.notes['TransparentNote'].id;
const note = new Note([new Fr(initialBalance), secretHash]);
const extendedNote = new ExtendedNote(
note,
Expand Down
10 changes: 5 additions & 5 deletions yarn-project/end-to-end/src/shared/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ export const browserTestSuite = (
INITIAL_TEST_SIGNING_KEYS,
INITIAL_TEST_ACCOUNT_SALTS,
Buffer,
contractArtifactFromBuffer,
} = window.AztecJs;
// We serialize the artifact since buffers (used for bytecode) do not cross well from one realm to another
const TokenContractArtifact = JSON.parse(
Buffer.from(serializedTokenContractArtifact, 'base64').toString('utf-8'),
(key, value) => (key === 'bytecode' && typeof value === 'string' ? Buffer.from(value, 'base64') : value),
const TokenContractArtifact = contractArtifactFromBuffer(
Buffer.from(serializedTokenContractArtifact, 'base64'),
);
const pxe = createPXEClient(rpcUrl!);

Expand Down Expand Up @@ -264,9 +264,9 @@ export const browserTestSuite = (
const secretHash = computeSecretHash(secret);
const mintPrivateReceipt = await token.methods.mint_private(initialBalance, secretHash).send().wait();

const storageSlot = new Fr(5);
const storageSlot = token.artifact.storageLayout['pending_shields'].slot;

const noteTypeId = new Fr(84114971101151129711410111011678111116101n);
const noteTypeId = token.artifact.notes['TransparentNote'].id;
const note = new Note([new Fr(initialBalance), secretHash]);
const extendedNote = new ExtendedNote(
note,
Expand Down
Loading

0 comments on commit fabdcaf

Please sign in to comment.