-
Notifications
You must be signed in to change notification settings - Fork 611
feat(e2e): shielding and unshielding #915
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
Merged
Merged
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
ee8dc36
fix: reroll noir hash loops
Maddiaa0 80657bd
fix: use libraries refactor
Maddiaa0 ec876ab
feat: add automatic formatting to build command
Maddiaa0 3e1a7b3
fix: merge noir refactors
Maddiaa0 6993900
fix: update test contract
Maddiaa0 0d492f1
fix: update zk_token
Maddiaa0 0719269
fix: update public private
Maddiaa0 8a936ec
fix: update non native token
Maddiaa0 1ac7df5
refactor: move aztec-noir lib into libs folder
Maddiaa0 d4882cd
fix: update compile all
Maddiaa0 27976ad
feat: unshield tokens
Maddiaa0 3480ee0
fix: formatting
Maddiaa0 43f4441
fix: revert plookup change
Maddiaa0 6e1dcc0
fix: increase timeout
Maddiaa0 2b5dc7e
merge
Maddiaa0 cbdd11c
fix: merge conflict
Maddiaa0 023613c
fix: review comments
Maddiaa0 a76942a
fix: fmt
Maddiaa0 20196b5
fix: test contract recompile
Maddiaa0 da7fa27
fix: hash code cleanup
Maddiaa0 dabc818
fix: update public to private e2e to check key invariants
Maddiaa0 8ee2833
chore(fmt): e2e
Maddiaa0 e2f7e17
fmt
Maddiaa0 daba48b
fix: post rebase clean
Maddiaa0 629f9ea
fix: fmt
Maddiaa0 7c7af5d
fmt
Maddiaa0 9770592
fix
Maddiaa0 d49336a
Merge branch 'master' into md/878-unshield
Maddiaa0 d680ef3
fix: collapse l1 to l2 message loops
Maddiaa0 47dc272
fix: more unrolling
Maddiaa0 1c56fb1
fix: note on sig
Maddiaa0 772e3e0
Merge branch 'md/noir-libs' into md/878-unshield
Maddiaa0 c6bdb67
Merge branch 'master' into md/878-unshield
Maddiaa0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 68 additions & 62 deletions
130
yarn-project/end-to-end/src/e2e_public_to_private_messaging.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,86 +1,92 @@ | ||
| import { AztecNodeService } from '@aztec/aztec-node'; | ||
| import { | ||
| AztecAddress, | ||
| AztecRPCServer, | ||
| Contract, | ||
| ContractDeployer, | ||
| Fr, | ||
| TxStatus, | ||
| computeMessageSecretHash, | ||
| } from '@aztec/aztec.js'; | ||
| import { PublicToPrivateContractAbi } from '@aztec/noir-contracts/examples'; | ||
| import { AztecAddress, AztecRPCServer, EthAddress } from '@aztec/aztec.js'; | ||
| import { DebugLogger } from '@aztec/foundation/log'; | ||
| import { pointToPublicKey, setup } from './utils.js'; | ||
| import { CrossChainTestHarness } from './cross_chain/test_harness.js'; | ||
| import { delay, setup } from './utils.js'; | ||
|
|
||
| describe('e2e_public_to_private_messaging', () => { | ||
| let aztecNode: AztecNodeService; | ||
| let aztecRpcServer: AztecRPCServer; | ||
| let accounts: AztecAddress[]; | ||
| let logger: DebugLogger; | ||
|
|
||
| let contract: Contract; | ||
| let ethAccount: EthAddress; | ||
|
|
||
| let underlyingERC20: any; | ||
|
|
||
| const initialBalance = 10n; | ||
| let ownerAddress: AztecAddress; | ||
|
|
||
| let crossChainTestHarness: CrossChainTestHarness; | ||
|
|
||
| beforeEach(async () => { | ||
| ({ aztecNode, aztecRpcServer, accounts, logger } = await setup(2)); | ||
| const { | ||
| aztecNode: aztecNode_, | ||
| aztecRpcServer: aztecRpcServer_, | ||
| deployL1ContractsValues, | ||
| accounts, | ||
| logger: logger_, | ||
| } = await setup(2); | ||
| crossChainTestHarness = await CrossChainTestHarness.new( | ||
| initialBalance, | ||
| aztecNode_, | ||
| aztecRpcServer_, | ||
| deployL1ContractsValues, | ||
| accounts, | ||
| logger_, | ||
| ); | ||
|
|
||
| ethAccount = crossChainTestHarness.ethAccount; | ||
| ownerAddress = crossChainTestHarness.ownerAddress; | ||
| underlyingERC20 = crossChainTestHarness.underlyingERC20; | ||
| aztecRpcServer = crossChainTestHarness.aztecRpcServer; | ||
| aztecNode = aztecNode_; | ||
|
|
||
| logger = logger_; | ||
| logger('Successfully deployed contracts and initialized portal'); | ||
| }, 100_000); | ||
|
|
||
| afterEach(async () => { | ||
| await aztecNode?.stop(); | ||
| await aztecRpcServer?.stop(); | ||
| await crossChainTestHarness?.stop(); | ||
| }); | ||
|
|
||
| const expectBalance = async (owner: AztecAddress, expectedBalance: bigint) => { | ||
| const ownerPublicKey = await aztecRpcServer.getAccountPublicKey(owner); | ||
| const [balance] = await contract.methods.getBalance(pointToPublicKey(ownerPublicKey)).view({ from: owner }); | ||
| logger(`Account ${owner} balance: ${balance}`); | ||
| expect(balance).toBe(expectedBalance); | ||
| }; | ||
|
|
||
| const deployContract = async () => { | ||
| logger(`Deploying Public to Private L2 contract...`); | ||
| const deployer = new ContractDeployer(PublicToPrivateContractAbi, aztecRpcServer); | ||
| const tx = deployer.deploy().send(); | ||
| const receipt = await tx.getReceipt(); | ||
| contract = new Contract(receipt.contractAddress!, PublicToPrivateContractAbi, aztecRpcServer); | ||
| await tx.isMined(0, 0.1); | ||
| await tx.getReceipt(); | ||
| logger('L2 contract deployed'); | ||
| return contract; | ||
| }; | ||
|
|
||
| /** | ||
| * Milestone 5.4: Intra-contract Public -\> Private calls. | ||
| */ | ||
| it('5.4: Should be able to create a commitment in a public function and spend in a private function', async () => { | ||
| const mintAmount = 100n; | ||
|
|
||
| const [owner, receiver] = accounts; | ||
|
|
||
| const deployedContract = await deployContract(); | ||
|
|
||
| // Create a secret for the transparent message | ||
| const secret = Fr.random(); | ||
| const secretHash = await computeMessageSecretHash(secret); | ||
| it('Milestone 5.4: Should be able to create a commitment in a public function and spend in a private function', async () => { | ||
| // Generate a claim secret using pedersen | ||
| const l1TokenBalance = 1000000n; | ||
| const bridgeAmount = 100n; | ||
| const shieldAmount = 50n; | ||
| const publicBalanceSlot = 2n; | ||
|
|
||
| // Create the commitment to be spent in the private domain | ||
| logger('Creating commitment in public call'); | ||
| const publicTx = deployedContract.methods.mintFromPublicToPrivate(mintAmount, secretHash).send({ from: receiver }); | ||
| const [secret, secretHash] = await crossChainTestHarness.generateClaimSecret(); | ||
|
|
||
| await publicTx.isMined(0, 0.1); | ||
| const publicReceipt = await publicTx.getReceipt(); | ||
| await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); | ||
| const messageKey = await crossChainTestHarness.sendTokensToPortal(bridgeAmount, secretHash); | ||
| expect(await underlyingERC20.read.balanceOf([ethAccount.toString()])).toBe(l1TokenBalance - bridgeAmount); | ||
|
|
||
| expect(publicReceipt.status).toBe(TxStatus.MINED); | ||
| // Wait for the archiver to process the message | ||
| await delay(5000); /// waiting 5 seconds. | ||
|
|
||
| // Create the transaction spending the commitment | ||
| logger('Spending commitment in private call'); | ||
| const privateTx = deployedContract.methods | ||
| .mintFromPublicMessage(mintAmount, secret, pointToPublicKey(await aztecRpcServer.getAccountPublicKey(owner))) | ||
| .send({ from: owner }); | ||
| // Perform another unrelated transaction on L2 to progress the rollup. | ||
| await crossChainTestHarness.expectBalanceOnL2(ownerAddress, initialBalance); | ||
| const transferAmount = 1n; | ||
| await crossChainTestHarness.performL2Transfer(transferAmount); | ||
| await crossChainTestHarness.expectBalanceOnL2(ownerAddress, initialBalance - transferAmount); | ||
|
|
||
| await crossChainTestHarness.consumeMessageOnAztecAndMintPublicly(bridgeAmount, messageKey, secret); | ||
| await crossChainTestHarness.expectPublicBalanceOnL2(ownerAddress, bridgeAmount, publicBalanceSlot); | ||
|
|
||
| await privateTx.isMined(); | ||
| const privateReceipt = await privateTx.getReceipt(); | ||
| // Create the commitment to be spent in the private domain | ||
| await crossChainTestHarness.shieldFundsOnL2(shieldAmount, secretHash); | ||
|
|
||
| expect(privateReceipt.status).toBe(TxStatus.MINED); | ||
| await expectBalance(owner, mintAmount); | ||
| }, 60_000); | ||
| // Create the transaction spending the commitment | ||
| await crossChainTestHarness.redeemShieldPrivatelyOnL2(shieldAmount, secret); | ||
| await crossChainTestHarness.expectPublicBalanceOnL2(ownerAddress, bridgeAmount - shieldAmount, publicBalanceSlot); | ||
| await crossChainTestHarness.expectBalanceOnL2(ownerAddress, initialBalance + shieldAmount - transferAmount); | ||
|
|
||
| // Unshield the tokens again, sending them to the same account, however this can be any account. | ||
| await crossChainTestHarness.unshieldTokensOnL2(shieldAmount); | ||
| await crossChainTestHarness.expectPublicBalanceOnL2(ownerAddress, bridgeAmount, publicBalanceSlot); | ||
| await crossChainTestHarness.expectBalanceOnL2(ownerAddress, initialBalance - transferAmount); | ||
| }, 120_000); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted later, this should handle the burning to not inflate.