Skip to content

Commit

Permalink
feat: Base rollup in noir (#3257)
Browse files Browse the repository at this point in the history
This PR ports the logic for the base rollup from CPP to noir. There are
multiple optimizations for this circuit in the pipeline:
- Change the indexed tree insertion algorithm to eliminate the second
branch. Experimental branch here
#3367
- Brillig array optimisation. Experimental branch here
#3377
 - Switch the public data tree to indexed

# 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.
- [x] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [x] Every change is related to the PR description.
- [x] 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).

---------

Co-authored-by: kevaundray <[email protected]>
Co-authored-by: ludamad <[email protected]>
  • Loading branch information
3 people authored Nov 24, 2023
1 parent 2001d47 commit 4a1e9c3
Show file tree
Hide file tree
Showing 41 changed files with 1,904 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ AggregationObject aggregate_proofs(BaseRollupInputs const& baseRollupInputs)
}

/** TODO: implement
* This is not being used
* @brief Get the prover contribution hash object
*
* @return NT::fr
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_p2p_network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('e2e_p2p_network', () => {
await context.pxeService.stop();
}
await bootstrapNode.stop();
}, 80_000);
}, 120_000);

const createBootstrapNode = async () => {
const peerId = await createLibP2PPeerId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('e2e_public_cross_chain_messaging', () => {
// ensure funds are gone to owner and not user2.
await crossChainTestHarness.expectPublicBalanceOnL2(ownerAddress, bridgeAmount + unrelatedMintAmount);
await crossChainTestHarness.expectPublicBalanceOnL2(user2Wallet.getAddress(), 0n);
}, 60_000);
}, 90_000);

it("Bridge can't withdraw my funds if I don't give approval", async () => {
const mintAmountToOwner = 100n;
Expand All @@ -163,7 +163,7 @@ describe('e2e_public_cross_chain_messaging', () => {
.methods.exit_to_l1_public(ethAccount, withdrawAmount, EthAddress.ZERO, nonce)
.simulate(),
).rejects.toThrowError('Assertion failed: Message not authorized by account');
});
}, 60_000);

it("can't claim funds privately which were intended for public deposit from the token portal", async () => {
const bridgeAmount = 100n;
Expand All @@ -185,5 +185,5 @@ describe('e2e_public_cross_chain_messaging', () => {
.methods.claim_private(secretHash, bridgeAmount, ethAccount, messageKey, secret)
.simulate(),
).rejects.toThrowError("Cannot satisfy constraint 'l1_to_l2_message_data.message.content == content");
});
}, 60_000);
});
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_sandbox_example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,5 @@ describe('e2e_sandbox_example', () => {
// check that alice and bob are in registeredAccounts
expect(registeredAccounts.find(acc => acc.equals(alice))).toBeTruthy();
expect(registeredAccounts.find(acc => acc.equals(bob))).toBeTruthy();
});
}, 60_000);
});
20 changes: 10 additions & 10 deletions yarn-project/end-to-end/src/guides/dapp_testing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('guides/dapp/testing', () => {
owner = await createAccount(pxe);
recipient = await createAccount(pxe);
token = await TokenContract.deploy(owner, owner.getCompleteAddress()).send().deployed();
}, 30_000);
}, 60_000);

it('increases recipient funds on mint', async () => {
const recipientAddress = recipient.getAddress();
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('guides/dapp/testing', () => {
// The balances mapping is defined on storage slot 3 and is indexed by user address
ownerSlot = cheats.aztec.computeSlotInMap(3n, ownerAddress);
// docs:end:calc-slot
}, 60_000);
}, 90_000);

it('checks private storage', async () => {
// docs:start:private-storage
Expand All @@ -158,7 +158,7 @@ describe('guides/dapp/testing', () => {
const balance = values.reduce((sum, current) => sum + current.toBigInt(), 0n);
expect(balance).toEqual(100n);
// docs:end:private-storage
});
}, 30_000);

it('checks public storage', async () => {
// docs:start:public-storage
Expand All @@ -167,7 +167,7 @@ describe('guides/dapp/testing', () => {
const balance = await pxe.getPublicStorageAt(token.address, ownerPublicBalanceSlot);
expect(balance!.value).toEqual(100n);
// docs:end:public-storage
});
}, 30_000);

it('checks unencrypted logs, [Kinda broken with current implementation]', async () => {
// docs:start:unencrypted-logs
Expand All @@ -180,21 +180,21 @@ describe('guides/dapp/testing', () => {
const logs = (await pxe.getUnencryptedLogs(filter)).logs;
expect(Fr.fromBuffer(logs[0].log.data)).toEqual(value);
// docs:end:unencrypted-logs
});
}, 30_000);

it('asserts a local transaction simulation fails by calling simulate', async () => {
// docs:start:local-tx-fails
const call = token.methods.transfer(owner.getAddress(), recipient.getAddress(), 200n, 0);
await expect(call.simulate()).rejects.toThrowError(/Balance too low/);
// docs:end:local-tx-fails
});
}, 30_000);

it('asserts a local transaction simulation fails by calling send', async () => {
// docs:start:local-tx-fails-send
const call = token.methods.transfer(owner.getAddress(), recipient.getAddress(), 200n, 0);
await expect(call.send().wait()).rejects.toThrowError(/Balance too low/);
// docs:end:local-tx-fails-send
});
}, 30_000);

it('asserts a transaction is dropped', async () => {
// docs:start:tx-dropped
Expand All @@ -207,21 +207,21 @@ describe('guides/dapp/testing', () => {
await call1.send().wait();
await expect(call2.send().wait()).rejects.toThrowError(/dropped/);
// docs:end:tx-dropped
});
}, 30_000);

it('asserts a simulation for a public function call fails', async () => {
// docs:start:local-pub-fails
const call = token.methods.transfer_public(owner.getAddress(), recipient.getAddress(), 1000n, 0);
await expect(call.simulate()).rejects.toThrowError(/Underflow/);
// docs:end:local-pub-fails
});
}, 30_000);

it('asserts a transaction with a failing public call is dropped (until we get public reverts)', async () => {
// docs:start:pub-dropped
const call = token.methods.transfer_public(owner.getAddress(), recipient.getAddress(), 1000n, 0);
await expect(call.send({ skipPublicSimulation: true }).wait()).rejects.toThrowError(/dropped/);
// docs:end:pub-dropped
});
}, 30_000);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,5 @@ describe('archiver integration with l1 to l2 messages', () => {

expect((await archiver.getPendingL1ToL2Messages(10)).length).toEqual(0);
expect(() => archiver.getConfirmedL1ToL2Message(Fr.ZERO)).toThrow();
});
}, 30_000);
});
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/sample-dapp/ci/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ describe('sample-dapp', () => {
await waitForSandbox();
await deploy();
await main();
}, 60_000);
}, 90_000);
});
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/sample-dapp/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ describe('token', () => {
expect(await token.methods.balance_of_private(recipient.getAddress()).view()).toEqual(0n);
await token.methods.transfer(owner.getAddress(), recipient.getAddress(), 20n, 0).send().wait();
expect(await token.methods.balance_of_private(recipient.getAddress()).view()).toEqual(20n);
});
}, 30_000);
// docs:end:test
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ struct NullifierLeafPreimage {
}

impl NullifierLeafPreimage {
// TODO(Kev): Check if this is needed.
fn is_empty(self) -> bool {
pub fn default() -> Self {
NullifierLeafPreimage {
leaf_value : 0,
next_value : 0,
next_index : 0,
}
}

pub fn is_empty(self) -> bool {
(self.leaf_value == 0) & (self.next_index == 0) & (self.next_value == 0)
}

fn hash(self) -> Field {
pub fn hash(self) -> Field {
if self.is_empty() {
0
} else {
Expand Down
Loading

0 comments on commit 4a1e9c3

Please sign in to comment.