Skip to content

Commit

Permalink
feat: Add return type parsing for noir private kernel circuit (#2762)
Browse files Browse the repository at this point in the history
Please provide a paragraph or two giving a summary of the change,
including relevant motivation and context.

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [ ] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [ ] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [ ] Every change is related to the PR description.
- [ ] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to relevant issues (if any exist).
  • Loading branch information
sirasistant authored Oct 10, 2023
1 parent d5a14eb commit c6c8e4b
Show file tree
Hide file tree
Showing 2 changed files with 403 additions and 16 deletions.
104 changes: 104 additions & 0 deletions yarn-project/noir-private-kernel/src/type_conversion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import {
AztecAddress,
ContractDeploymentData,
EthAddress,
Fr,
FunctionData,
FunctionSelector,
HistoricBlockData,
Point,
TxContext,
} from '@aztec/circuits.js';

import {
mapAztecAddressFromNoir,
mapAztecAddressToNoir,
mapContractDeploymentDataFromNoir,
mapContractDeploymentDataToNoir,
mapEthAddressFromNoir,
mapEthAddressToNoir,
mapFieldFromNoir,
mapFieldToNoir,
mapFunctionDataFromNoir,
mapFunctionDataToNoir,
mapFunctionSelectorFromNoir,
mapFunctionSelectorToNoir,
mapHistoricalBlockDataFromNoir,
mapHistoricalBlockDataToNoir,
mapPointFromNoir,
mapPointToNoir,
mapTxContextFromNoir,
mapTxContextToNoir,
} from './type_conversion.js';

describe('Noir<>Circuits.js type conversion test suite', () => {
describe('Round trip', () => {
it('should map fields', () => {
const field = new Fr(27n);
expect(mapFieldFromNoir(mapFieldToNoir(field))).toEqual(field);
});

const point = new Point(new Fr(27n), new Fr(28n));

it('should map points', () => {
expect(mapPointFromNoir(mapPointToNoir(point))).toEqual(point);
});

it('should map aztec addresses', () => {
const aztecAddress = AztecAddress.random();
expect(mapAztecAddressFromNoir(mapAztecAddressToNoir(aztecAddress))).toEqual(aztecAddress);
});

it('should map eth addresses', () => {
const ethAddress = EthAddress.random();
expect(mapEthAddressFromNoir(mapEthAddressToNoir(ethAddress))).toEqual(ethAddress);
});

const contractDeploymentData = new ContractDeploymentData(
point,
new Fr(29n),
new Fr(30n),
new Fr(31n),
AztecAddress.random(),
);

it('should map contract deployment data', () => {
expect(mapContractDeploymentDataFromNoir(mapContractDeploymentDataToNoir(contractDeploymentData))).toEqual(
contractDeploymentData,
);
});

it('should map tx context', () => {
const txContext = new TxContext(false, true, false, contractDeploymentData, new Fr(32n), new Fr(33n));
expect(mapTxContextFromNoir(mapTxContextToNoir(txContext))).toEqual(txContext);
});

const functionSelector = new FunctionSelector(34);

it('should map function selectors', () => {
expect(mapFunctionSelectorFromNoir(mapFunctionSelectorToNoir(functionSelector))).toEqual(functionSelector);
});

const functionData = new FunctionData(functionSelector, false, true, false);

it('should map function data', () => {
expect(mapFunctionDataFromNoir(mapFunctionDataToNoir(functionData))).toEqual(functionData);
});

it('should map historical block data', () => {
const historicalBlockData = new HistoricBlockData(
new Fr(35n),
new Fr(36n),
new Fr(37n),
new Fr(38n),
new Fr(39n),
new Fr(40n),
new Fr(41n),
new Fr(42n),
);
expect(mapHistoricalBlockDataFromNoir(mapHistoricalBlockDataToNoir(historicalBlockData))).toEqual(
historicalBlockData,
);
});
});
});
Loading

0 comments on commit c6c8e4b

Please sign in to comment.