diff --git a/yarn-project/aztec.js/src/contract/get_gas_limits.test.ts b/yarn-project/aztec.js/src/contract/get_gas_limits.test.ts index 8a25b836e375..610d0f0e51e6 100644 --- a/yarn-project/aztec.js/src/contract/get_gas_limits.test.ts +++ b/yarn-project/aztec.js/src/contract/get_gas_limits.test.ts @@ -15,6 +15,8 @@ describe('getGasLimits', () => { txSimulationResult.publicOutput!.gasUsed = { totalGas: Gas.from({ daGas: 140, l2Gas: 280 }), + // Assume teardown gas limit of 20, 30 + billedGas: Gas.from({ daGas: 150, l2Gas: 290 }), teardownGas: Gas.from({ daGas: 10, l2Gas: 20 }), publicGas: Gas.from({ daGas: 50, l2Gas: 200 }), }; diff --git a/yarn-project/circuit-types/src/mocks.ts b/yarn-project/circuit-types/src/mocks.ts index 68710913c229..232de1087914 100644 --- a/yarn-project/circuit-types/src/mocks.ts +++ b/yarn-project/circuit-types/src/mocks.ts @@ -176,6 +176,7 @@ export const mockSimulatedTx = async (seed = 1) => { totalGas: makeGas(), teardownGas: makeGas(), publicGas: makeGas(), + billedGas: makeGas(), }, ); return new TxSimulationResult(privateExecutionResult, tx.data, output); diff --git a/yarn-project/circuit-types/src/test/factories.ts b/yarn-project/circuit-types/src/test/factories.ts index 44715bb1f648..a8647ff85c9d 100644 --- a/yarn-project/circuit-types/src/test/factories.ts +++ b/yarn-project/circuit-types/src/test/factories.ts @@ -124,6 +124,7 @@ export async function makeBloatedProcessedTx({ totalGas: Gas.empty(), teardownGas: Gas.empty(), publicGas: Gas.empty(), + billedGas: Gas.empty(), } satisfies GasUsed; return makeProcessedTxFromTxWithPublicCalls( diff --git a/yarn-project/circuit-types/src/tx/gas_used.ts b/yarn-project/circuit-types/src/tx/gas_used.ts index ceb145467fc1..944f10ec236f 100644 --- a/yarn-project/circuit-types/src/tx/gas_used.ts +++ b/yarn-project/circuit-types/src/tx/gas_used.ts @@ -3,16 +3,21 @@ import { type Gas } from '@aztec/circuits.js'; export interface GasUsed { /** * Total gas used across both private and public executions. - * Note that this does not determine the transaction fee. The fee is calculated using `teardownGasLimits` from + * Note that this does not determine the transaction fee. The fee is calculated with billedGas, which uses `teardownGasLimits` from * `GasSettings`, rather than actual teardown gas. */ totalGas: Gas; - /** Total gas used during public execution, including teardown gas */ + /** Total gas used during public execution, including actual teardown gas */ publicGas: Gas; /** * The actual gas used in the teardown phase. */ teardownGas: Gas; + + /** + * The gas billed for the transaction. This uses teardown gas limit instead of actual teardown gas. + */ + billedGas: Gas; } diff --git a/yarn-project/circuit-types/src/tx/processed_tx.ts b/yarn-project/circuit-types/src/tx/processed_tx.ts index 1272594371fc..3cbd89b4bfe0 100644 --- a/yarn-project/circuit-types/src/tx/processed_tx.ts +++ b/yarn-project/circuit-types/src/tx/processed_tx.ts @@ -102,7 +102,9 @@ export async function makeProcessedTxFromPrivateOnlyTx( ); const gasUsed = { + // Billed gas is the same as total gas since there is no teardown execution totalGas: tx.data.gasUsed, + billedGas: tx.data.gasUsed, teardownGas: Gas.empty(), publicGas: Gas.empty(), } satisfies GasUsed; diff --git a/yarn-project/circuit-types/src/tx/public_simulation_output.ts b/yarn-project/circuit-types/src/tx/public_simulation_output.ts index 0994cfcb92d3..18b4a5c79faa 100644 --- a/yarn-project/circuit-types/src/tx/public_simulation_output.ts +++ b/yarn-project/circuit-types/src/tx/public_simulation_output.ts @@ -61,7 +61,12 @@ export class PublicSimulationOutput { constants: CombinedConstantData.schema, txEffect: TxEffect.schema, publicReturnValues: z.array(NestedProcessReturnValues.schema), - gasUsed: z.object({ totalGas: Gas.schema, teardownGas: Gas.schema, publicGas: Gas.schema }), + gasUsed: z.object({ + totalGas: Gas.schema, + teardownGas: Gas.schema, + publicGas: Gas.schema, + billedGas: Gas.schema, + }), }) .transform( fields => @@ -81,7 +86,7 @@ export class PublicSimulationOutput { CombinedConstantData.empty(), TxEffect.empty(), times(2, NestedProcessReturnValues.random), - { teardownGas: Gas.random(), totalGas: Gas.random(), publicGas: Gas.random() }, + { teardownGas: Gas.random(), totalGas: Gas.random(), publicGas: Gas.random(), billedGas: Gas.random() }, ); } } diff --git a/yarn-project/circuit-types/src/tx/simulated_tx.ts b/yarn-project/circuit-types/src/tx/simulated_tx.ts index b68a90ab53b7..de3921ca381c 100644 --- a/yarn-project/circuit-types/src/tx/simulated_tx.ts +++ b/yarn-project/circuit-types/src/tx/simulated_tx.ts @@ -59,6 +59,7 @@ export class TxSimulationResult extends PrivateSimulationResult { return ( this.publicOutput?.gasUsed ?? { totalGas: this.publicInputs.gasUsed, + billedGas: this.publicInputs.gasUsed, teardownGas: Gas.empty(), publicGas: Gas.empty(), } diff --git a/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts b/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts index 03de06a137c1..bb525b83f979 100644 --- a/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts +++ b/yarn-project/prover-client/src/orchestrator/block-building-helpers.ts @@ -344,7 +344,7 @@ export const buildHeaderAndBodyFromTxs = runInSpan( const contentCommitment = new ContentCommitment(new Fr(numTxs), blobsHash, parityShaRoot, outHash); const fees = body.txEffects.reduce((acc, tx) => acc.add(tx.transactionFee), Fr.ZERO); - const manaUsed = txs.reduce((acc, tx) => acc.add(new Fr(tx.gasUsed.totalGas.l2Gas)), Fr.ZERO); + const manaUsed = txs.reduce((acc, tx) => acc.add(new Fr(tx.gasUsed.billedGas.l2Gas)), Fr.ZERO); const header = new BlockHeader(previousArchive, contentCommitment, stateReference, globalVariables, fees, manaUsed); diff --git a/yarn-project/simulator/src/public/public_processor.test.ts b/yarn-project/simulator/src/public/public_processor.test.ts index 8f9bedb015f7..f22b9ae5b57f 100644 --- a/yarn-project/simulator/src/public/public_processor.test.ts +++ b/yarn-project/simulator/src/public/public_processor.test.ts @@ -67,6 +67,7 @@ describe('public_processor', () => { totalGas: Gas.empty(), teardownGas: Gas.empty(), publicGas: Gas.empty(), + billedGas: Gas.empty(), }, revertCode: RevertCode.OK, processedPhases: [], diff --git a/yarn-project/simulator/src/public/public_tx_simulator.test.ts b/yarn-project/simulator/src/public/public_tx_simulator.test.ts index bde8d830956a..e6f7713c899a 100644 --- a/yarn-project/simulator/src/public/public_tx_simulator.test.ts +++ b/yarn-project/simulator/src/public/public_tx_simulator.test.ts @@ -333,6 +333,7 @@ describe('public_tx_simulator', () => { const expectedTotalGas = privateGasUsed.add(expectedPublicGasUsed); expect(txResult.gasUsed).toEqual({ totalGas: expectedTotalGas, + billedGas: expectedTotalGas, teardownGas: Gas.empty(), publicGas: expectedPublicGasUsed, }); @@ -369,6 +370,7 @@ describe('public_tx_simulator', () => { const expectedTotalGas = privateGasUsed.add(expectedPublicGasUsed); expect(txResult.gasUsed).toEqual({ totalGas: expectedTotalGas, + billedGas: expectedTotalGas, teardownGas: Gas.empty(), publicGas: expectedPublicGasUsed, }); @@ -403,8 +405,10 @@ describe('public_tx_simulator', () => { const expectedTeardownGasUsed = enqueuedCallGasUsed; const expectedTotalGas = privateGasUsed.add(expectedTeardownGasUsed); + const expectedBilledGas = privateGasUsed.add(teardownGasLimits); expect(txResult.gasUsed).toEqual({ totalGas: expectedTotalGas, + billedGas: expectedBilledGas, teardownGas: expectedTeardownGasUsed, publicGas: expectedTeardownGasUsed, }); @@ -443,8 +447,11 @@ describe('public_tx_simulator', () => { const expectedPublicGasUsed = enqueuedCallGasUsed.mul(3); // 2 for setup and 1 for app logic. const expectedTeardownGasUsed = enqueuedCallGasUsed; const expectedTotalGas = privateGasUsed.add(expectedPublicGasUsed).add(expectedTeardownGasUsed); + const expectedBilledGas = privateGasUsed.add(expectedPublicGasUsed).add(teardownGasLimits); + expect(txResult.gasUsed).toEqual({ totalGas: expectedTotalGas, + billedGas: expectedBilledGas, teardownGas: expectedTeardownGasUsed, publicGas: expectedPublicGasUsed.add(expectedTeardownGasUsed), }); @@ -593,8 +600,10 @@ describe('public_tx_simulator', () => { const expectedAppLogicGas = enqueuedCallGasUsed.mul(2); const expectedTeardownGasUsed = enqueuedCallGasUsed; const expectedTotalGas = privateGasUsed.add(expectedSetupGas).add(expectedAppLogicGas).add(expectedTeardownGasUsed); + const expectedBilledGas = privateGasUsed.add(expectedSetupGas).add(expectedAppLogicGas).add(teardownGasLimits); expect(txResult.gasUsed).toEqual({ totalGas: expectedTotalGas, + billedGas: expectedBilledGas, teardownGas: expectedTeardownGasUsed, publicGas: expectedTotalGas.sub(privateGasUsed), }); @@ -675,8 +684,10 @@ describe('public_tx_simulator', () => { const expectedAppLogicGas = enqueuedCallGasUsed.mul(2); const expectedTeardownGasUsed = enqueuedCallGasUsed; const expectedTotalGas = privateGasUsed.add(expectedSetupGas).add(expectedAppLogicGas).add(expectedTeardownGasUsed); + const expectedBilledGas = privateGasUsed.add(expectedSetupGas).add(expectedAppLogicGas).add(teardownGasLimits); expect(txResult.gasUsed).toEqual({ totalGas: expectedTotalGas, + billedGas: expectedBilledGas, teardownGas: expectedTeardownGasUsed, publicGas: expectedTotalGas.sub(privateGasUsed), }); @@ -759,8 +770,10 @@ describe('public_tx_simulator', () => { const expectedAppLogicGas = enqueuedCallGasUsed.mul(2); const expectedTeardownGasUsed = enqueuedCallGasUsed; const expectedTotalGas = privateGasUsed.add(expectedSetupGas).add(expectedAppLogicGas).add(expectedTeardownGasUsed); + const expectedBilledGas = privateGasUsed.add(expectedSetupGas).add(expectedAppLogicGas).add(teardownGasLimits); expect(txResult.gasUsed).toEqual({ totalGas: expectedTotalGas, + billedGas: expectedBilledGas, teardownGas: expectedTeardownGasUsed, publicGas: expectedTotalGas.sub(privateGasUsed), }); @@ -900,8 +913,10 @@ describe('public_tx_simulator', () => { const expectedPublicGasUsed = enqueuedCallGasUsed.mul(2); // 1 for setup and 1 for app logic. const expectedTeardownGasUsed = enqueuedCallGasUsed; const expectedTotalGas = privateGasUsed.add(expectedPublicGasUsed).add(expectedTeardownGasUsed); + const expectedBilledGas = privateGasUsed.add(expectedPublicGasUsed).add(teardownGasLimits); expect(txResult.gasUsed).toEqual({ totalGas: expectedTotalGas, + billedGas: expectedBilledGas, teardownGas: expectedTeardownGasUsed, publicGas: expectedPublicGasUsed.add(expectedTeardownGasUsed), }); diff --git a/yarn-project/simulator/src/public/public_tx_simulator.ts b/yarn-project/simulator/src/public/public_tx_simulator.ts index 371b6db33277..a03f3c7b3e4f 100644 --- a/yarn-project/simulator/src/public/public_tx_simulator.ts +++ b/yarn-project/simulator/src/public/public_tx_simulator.ts @@ -138,6 +138,7 @@ export class PublicTxSimulator { totalGas: context.getActualGasUsed(), teardownGas: context.teardownGasUsed, publicGas: context.getActualPublicGasUsed(), + billedGas: context.getTotalGasUsed(), }, revertCode, revertReason: context.revertReason,