Skip to content

Commit 66a2d43

Browse files
authored
feat: remove total logs len from pre tail kernels + add to L1 (AztecProtocol#6466)
## Remove total logs length Now individual logs lengths are tracked inside the kernels, we can accurately calculate DA gas and don't need the total lengths (`(un)encrypted_log_preimages_length`). This PR removes them. However, we should be checking that logs emitted on L1 are the lengths claimed in the circuits since they originate in untrusted contexts. ## Add length check to L1 To allow for this check, total lengths are calculated when converting to `CombinedAccumulatedData` at the 'end' of the tail kernels. In the circuit, these are maintained throughout the rollup stages and included in the `txsEffectHash`. On L1, when we re-calculate the hash, the lengths of the raw logs are accumulated and asserted to match those given in the block. A mismatch suggests that a user may have claimed their log was shorter than reality to try and pay less gas (and the sequencer missed it or is dishonest). --- - [x] Remove total logs length from pre-tail kernel circuits - [x] Calculate the total length when converting to `CombinedAccumulatedData` - [x] Add lengths to `txEffectsHash` and check against raw logs on L1 ---
1 parent 0ac83dc commit 66a2d43

65 files changed

Lines changed: 381 additions & 443 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ const size_t PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH =
116116
MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + 1 +
117117
(L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 +
118118
(NOTE_LOG_HASH_LENGTH * MAX_NOTE_ENCRYPTED_LOGS_PER_CALL) + (LOG_HASH_LENGTH * MAX_ENCRYPTED_LOGS_PER_CALL) +
119-
(LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 2 + HEADER_LENGTH + TX_CONTEXT_LENGTH;
119+
(LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + HEADER_LENGTH + TX_CONTEXT_LENGTH;
120120
const size_t PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH =
121121
CALL_CONTEXT_LENGTH + 2 + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) +
122122
(READ_REQUEST_LENGTH * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL) +
123123
(CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL) +
124124
(CONTRACT_STORAGE_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_CALL) + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL +
125125
(NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) +
126126
(L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + (LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) +
127-
1 + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + AZTEC_ADDRESS_LENGTH + /* revert_code */ 1 + 2 * GAS_LENGTH +
127+
HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + AZTEC_ADDRESS_LENGTH + /* revert_code */ 1 + 2 * GAS_LENGTH +
128128
/* transaction_fee */ 1;
129129
const size_t PRIVATE_CALL_STACK_ITEM_LENGTH =
130130
AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH;
@@ -149,15 +149,15 @@ const size_t PRIVATE_ACCUMULATED_DATA_LENGTH =
149149
(SCOPED_NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_TX) + (SCOPED_NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_TX) +
150150
(MAX_NEW_L2_TO_L1_MSGS_PER_TX * SCOPED_L2_TO_L1_MESSAGE_LENGTH) +
151151
(NOTE_LOG_HASH_LENGTH * MAX_NOTE_ENCRYPTED_LOGS_PER_TX) + (LOG_HASH_LENGTH * MAX_ENCRYPTED_LOGS_PER_TX) +
152-
(LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_TX) + 2 + (CALL_REQUEST_LENGTH * MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX) +
152+
(LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_TX) + (CALL_REQUEST_LENGTH * MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX) +
153153
(CALL_REQUEST_LENGTH * MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX);
154154
const size_t PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH =
155155
1 + VALIDATION_REQUESTS_LENGTH + PRIVATE_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH +
156156
CALL_REQUEST_LENGTH + AZTEC_ADDRESS_LENGTH;
157157
const size_t PUBLIC_ACCUMULATED_DATA_LENGTH =
158158
(MAX_NEW_NOTE_HASHES_PER_TX * NOTE_HASH_LENGTH) + (MAX_NEW_NULLIFIERS_PER_TX * NULLIFIER_LENGTH) +
159159
(MAX_NEW_L2_TO_L1_MSGS_PER_TX * 1) + (NOTE_LOG_HASH_LENGTH * MAX_NOTE_ENCRYPTED_LOGS_PER_TX) +
160-
(MAX_ENCRYPTED_LOGS_PER_TX * LOG_HASH_LENGTH) + (MAX_UNENCRYPTED_LOGS_PER_TX * LOG_HASH_LENGTH) + 2 +
160+
(MAX_ENCRYPTED_LOGS_PER_TX * LOG_HASH_LENGTH) + (MAX_UNENCRYPTED_LOGS_PER_TX * LOG_HASH_LENGTH) +
161161
(MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * PUBLIC_DATA_UPDATE_REQUEST_LENGTH) +
162162
(MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX * CALL_REQUEST_LENGTH) + GAS_LENGTH;
163163
const size_t PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH =

l1-contracts/src/core/libraries/ConstantsGen.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ library Constants {
148148
+ (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2
149149
+ (NOTE_LOG_HASH_LENGTH * MAX_NOTE_ENCRYPTED_LOGS_PER_CALL)
150150
+ (LOG_HASH_LENGTH * MAX_ENCRYPTED_LOGS_PER_CALL)
151-
+ (LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 2 + HEADER_LENGTH + TX_CONTEXT_LENGTH;
151+
+ (LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + HEADER_LENGTH + TX_CONTEXT_LENGTH;
152152
uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = CALL_CONTEXT_LENGTH + 2
153153
+ (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL)
154154
+ (READ_REQUEST_LENGTH * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL)
@@ -157,7 +157,7 @@ library Constants {
157157
+ MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL)
158158
+ (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL)
159159
+ (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2
160-
+ (LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 1 + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH
160+
+ (LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH
161161
+ AZTEC_ADDRESS_LENGTH /* revert_code */ + 1 + 2 * GAS_LENGTH /* transaction_fee */ + 1;
162162
uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH =
163163
AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH;
@@ -186,7 +186,7 @@ library Constants {
186186
+ (MAX_NEW_L2_TO_L1_MSGS_PER_TX * SCOPED_L2_TO_L1_MESSAGE_LENGTH)
187187
+ (NOTE_LOG_HASH_LENGTH * MAX_NOTE_ENCRYPTED_LOGS_PER_TX)
188188
+ (LOG_HASH_LENGTH * MAX_ENCRYPTED_LOGS_PER_TX) + (LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_TX)
189-
+ 2 + (CALL_REQUEST_LENGTH * MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX)
189+
+ (CALL_REQUEST_LENGTH * MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX)
190190
+ (CALL_REQUEST_LENGTH * MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX);
191191
uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1
192192
+ VALIDATION_REQUESTS_LENGTH + PRIVATE_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH
@@ -196,7 +196,7 @@ library Constants {
196196
) + (MAX_NEW_NULLIFIERS_PER_TX * NULLIFIER_LENGTH) + (MAX_NEW_L2_TO_L1_MSGS_PER_TX * 1)
197197
+ (NOTE_LOG_HASH_LENGTH * MAX_NOTE_ENCRYPTED_LOGS_PER_TX)
198198
+ (MAX_ENCRYPTED_LOGS_PER_TX * LOG_HASH_LENGTH) + (MAX_UNENCRYPTED_LOGS_PER_TX * LOG_HASH_LENGTH)
199-
+ 2 + (MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * PUBLIC_DATA_UPDATE_REQUEST_LENGTH)
199+
+ (MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * PUBLIC_DATA_UPDATE_REQUEST_LENGTH)
200200
+ (MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX * CALL_REQUEST_LENGTH) + GAS_LENGTH;
201201
uint256 internal constant PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = VALIDATION_REQUESTS_LENGTH
202202
+ PUBLIC_ACCUMULATED_DATA_LENGTH + PUBLIC_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH

l1-contracts/src/core/libraries/Errors.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ library Errors {
5151
error Registry__RollupNotRegistered(address rollup); // 0xa1fee4cf
5252
error Registry__RollupAlreadyRegistered(address rollup); // 0x3c34eabf
5353

54+
//TxsDecoder
55+
error TxsDecoder__InvalidLogsLength(uint256 expected, uint256 actual); // 0x829ca981
56+
5457
// HeaderLib
5558
error HeaderLib__InvalidHeaderSize(uint256 expected, uint256 actual); // 0xf3ccb247
5659

l1-contracts/src/core/libraries/decoders/TxsDecoder.sol

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
pragma solidity >=0.8.18;
44

55
// Libraries
6+
import {Errors} from "../Errors.sol";
67
import {Constants} from "../ConstantsGen.sol";
78
import {Hash} from "../Hash.sol";
89

@@ -53,6 +54,8 @@ library TxsDecoder {
5354
uint256 nullifier;
5455
uint256 l2ToL1Msgs;
5556
uint256 publicData;
57+
uint256 encryptedLogsLength;
58+
uint256 unencryptedLogsLength;
5659
}
5760

5861
struct Counts {
@@ -66,6 +69,9 @@ library TxsDecoder {
6669
struct ConsumablesVars {
6770
bytes32[] baseLeaves;
6871
bytes baseLeaf;
72+
uint256 kernelNoteEncryptedLogsLength;
73+
uint256 kernelEncryptedLogsLength;
74+
uint256 kernelUnencryptedLogsLength;
6975
bytes32 noteEncryptedLogsHash;
7076
bytes32 encryptedLogsHash;
7177
bytes32 unencryptedLogsHash;
@@ -148,9 +154,38 @@ library TxsDecoder {
148154
* Compute encrypted and unencrypted logs hashes corresponding to the current leaf.
149155
* Note: will advance offsets by the number of bytes processed.
150156
*/
151-
(vars.noteEncryptedLogsHash, offset) = computeKernelLogsHash(offset, _body, true);
152-
(vars.encryptedLogsHash, offset) = computeKernelLogsHash(offset, _body, false);
153-
(vars.unencryptedLogsHash, offset) = computeKernelLogsHash(offset, _body, false);
157+
offsets.encryptedLogsLength = offset;
158+
offset += 0x20;
159+
offsets.unencryptedLogsLength = offset;
160+
offset += 0x20;
161+
162+
(vars.noteEncryptedLogsHash, offset, vars.kernelNoteEncryptedLogsLength) =
163+
computeKernelLogsHash(offset, _body, true);
164+
(vars.encryptedLogsHash, offset, vars.kernelEncryptedLogsLength) =
165+
computeKernelLogsHash(offset, _body, false);
166+
(vars.unencryptedLogsHash, offset, vars.kernelUnencryptedLogsLength) =
167+
computeKernelLogsHash(offset, _body, false);
168+
169+
// We throw to ensure that the byte len we charge for DA gas in the kernels matches the actual chargable log byte len
170+
// Without this check, the user may provide the kernels with a lower log len than reality
171+
if (
172+
uint256(bytes32(slice(_body, offsets.encryptedLogsLength, 0x20)))
173+
!= vars.kernelNoteEncryptedLogsLength + vars.kernelEncryptedLogsLength
174+
) {
175+
revert Errors.TxsDecoder__InvalidLogsLength(
176+
uint256(bytes32(slice(_body, offsets.encryptedLogsLength, 0x20))),
177+
vars.kernelNoteEncryptedLogsLength + vars.kernelEncryptedLogsLength
178+
);
179+
}
180+
if (
181+
uint256(bytes32(slice(_body, offsets.unencryptedLogsLength, 0x20)))
182+
!= vars.kernelUnencryptedLogsLength
183+
) {
184+
revert Errors.TxsDecoder__InvalidLogsLength(
185+
uint256(bytes32(slice(_body, offsets.unencryptedLogsLength, 0x20))),
186+
vars.kernelUnencryptedLogsLength
187+
);
188+
}
154189

155190
// Insertions are split into multiple `bytes.concat` to work around stack too deep.
156191
vars.baseLeaf = bytes.concat(
@@ -185,6 +220,10 @@ library TxsDecoder {
185220
Constants.PUBLIC_DATA_WRITES_NUM_BYTES_PER_BASE_ROLLUP
186221
)
187222
),
223+
bytes.concat(
224+
slice(_body, offsets.encryptedLogsLength, 0x20),
225+
slice(_body, offsets.unencryptedLogsLength, 0x20)
226+
),
188227
bytes.concat(vars.noteEncryptedLogsHash, vars.encryptedLogsHash, vars.unencryptedLogsHash)
189228
);
190229

@@ -194,7 +233,7 @@ library TxsDecoder {
194233
// We pad base leaves with hashes of empty tx effect.
195234
for (uint256 i = numTxEffects; i < vars.baseLeaves.length; i++) {
196235
// Value taken from tx_effect.test.ts "hash of empty tx effect matches snapshot" test case
197-
vars.baseLeaves[i] = hex"00543e0a6642ffeb8039296861765a53407bba62bd1c97ca43374de950bbe0a7";
236+
vars.baseLeaves[i] = hex"009f12fb98ebbf4e5deef4cf51ade63094a795b891880217958b226707c95f43";
198237
}
199238
}
200239

@@ -207,13 +246,12 @@ library TxsDecoder {
207246
* @param _body - The L2 block calldata.
208247
* @return The hash of the logs and offset in a block after processing the logs.
209248
* @dev We have logs preimages on the input and we need to perform the same hashing process as is done in the app
210-
* circuit (hashing the logs) and in the kernel circuit (accumulating the logs hashes). In each iteration of
211-
* kernel, the kernel computes a hash of the previous iteration's logs hash (the hash in the previous kernel's
212-
* public inputs) and the current iteration private circuit public inputs logs hash.
249+
* circuit (hashing the logs) and in the kernel circuit (accumulating the logs hashes). The tail kernel
250+
* circuit flat hashes all the app log hashes.
213251
*
214252
* E.g. for resulting logs hash of a kernel with 3 iterations would be computed as:
215253
*
216-
* kernelPublicInputsLogsHash = sha256(sha256(sha256(I1_LOGS), sha256(I2_LOGS)), sha256(I3_LOGS))
254+
* kernelPublicInputsLogsHash = sha256((sha256(I1_LOGS), sha256(I2_LOGS)), sha256(I3_LOGS))
217255
*
218256
* where I1_LOGS, I2_LOGS and I3_LOGS are logs emitted in the first, second and third function call.
219257
*
@@ -229,17 +267,22 @@ library TxsDecoder {
229267
* I1_LOGS_LEN (i) is the length of the logs in the first iteration.
230268
* I1_LOGS are all the logs emitted in the first iteration.
231269
* I2_LOGS_LEN (j) ...
270+
* @dev The circuit outputs a total logs len based on the byte length that the user pays DA gas for.
271+
* In terms of the encoding above, this is the raw log length (i, j, or k) + 4 for each log.
272+
* For the example above, kernelLogsLength = (i + 4) + (j + 4) + (k + 4). Since we already track
273+
* the total remainingLogsLength, we just remove the bytes holding function logs length.
232274
*
233275
* @dev Link to a relevant discussion:
234276
* https://discourse.aztec.network/t/proposal-forcing-the-sequencer-to-actually-submit-data-to-l1/426/9
235277
*/
236278
function computeKernelLogsHash(uint256 _offsetInBlock, bytes calldata _body, bool noteLogs)
237279
internal
238280
pure
239-
returns (bytes32, uint256)
281+
returns (bytes32, uint256, uint256)
240282
{
241283
uint256 offset = _offsetInBlock;
242284
uint256 remainingLogsLength = read4(_body, offset);
285+
uint256 kernelLogsLength = remainingLogsLength;
243286
offset += 0x4;
244287

245288
bytes memory flattenedLogHashes; // The hash input
@@ -253,6 +296,8 @@ library TxsDecoder {
253296
// Decrease remaining logs length by this privateCircuitPublicInputsLogs's length (len(I?_LOGS)) and 4 bytes for I?_LOGS_LEN
254297
remainingLogsLength -= (privateCircuitPublicInputLogsLength + 0x4);
255298

299+
kernelLogsLength -= 0x4;
300+
256301
while (privateCircuitPublicInputLogsLength > 0) {
257302
uint256 singleCallLogsLength = read4(_body, offset);
258303
offset += 0x4;
@@ -268,7 +313,7 @@ library TxsDecoder {
268313

269314
// Not having a 0 value hash for empty logs causes issues with empty txs used for padding.
270315
if (flattenedLogHashes.length == 0) {
271-
return (0, offset);
316+
return (0, offset, 0);
272317
}
273318

274319
// padded to MAX_LOGS * 32 bytes
@@ -284,7 +329,7 @@ library TxsDecoder {
284329

285330
bytes32 kernelPublicInputsLogsHash = Hash.sha256ToField(flattenedLogHashes);
286331

287-
return (kernelPublicInputsLogsHash, offset);
332+
return (kernelPublicInputsLogsHash, offset, kernelLogsLength);
288333
}
289334

290335
/**

l1-contracts/test/decoders/Decoders.t.sol

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,11 @@ contract DecodersTest is DecoderBase {
174174
bytes memory iterationLogsLength = hex"00000000"; // 4 empty bytes indicating that length of this iteration's logs is 0
175175
bytes memory encodedLogs = abi.encodePacked(kernelLogsLength, iterationLogsLength);
176176

177-
(bytes32 logsHash, uint256 bytesAdvanced) = txsHelper.computeKernelLogsHash(encodedLogs);
177+
(bytes32 logsHash, uint256 bytesAdvanced, uint256 logsLength) =
178+
txsHelper.computeKernelLogsHash(encodedLogs);
178179

179180
assertEq(bytesAdvanced, encodedLogs.length, "Advanced by an incorrect number of bytes");
181+
assertEq(logsLength, 0, "Incorrect logs length");
180182
assertEq(logsHash, bytes32(0), "Incorrect logs hash");
181183
}
182184

@@ -190,7 +192,8 @@ contract DecodersTest is DecoderBase {
190192
// Note: 00000004 is the length of 1 log within function logs
191193
bytes memory encodedLogs =
192194
abi.encodePacked(hex"0000000c00000008", hex"00000004", firstFunctionCallLogs);
193-
(bytes32 logsHash, uint256 bytesAdvanced) = txsHelper.computeKernelLogsHash(encodedLogs);
195+
(bytes32 logsHash, uint256 bytesAdvanced, uint256 logsLength) =
196+
txsHelper.computeKernelLogsHash(encodedLogs);
194197

195198
bytes32 privateCircuitPublicInputsLogsHashFirstCall = Hash.sha256ToField(firstFunctionCallLogs);
196199

@@ -202,6 +205,8 @@ contract DecodersTest is DecoderBase {
202205
);
203206

204207
assertEq(bytesAdvanced, encodedLogs.length, "Advanced by an incorrect number of bytes");
208+
// We take 8 as the user does not pay for the gas of the overall len (hex"0000002400000008")
209+
assertEq(logsLength, encodedLogs.length - 8, "Incorrect logs length");
205210
assertEq(logsHash, referenceLogsHash, "Incorrect logs hash");
206211
}
207212

@@ -222,7 +227,8 @@ contract DecodersTest is DecoderBase {
222227
hex"00000010",
223228
secondFunctionCallLogs
224229
);
225-
(bytes32 logsHash, uint256 bytesAdvanced) = txsHelper.computeKernelLogsHash(encodedLogs);
230+
(bytes32 logsHash, uint256 bytesAdvanced, uint256 logsLength) =
231+
txsHelper.computeKernelLogsHash(encodedLogs);
226232

227233
bytes32 referenceLogsHashFromIteration1 = Hash.sha256ToField(firstFunctionCallLogs);
228234

@@ -238,6 +244,8 @@ contract DecodersTest is DecoderBase {
238244
);
239245

240246
assertEq(bytesAdvanced, encodedLogs.length, "Advanced by an incorrect number of bytes");
247+
// We take 12 as the user does not pay for the gas of the function logs len bytes (hex"00000014") or overall len (hex"0000002400000008")
248+
assertEq(logsLength, encodedLogs.length - 12, "Incorrect logs length");
241249
assertEq(logsHash, referenceLogsHashFromIteration2, "Incorrect logs hash");
242250
}
243251

@@ -263,7 +271,8 @@ contract DecodersTest is DecoderBase {
263271
hex"00000010",
264272
thirdFunctionCallLogs
265273
);
266-
(bytes32 logsHash, uint256 bytesAdvanced) = txsHelper.computeKernelLogsHash(encodedLogs);
274+
(bytes32 logsHash, uint256 bytesAdvanced, uint256 logsLength) =
275+
txsHelper.computeKernelLogsHash(encodedLogs);
267276

268277
bytes32 referenceLogsHashFromIteration1 = Hash.sha256ToField(firstFunctionCallLogs);
269278

@@ -281,6 +290,9 @@ contract DecodersTest is DecoderBase {
281290
);
282291

283292
assertEq(bytesAdvanced, encodedLogs.length, "Advanced by an incorrect number of bytes");
293+
// We take 16 as the user does not pay for the gas of the function logs len bytes (hex"00000014"),
294+
// empty logs len bytes (hex"00000000") or overall len (hex"0000002400000008")
295+
assertEq(logsLength, encodedLogs.length - 16, "Incorrect logs length");
284296
assertEq(logsHash, referenceLogsHashFromIteration3, "Incorrect logs hash");
285297
}
286298

l1-contracts/test/decoders/helpers/TxsDecoderHelper.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ contract TxsDecoderHelper {
1313
function computeKernelLogsHash(bytes calldata _kernelLogs)
1414
external
1515
pure
16-
returns (bytes32, uint256)
16+
returns (bytes32, uint256, uint256)
1717
{
1818
return TxsDecoder.computeKernelLogsHash(0, _kernelLogs, false);
1919
}

0 commit comments

Comments
 (0)