Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 16, 2025
1 parent a3c255f commit 9ef07b3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ pub fn calculate_fee<TPublicContext>(context: PublicContext) -> Field {
context.transaction_fee()
}

pub fn get_bridge_gas_msg_hash(owner: AztecAddress, amount: Field) -> Field {
pub fn get_bridge_gas_msg_hash(owner: AztecAddress, amount: U128) -> Field {
let mut hash_bytes = [0; 68];
let recipient_bytes: [u8; 32] = owner.to_field().to_be_bytes();
let amount_bytes: [u8; 32] = amount.to_be_bytes();
let amount_bytes: [u8; 32] = amount.to_field().to_be_bytes();

// The purpose of including the following selector is to make the message unique to that specific call. Note that
// it has nothing to do with calling the function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract FeeJuice {
// Not flagged as initializer to reduce cost of checking init nullifier in all functions.
// This function should be called as entrypoint to initialize the contract by minting itself funds.
#[private]
fn initialize(portal_address: EthAddress, initial_mint: Field) {
fn initialize(portal_address: EthAddress, initial_mint: U128) {
// Validate contract class parameters are correct
let self = context.this_address();

Expand All @@ -46,7 +46,7 @@ contract FeeJuice {
}

#[private]
fn claim(to: AztecAddress, amount: Field, secret: Field, message_leaf_index: Field) {
fn claim(to: AztecAddress, amount: U128, secret: Field, message_leaf_index: Field) {
let content_hash = get_bridge_gas_msg_hash(to, amount);
let portal_address = storage.portal_address.read();
assert(!portal_address.is_zero());
Expand All @@ -63,22 +63,21 @@ contract FeeJuice {

#[public]
#[internal]
fn _increase_public_balance(to: AztecAddress, amount: Field) {
let new_balance = storage.balances.at(to).read().add(U128::from_integer(amount));
fn _increase_public_balance(to: AztecAddress, amount: U128) {
let new_balance = storage.balances.at(to).read().add(amount);
storage.balances.at(to).write(new_balance);
}

#[public]
#[view]
fn check_balance(fee_limit: Field) {
let fee_limit = U128::from_integer(fee_limit);
fn check_balance(fee_limit: U128) {
assert(storage.balances.at(context.msg_sender()).read() >= fee_limit, "Balance too low");
}

// utility function for testing
#[public]
#[view]
fn balance_of_public(owner: AztecAddress) -> pub Field {
storage.balances.at(owner).read().to_field()
fn balance_of_public(owner: AztecAddress) -> pub U128 {
storage.balances.at(owner).read()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ contract PriceFeed {
}

#[public]
fn set_price(asset_id: Field, price: Field) {
fn set_price(asset_id: Field, price: U128) {
let asset = storage.assets.at(asset_id);
asset.write(Asset { price: U128::from_integer(price) });
asset.write(Asset { price });
}

#[public]
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/sequencer-client/src/sequencer/allowed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export function getDefaultAllowedSetupFunctions(): AllowedElement[] {
{
address: ProtocolContractAddress.FeeJuice,
// We can't restrict the selector because public functions get routed via dispatch.
// selector: FunctionSelector.fromSignature('_increase_public_balance((Field),Field)'),
// selector: FunctionSelector.fromSignature('_increase_public_balance((Field),(Field,Field))'),
},
// needed for private transfers via FPC
{
classId: getContractClassFromArtifact(TokenContractArtifact).id,
// We can't restrict the selector because public functions get routed via dispatch.
// selector: FunctionSelector.fromSignature('_increase_public_balance((Field),Field)'),
// selector: FunctionSelector.fromSignature('_increase_public_balance((Field),(Field,Field))'),
},
{
classId: getContractClassFromArtifact(FPCContract.artifact).id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('GasTxValidator', () => {

it('allows fee paying txs if fee payer claims enough balance during setup', async () => {
mockBalance(feeLimit - 1n);
const selector = FunctionSelector.fromSignature('_increase_public_balance((Field),Field)');
const selector = FunctionSelector.fromSignature('_increase_public_balance((Field),(Field,Field))');
patchNonRevertibleFn(tx, 0, {
address: ProtocolContractAddress.FeeJuice,
selector: FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)),
Expand All @@ -90,7 +90,7 @@ describe('GasTxValidator', () => {
it('rejects txs if fee payer claims balance outside setup', async () => {
mockBalance(feeLimit - 1n);
patchRevertibleFn(tx, 0, {
selector: FunctionSelector.fromSignature('_increase_public_balance((Field),Field)'),
selector: FunctionSelector.fromSignature('_increase_public_balance((Field),(Field,Field))'),
args: [payer.toField(), new Fr(1n)],
});
await expectInvalid(tx, 'Insufficient fee payer balance');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ export class GasTxValidator implements TxValidator<Tx> {
fn.callContext.msgSender.equals(this.#feeJuiceAddress) &&
fn.args.length > 2 &&
// Public functions get routed through the dispatch function, whose first argument is the target function selector.
fn.args[0].equals(FunctionSelector.fromSignature('_increase_public_balance((Field),Field)').toField()) &&
fn.args[0].equals(
FunctionSelector.fromSignature('_increase_public_balance((Field),(Field,Field))').toField(),
) &&
fn.args[1].equals(feePayer.toField()) &&
!fn.callContext.isStaticCall,
);
Expand Down

0 comments on commit 9ef07b3

Please sign in to comment.