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: Calculate tx fee using current constants in public kernel #6066

Merged
merged 1 commit into from
Apr 26, 2024
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 @@ -32,11 +32,11 @@ impl PublicKernelTeardownCircuitPrivateInputs {
}

// Validates the transaction fee injected into the app circuit is properly computed from gas_used and block gas_fees
fn validate_transaction_fee(self) {
fn validate_transaction_fee(self, public_inputs: PublicKernelCircuitPublicInputsBuilder) {
let transaction_fee = self.public_call.call_stack_item.public_inputs.transaction_fee;
// Note that teardown_gas is already included in end.gas_used as it was injected by the private kernel
let total_gas_used = self.previous_kernel.public_inputs.end.gas_used.add(self.previous_kernel.public_inputs.end_non_revertible.gas_used);
let block_gas_fees = self.previous_kernel.public_inputs.constants.global_variables.gas_fees;
let block_gas_fees = public_inputs.constants.global_variables.gas_fees;
let inclusion_fee = self.previous_kernel.public_inputs.constants.tx_context.gas_settings.inclusion_fee;
let computed_transaction_fee = total_gas_used.compute_fee(block_gas_fees) + inclusion_fee;

Expand Down Expand Up @@ -84,7 +84,7 @@ impl PublicKernelTeardownCircuitPrivateInputs {
common::validate_call_against_request(self.public_call, call_request);

self.validate_start_gas();
self.validate_transaction_fee();
self.validate_transaction_fee(public_inputs);

common::update_validation_requests(self.public_call, &mut public_inputs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ describe('benchmarks/tx_size_fees', () => {
await token.methods.mint_public(aliceWallet.getAddress(), 100e9).send().wait();
});

it.each<() => Promise<FeePaymentMethod | undefined>>([
() => Promise.resolve(undefined),
() => NativeFeePaymentMethod.create(aliceWallet),
() => Promise.resolve(new PublicFeePaymentMethod(token.address, fpc.address, aliceWallet)),
() => Promise.resolve(new PrivateFeePaymentMethod(token.address, fpc.address, aliceWallet)),
])('sends a tx with a fee', async createPaymentMethod => {
it.each<[string, () => Promise<FeePaymentMethod | undefined>]>([
['no', () => Promise.resolve(undefined)],
['native fee', () => NativeFeePaymentMethod.create(aliceWallet)],
['public fee', () => Promise.resolve(new PublicFeePaymentMethod(token.address, fpc.address, aliceWallet))],
['private fee', () => Promise.resolve(new PrivateFeePaymentMethod(token.address, fpc.address, aliceWallet))],
] as const)('sends a tx with a fee with %s payment method', async (_name, createPaymentMethod) => {
const paymentMethod = await createPaymentMethod();
const gasSettings = GasSettings.default();
const tx = await token.methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ export class SimpleTestGlobalVariableBuilder implements GlobalVariableBuilder {
lastTimestamp = new Fr(lastTimestamp.value + 1n);
}

this.log.debug(
`Built global variables for block ${blockNumber}: (${chainId}, ${version}, ${blockNumber}, ${lastTimestamp}, ${coinbase}, ${feeRecipient})`,
);

const gasFees = GasFees.default();
const globalVariables = new GlobalVariables(
chainId,
version,
blockNumber,
lastTimestamp,
coinbase,
feeRecipient,
gasFees,
);
this.log.debug(`Built global variables for block ${blockNumber}`, globalVariables.toJSON());
return new GlobalVariables(chainId, version, blockNumber, lastTimestamp, coinbase, feeRecipient, gasFees);
}
}
Loading