Skip to content

Commit afe7c0e

Browse files
committed
feat: include transaction fee in txreceipt
1 parent 7c29644 commit afe7c0e

File tree

13 files changed

+199
-49
lines changed

13 files changed

+199
-49
lines changed

noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub fn update_non_revertible_gas_used(public_call: PublicCallData, circuit_outpu
232232
let accum_end_gas_used = circuit_outputs.end.gas_used;
233233

234234
// dep::types::debug_log::debug_log_format(
235-
// "Updating non-revertible gas: limit.da={0} limit.l1={1} limit.l2={2} left.da={3} left.l1={4} left.l2={5} used.da={6} used.l1={7} used.l2={8}",
235+
// "Updating non-revertible gas: limit.da={0} limit.l2={1} left.da={2} left.l2={3} used.da={4} used.l2={5}",
236236
// [
237237
// tx_gas_limits.da_gas as Field,
238238
// tx_gas_limits.l2_gas as Field,
@@ -243,10 +243,6 @@ pub fn update_non_revertible_gas_used(public_call: PublicCallData, circuit_outpu
243243
// ]
244244
// );
245245

246-
// println(
247-
// f"Updating non-revertible gas: tx_gas_limits={tx_gas_limits} call_gas_left={call_gas_left} accum_end_gas_used={accum_end_gas_used}"
248-
// );
249-
250246
circuit_outputs.end_non_revertible.gas_used = tx_gas_limits
251247
.sub(call_gas_left)
252248
.sub(accum_end_gas_used);

noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,19 @@ impl PublicKernelTeardownCircuitPrivateInputs {
3535
fn validate_transaction_fee(self, public_inputs: PublicKernelCircuitPublicInputsBuilder) {
3636
let transaction_fee = self.public_call.call_stack_item.public_inputs.transaction_fee;
3737
// Note that teardown_gas is already included in end.gas_used as it was injected by the private kernel
38-
let total_gas_used = self.previous_kernel.public_inputs.end.gas_used.add(self.previous_kernel.public_inputs.end_non_revertible.gas_used);
38+
let total_gas_used = self.previous_kernel.public_inputs.end.gas_used
39+
+ self.previous_kernel.public_inputs.end_non_revertible.gas_used;
3940
let block_gas_fees = public_inputs.constants.global_variables.gas_fees;
4041
let inclusion_fee = self.previous_kernel.public_inputs.constants.tx_context.gas_settings.inclusion_fee;
4142
let computed_transaction_fee = total_gas_used.compute_fee(block_gas_fees) + inclusion_fee;
4243

4344
// dep::types::debug_log::debug_log_format(
44-
// "Validating tx fee: total_gas_used.da={0} total_gas_used.l1={1} total_gas_used.l2={2} block_fee_per_gas.da={3} block_fee_per_gas.l1={4} block_fee_per_gas.l2={5} inclusion_fee={6} computed={7} actual={8}",
45+
// "Validating tx fee: end.gas_used.da={0} end.gas_used.l2={1} non_revertible.gas_used.da={2} non_revertible.gas_used.l2={3} block_fee_per_gas.da={4} block_fee_per_gas.l2={5} inclusion_fee={6} computed={7} actual={8}",
4546
// [
46-
// total_gas_used.da_gas as Field,
47-
// total_gas_used.l2_gas as Field,
47+
// self.previous_kernel.public_inputs.end.gas_used.da_gas as Field,
48+
// self.previous_kernel.public_inputs.end.gas_used.l2_gas as Field,
49+
// self.previous_kernel.public_inputs.end_non_revertible.gas_used.da_gas as Field,
50+
// self.previous_kernel.public_inputs.end_non_revertible.gas_used.l2_gas as Field,
4851
// block_gas_fees.fee_per_da_gas as Field,
4952
// block_gas_fees.fee_per_l2_gas as Field,
5053
// inclusion_fee,

noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl CombinedAccumulatedData {
5959
non_revertible.public_data_update_requests,
6060
revertible.public_data_update_requests
6161
),
62-
gas_used: revertible.gas_used.add(non_revertible.gas_used)
62+
gas_used: revertible.gas_used + non_revertible.gas_used
6363
}
6464
}
6565
}

yarn-project/archiver/src/archiver/kv_archiver_store/block_store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export class BlockStore {
140140
txHash,
141141
tx.revertCode.isOK() ? TxStatus.MINED : TxStatus.REVERTED,
142142
'',
143+
tx.transactionFee.toBigInt(),
143144
block.hash().toBuffer(),
144145
block.number,
145146
);

yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import {
2+
ExtendedUnencryptedL2Log,
3+
LogId,
4+
LogType,
5+
TxReceipt,
6+
TxStatus,
27
type Body,
38
type EncryptedL2BlockL2Logs,
4-
ExtendedUnencryptedL2Log,
59
type FromLogType,
610
type GetUnencryptedLogsResponse,
711
type InboxLeaf,
812
type L2Block,
913
type L2BlockL2Logs,
1014
type LogFilter,
11-
LogId,
12-
LogType,
1315
type TxEffect,
1416
type TxHash,
15-
TxReceipt,
16-
TxStatus,
1717
type UnencryptedL2BlockL2Logs,
1818
} from '@aztec/circuit-types';
1919
import { Fr, INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js';
@@ -266,10 +266,18 @@ export class MemoryArchiverStore implements ArchiverDataStore {
266266
*/
267267
public getSettledTxReceipt(txHash: TxHash): Promise<TxReceipt | undefined> {
268268
for (const block of this.l2Blocks) {
269-
const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash);
270-
for (const currentTxHash of txHashes) {
271-
if (currentTxHash.equals(txHash)) {
272-
return Promise.resolve(new TxReceipt(txHash, TxStatus.MINED, '', block.hash().toBuffer(), block.number));
269+
for (const txEffect of block.body.txEffects) {
270+
if (txEffect.txHash.equals(txHash)) {
271+
return Promise.resolve(
272+
new TxReceipt(
273+
txHash,
274+
TxStatus.MINED,
275+
'',
276+
txEffect.transactionFee.toBigInt(),
277+
block.hash().toBuffer(),
278+
block.number,
279+
),
280+
);
273281
}
274282
}
275283
}

yarn-project/circuit-types/src/tx/tx_receipt.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export class TxReceipt {
3232
* Description of transaction error, if any.
3333
*/
3434
public error: string,
35+
/**
36+
* The transaction fee paid for the transaction.
37+
*/
38+
public transactionFee?: bigint,
3539
/**
3640
* The hash of the block containing the transaction.
3741
*/
@@ -69,9 +73,10 @@ export class TxReceipt {
6973
const txHash = TxHash.fromString(obj.txHash);
7074
const status = obj.status as TxStatus;
7175
const error = obj.error;
76+
const transactionFee = obj.transactionFee;
7277
const blockHash = obj.blockHash ? Buffer.from(obj.blockHash, 'hex') : undefined;
7378
const blockNumber = obj.blockNumber ? Number(obj.blockNumber) : undefined;
74-
return new TxReceipt(txHash, status, error, blockHash, blockNumber);
79+
return new TxReceipt(txHash, status, error, transactionFee, blockHash, blockNumber);
7580
}
7681
}
7782

yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { makeTuple } from '@aztec/foundation/array';
22
import { Fr } from '@aztec/foundation/fields';
33
import { BufferReader, type Tuple, serializeToBuffer } from '@aztec/foundation/serialize';
44

5+
import { inspect } from 'util';
6+
57
import {
68
type MAX_NEW_L2_TO_L1_MSGS_PER_CALL,
79
MAX_NEW_L2_TO_L1_MSGS_PER_TX,
@@ -116,4 +118,30 @@ export class CombinedAccumulatedData {
116118
Gas.empty(),
117119
);
118120
}
121+
122+
[inspect.custom]() {
123+
return `CombinedAccumulatedData {
124+
newNoteHashes: [${this.newNoteHashes
125+
.filter(x => !x.isZero())
126+
.map(x => inspect(x))
127+
.join(', ')}],
128+
newNullifiers: [${this.newNullifiers
129+
.filter(x => !x.isZero())
130+
.map(x => inspect(x))
131+
.join(', ')}],
132+
newL2ToL1Msgs: [${this.newL2ToL1Msgs
133+
.filter(x => !x.isZero())
134+
.map(x => inspect(x))
135+
.join(', ')}],
136+
encryptedLogsHash: ${this.encryptedLogsHash.toString()},
137+
unencryptedLogsHash: ${this.unencryptedLogsHash.toString()},
138+
encryptedLogPreimagesLength: ${this.encryptedLogPreimagesLength.toString()},
139+
unencryptedLogPreimagesLength: ${this.unencryptedLogPreimagesLength.toString()},
140+
publicDataUpdateRequests: [${this.publicDataUpdateRequests
141+
.filter(x => !x.isEmpty())
142+
.map(x => inspect(x))
143+
.join(', ')}],
144+
gasUsed: ${inspect(this.gasUsed)}
145+
}`;
146+
}
119147
}

yarn-project/circuits.js/src/structs/kernel/public_accumulated_data.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,37 @@ export class PublicAccumulatedData {
103103
[inspect.custom]() {
104104
// print out the non-empty fields
105105
return `PublicAccumulatedData {
106-
newNoteHashes: [${this.newNoteHashes.map(h => h.toString()).join(', ')}],
107-
newNullifiers: [${this.newNullifiers.map(h => h.toString()).join(', ')}],
108-
newL2ToL1Msgs: [${this.newL2ToL1Msgs.map(h => h.toString()).join(', ')}],
109-
encryptedLogsHashes: [${this.encryptedLogsHashes.map(h => h.toString()).join(', ')}],
110-
unencryptedLogsHashes: [${this.unencryptedLogsHashes.map(h => h.toString()).join(', ')}],
106+
newNoteHashes: [${this.newNoteHashes
107+
.filter(x => !x.isEmpty())
108+
.map(h => inspect(h))
109+
.join(', ')}],
110+
newNullifiers: [${this.newNullifiers
111+
.filter(x => !x.isEmpty())
112+
.map(h => inspect(h))
113+
.join(', ')}],
114+
newL2ToL1Msgs: [${this.newL2ToL1Msgs
115+
.filter(x => !x.isZero())
116+
.map(h => inspect(h))
117+
.join(', ')}],
118+
encryptedLogsHashes: [${this.encryptedLogsHashes
119+
.filter(x => !x.isEmpty())
120+
.map(h => inspect(h))
121+
.join(', ')}],
122+
unencryptedLogsHashes: [${this.unencryptedLogsHashes
123+
.filter(x => !x.isEmpty())
124+
.map(h => inspect(h))
125+
.join(', ')}],
111126
encryptedLogPreimagesLength: ${this.encryptedLogPreimagesLength}
112127
unencryptedLogPreimagesLength: ${this.unencryptedLogPreimagesLength}
113-
publicDataUpdateRequests: [${this.publicDataUpdateRequests.map(h => h.toString()).join(', ')}],
114-
publicCallStack: [${this.publicCallStack.map(h => h.toString()).join(', ')}],
115-
gasUsed: [${this.gasUsed}]
128+
publicDataUpdateRequests: [${this.publicDataUpdateRequests
129+
.filter(x => !x.isEmpty())
130+
.map(h => inspect(h))
131+
.join(', ')}],
132+
publicCallStack: [${this.publicCallStack
133+
.filter(x => !x.isEmpty())
134+
.map(h => inspect(h))
135+
.join(', ')}],
136+
gasUsed: [${inspect(this.gasUsed)}]
116137
}`;
117138
}
118139

yarn-project/circuits.js/src/structs/kernel/public_kernel_circuit_public_inputs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export class PublicKernelCircuitPublicInputs {
105105
validationRequests: ${inspect(this.validationRequests)},
106106
endNonRevertibleData: ${inspect(this.endNonRevertibleData)},
107107
end: ${inspect(this.end)},
108-
constants: ${this.constants},
108+
constants: ${inspect(this.constants)},
109109
revertCode: ${this.revertCode}
110110
}`;
111111
}

yarn-project/circuits.js/src/structs/validation_requests.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { makeTuple } from '@aztec/foundation/array';
22
import { BufferReader, type Tuple, serializeToBuffer } from '@aztec/foundation/serialize';
33

4+
import { inspect } from 'util';
5+
46
import {
57
MAX_NOTE_HASH_READ_REQUESTS_PER_TX,
68
MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX,
@@ -103,4 +105,30 @@ export class ValidationRequests {
103105
makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, PublicDataRead.empty),
104106
);
105107
}
108+
109+
[inspect.custom]() {
110+
return `ValidationRequests {
111+
forRollup: ${inspect(this.forRollup)},
112+
noteHashReadRequests: [${this.noteHashReadRequests
113+
.filter(x => !x.isEmpty())
114+
.map(h => inspect(h))
115+
.join(', ')}],
116+
nullifierReadRequests: [${this.nullifierReadRequests
117+
.filter(x => !x.isEmpty())
118+
.map(h => inspect(h))
119+
.join(', ')}],
120+
nullifierNonExistentReadRequests: [${this.nullifierNonExistentReadRequests
121+
.filter(x => !x.isEmpty())
122+
.map(h => inspect(h))
123+
.join(', ')}],
124+
nullifierKeyValidationRequests: [${this.nullifierKeyValidationRequests
125+
.filter(x => !x.isEmpty())
126+
.map(h => inspect(h))
127+
.join(', ')}],
128+
publicDataReads: [${this.publicDataReads
129+
.filter(x => !x.isEmpty())
130+
.map(h => inspect(h))
131+
.join(', ')}]
132+
}`;
133+
}
106134
}

0 commit comments

Comments
 (0)