Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sklppy88 committed Sep 3, 2024
1 parent e8a097c commit 149cc4c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 32 deletions.
2 changes: 1 addition & 1 deletion l1-contracts/src/core/FeeJuicePortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ contract FeeJuicePortal is IFeeJuicePortal, Ownable {

// Hash the message content to be reconstructed in the receiving contract
bytes32 contentHash =
Hash.sha256ToField(abi.encodeWithSignature("mint_public(bytes32,uint256)", _to, _amount));
Hash.sha256ToField(abi.encodeWithSignature("claim(bytes32,uint256)", _to, _amount));

// Hold the tokens in the portal
underlying.safeTransferFrom(msg.sender, address(this), _amount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ pub fn get_bridge_gas_msg_hash(owner: AztecAddress, amount: Field) -> Field {
hash_bytes[i + 36] = amount_bytes[i];
}

// Function selector: 0x3e87b9be keccak256('mint_public(bytes32,uint256)')
hash_bytes[0] = 0x3e;
hash_bytes[1] = 0x87;
hash_bytes[2] = 0xb9;
hash_bytes[3] = 0xbe;
// Function selector: 0x63f44968 keccak256('claim(bytes32,uint256)')
hash_bytes[0] = 0x63;
hash_bytes[1] = 0xf4;
hash_bytes[2] = 0x49;
hash_bytes[3] = 0x68;

let content_hash = sha256_to_field(hash_bytes);
content_hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,6 @@ contract FeeJuice {
storage.balances.at(to).write(new_balance);
}

// TODO(palla/gas) Remove this function and use the private claim flow only
#[aztec(public)]
fn claim_public(to: AztecAddress, amount: Field, secret: Field, leaf_index: Field) {
let content_hash = get_bridge_gas_msg_hash(to, amount);
let portal_address = storage.portal_address.read_public();
assert(!portal_address.is_zero());

// Consume message and emit nullifier
context.consume_l1_to_l2_message(content_hash, secret, portal_address, leaf_index);

let new_balance = storage.balances.at(to).read() + U128::from_integer(amount);
storage.balances.at(to).write(new_balance);
}

#[aztec(public)]
#[aztec(view)]
fn check_balance(fee_limit: Field) {
Expand Down
19 changes: 7 additions & 12 deletions yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ export class GasBridgingTestHarness implements IGasBridgingTestHarness {
return Fr.fromString(messageHash);
}

async consumeMessageOnAztecAndMintPublicly(bridgeAmount: bigint, owner: AztecAddress, secret: Fr, leafIndex: bigint) {
this.logger.info('Consuming messages on L2 Publicly');
// Call the mint tokens function on the Aztec.nr contract
await this.l2Token.methods.claim_public(owner, bridgeAmount, secret, leafIndex).send().wait();
async consumeMessageOnAztecAndMintPrivately(bridgeAmount: bigint, owner: AztecAddress, secret: Fr) {
this.logger.info('Consuming messages on L2 Privately');
// Call the claim function on the Aztec.nr Fee Juice contract
await this.l2Token.methods.claim(owner, bridgeAmount, secret).send().wait();
}

async getL2PublicBalanceOf(owner: AztecAddress) {
Expand Down Expand Up @@ -211,15 +211,10 @@ export class GasBridgingTestHarness implements IGasBridgingTestHarness {

async bridgeFromL1ToL2(l1TokenBalance: bigint, bridgeAmount: bigint, owner: AztecAddress) {
// Prepare the tokens on the L1 side
const { secret, msgHash } = await this.prepareTokensOnL1(l1TokenBalance, bridgeAmount, owner);
const { secret } = await this.prepareTokensOnL1(l1TokenBalance, bridgeAmount, owner);

// Get message leaf index, needed for claiming in public
const maybeIndexAndPath = await this.aztecNode.getL1ToL2MessageMembershipWitness('latest', msgHash, 0n);
expect(maybeIndexAndPath).toBeDefined();
const messageLeafIndex = maybeIndexAndPath![0];

// Consume L1-> L2 message and mint public tokens on L2
await this.consumeMessageOnAztecAndMintPublicly(bridgeAmount, owner, secret, messageLeafIndex);
// Consume L1-> L2 message and mint tokens privately on L2
await this.consumeMessageOnAztecAndMintPrivately(bridgeAmount, owner, secret);
await this.expectPublicBalanceOnL2(owner, bridgeAmount);
}
}
Expand Down

0 comments on commit 149cc4c

Please sign in to comment.