Skip to content
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

fix #741 and #646 #772

Merged
merged 3 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ describe('Private Execution test suite', () => {
const secret = new Fr(1n);
const preimage = await buildL1ToL2Message([new Fr(bridgedAmount), new Fr(recipient.x)], contractAddress, secret);

const messageKey = preimage.hash();
// stub message key
const messageKey = Fr.random();
LHerskind marked this conversation as resolved.
Show resolved Hide resolved

const tree: AppendOnlyTree = await newTree(
StandardTree,
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './contract/index.js';
export * from './contract_deployer/index.js';
export * from './utils/index.js';

// TODO - only export necessary stuffs
export * from '@aztec/aztec-rpc';
1 change: 1 addition & 0 deletions yarn-project/aztec.js/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './secrets.js';
12 changes: 12 additions & 0 deletions yarn-project/aztec.js/src/utils/secrets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { CircuitsWasm, Fr } from '@aztec/circuits.js';
import { computeSecretMessageHash } from '@aztec/circuits.js/abis';

/**
* Given a secret, it computes its pedersen hash - used to send l1 to l2 messages
* @param secret - the secret to hash - secret could be generated however you want e.g. `Fr.random()`
* @returns the hash
*/
export async function computeMessageSecretHash(secret: Fr): Promise<Fr> {
const wasm = await CircuitsWasm.get();
return computeSecretMessageHash(wasm, secret);
}
12 changes: 4 additions & 8 deletions yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { AztecNodeService } from '@aztec/aztec-node';
import { AztecAddress, AztecRPCServer, Contract, TxStatus } from '@aztec/aztec.js';
import { AztecAddress, AztecRPCServer, Contract, TxStatus, computeMessageSecretHash } from '@aztec/aztec.js';
import { EthAddress } from '@aztec/foundation/eth-address';

import { CircuitsWasm } from '@aztec/circuits.js';
import { computeSecretMessageHash } from '@aztec/circuits.js/abis';
import { DeployL1Contracts } from '@aztec/ethereum';
import { toBigIntBE, toBufferBE } from '@aztec/foundation/bigint-buffer';
import { Fr } from '@aztec/foundation/fields';
Expand Down Expand Up @@ -88,12 +86,11 @@ describe('e2e_cross_chain_messaging', () => {

it('Milestone 2: Deposit funds from L1 -> L2 and withdraw back to L1', async () => {
// Generate a claim secret using pedersen
// TODO (#741): make this into an aztec.js utility function
logger("Generating a claim secret using pedersen's hash function");
const wasm = await CircuitsWasm.get();
const secret = Fr.random();
const claimSecretHash = computeSecretMessageHash(wasm, secret);
logger('Generated claim secret: ', claimSecretHash.toString());
const secretHash = await computeMessageSecretHash(secret);
const secretString = `0x${secretHash.toBuffer().toString('hex')}` as `0x${string}`;
logger('Generated claim secret: ', secretString);

logger('Minting tokens on L1');
await underlyingERC20.write.mint([ethAccount.toString(), 1000000n], {} as any);
Expand All @@ -102,7 +99,6 @@ describe('e2e_cross_chain_messaging', () => {
expect(await underlyingERC20.read.balanceOf([ethAccount.toString()])).toBe(1000000n);

// Deposit tokens to the TokenPortal
const secretString = `0x${claimSecretHash.toBuffer().toString('hex')}` as `0x${string}`;
const deadline = 2 ** 32 - 1; // max uint32 - 1

const mintAmount = 100n;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
import { AztecAddress, AztecRPCServer, Contract } from '@aztec/aztec.js';
import { AztecAddress, AztecRPCServer, Contract, computeMessageSecretHash } from '@aztec/aztec.js';
import { EthAddress } from '@aztec/foundation/eth-address';

import { CircuitsWasm } from '@aztec/circuits.js';
import { computeSecretMessageHash } from '@aztec/circuits.js/abis';
import { DeployL1Contracts } from '@aztec/ethereum';
import { Fr } from '@aztec/foundation/fields';
import { DebugLogger } from '@aztec/foundation/log';
Expand Down Expand Up @@ -84,12 +82,11 @@ describe('archiver integration with l1 to l2 messages', () => {
// create a message, then cancel it

// Generate a claim secret using pedersen
// TODO (#741): make this into an aztec.js utility function
logger("Generating a claim secret using pedersen's hash function");
const wasm = await CircuitsWasm.get();
const secret = Fr.random();
const claimSecretHash = computeSecretMessageHash(wasm, secret);
logger('Generated claim secret: ', claimSecretHash.toString());
const secretHash = await computeMessageSecretHash(secret);
const secretString = `0x${secretHash.toBuffer().toString('hex')}` as `0x${string}`;
logger('Generated claim secret: ', secretString);

logger('Minting tokens on L1');
await underlyingERC20.write.mint([ethAccount.toString(), 1000000n], {} as any);
Expand All @@ -98,7 +95,6 @@ describe('archiver integration with l1 to l2 messages', () => {
expect(await underlyingERC20.read.balanceOf([ethAccount.toString()])).toBe(1000000n);

// Deposit tokens to the TokenPortal
const secretString = `0x${claimSecretHash.toBuffer().toString('hex')}` as `0x${string}`;
const deadline = Number((await publicClient.getBlock()).timestamp + 1000n);
const mintAmount = 100n;

Expand Down
9 changes: 0 additions & 9 deletions yarn-project/types/src/l1_to_l2_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { EthAddress } from '@aztec/foundation/eth-address';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, serializeToBuffer } from '@aztec/circuits.js/utils';
import { sha256 } from '@aztec/foundation/crypto';
import { toBigIntBE, toBufferBE } from '@aztec/foundation/bigint-buffer';

/**
* Interface of classes allowing for the retrieval of L1 to L2 messages.
Expand Down Expand Up @@ -74,13 +72,6 @@ export class L1ToL2Message {
public readonly entryKey?: Fr,
) {}

// TODO: (#646) - sha256 hash of the message packed the same as solidity
hash(): Fr {
const buf = this.toBuffer();
const temp = toBigIntBE(sha256(buf));
return Fr.fromBuffer(toBufferBE(temp % Fr.MODULUS, 32));
}

/**
* Returns each element within its own field so that it can be consumed by an acvm oracle call.
* @returns The message as an array of fields (in order).
Expand Down