@aztec/blob-lib 3.0.0-devnet.2 → 3.0.0-devnet.20251212
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/batched_blob.d.ts +26 -0
- package/dest/batched_blob.d.ts.map +1 -0
- package/dest/batched_blob.js +20 -0
- package/dest/blob.d.ts +6 -11
- package/dest/blob.d.ts.map +1 -1
- package/dest/blob.js +5 -2
- package/dest/blob_batching.d.ts +35 -84
- package/dest/blob_batching.d.ts.map +1 -1
- package/dest/blob_batching.js +73 -108
- package/dest/blob_utils.d.ts +21 -11
- package/dest/blob_utils.d.ts.map +1 -1
- package/dest/blob_utils.js +29 -20
- package/dest/circuit_types/blob_accumulator.d.ts +4 -2
- package/dest/circuit_types/blob_accumulator.d.ts.map +1 -1
- package/dest/circuit_types/blob_accumulator.js +5 -1
- package/dest/circuit_types/final_blob_accumulator.d.ts +3 -2
- package/dest/circuit_types/final_blob_accumulator.d.ts.map +1 -1
- package/dest/circuit_types/final_blob_accumulator.js +2 -1
- package/dest/circuit_types/final_blob_batching_challenges.d.ts +3 -2
- package/dest/circuit_types/final_blob_batching_challenges.d.ts.map +1 -1
- package/dest/circuit_types/final_blob_batching_challenges.js +2 -1
- package/dest/circuit_types/index.d.ts +1 -1
- package/dest/encoding/block_blob_data.d.ts +22 -0
- package/dest/encoding/block_blob_data.d.ts.map +1 -0
- package/dest/encoding/block_blob_data.js +65 -0
- package/dest/encoding/block_end_marker.d.ts +11 -0
- package/dest/encoding/block_end_marker.d.ts.map +1 -0
- package/dest/encoding/block_end_marker.js +41 -0
- package/dest/encoding/block_end_state_field.d.ts +12 -0
- package/dest/encoding/block_end_state_field.d.ts.map +1 -0
- package/dest/encoding/block_end_state_field.js +39 -0
- package/dest/encoding/checkpoint_blob_data.d.ts +15 -0
- package/dest/encoding/checkpoint_blob_data.d.ts.map +1 -0
- package/dest/encoding/checkpoint_blob_data.js +67 -0
- package/dest/encoding/checkpoint_end_marker.d.ts +8 -0
- package/dest/encoding/checkpoint_end_marker.d.ts.map +1 -0
- package/dest/encoding/checkpoint_end_marker.js +28 -0
- package/dest/encoding/fixtures.d.ts +41 -0
- package/dest/encoding/fixtures.d.ts.map +1 -0
- package/dest/encoding/fixtures.js +140 -0
- package/dest/encoding/index.d.ts +10 -0
- package/dest/encoding/index.d.ts.map +1 -0
- package/dest/encoding/index.js +9 -0
- package/dest/encoding/tx_blob_data.d.ts +19 -0
- package/dest/encoding/tx_blob_data.d.ts.map +1 -0
- package/dest/encoding/tx_blob_data.js +79 -0
- package/dest/encoding/tx_start_marker.d.ts +16 -0
- package/dest/encoding/tx_start_marker.d.ts.map +1 -0
- package/dest/{encoding.js → encoding/tx_start_marker.js} +13 -59
- package/dest/errors.d.ts +1 -1
- package/dest/errors.d.ts.map +1 -1
- package/dest/hash.d.ts +13 -5
- package/dest/hash.d.ts.map +1 -1
- package/dest/hash.js +19 -8
- package/dest/index.d.ts +4 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -3
- package/dest/interface.d.ts +1 -1
- package/dest/kzg_context.d.ts +6 -2
- package/dest/kzg_context.d.ts.map +1 -1
- package/dest/kzg_context.js +12 -3
- package/dest/sponge_blob.d.ts +9 -15
- package/dest/sponge_blob.d.ts.map +1 -1
- package/dest/sponge_blob.js +21 -36
- package/dest/testing.d.ts +8 -16
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +35 -64
- package/dest/types.d.ts +2 -1
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +1 -0
- package/package.json +8 -7
- package/src/batched_blob.ts +26 -0
- package/src/blob.ts +5 -2
- package/src/blob_batching.ts +91 -126
- package/src/blob_utils.ts +33 -22
- package/src/circuit_types/blob_accumulator.ts +13 -1
- package/src/circuit_types/final_blob_accumulator.ts +2 -1
- package/src/circuit_types/final_blob_batching_challenges.ts +2 -1
- package/src/encoding/block_blob_data.ts +102 -0
- package/src/encoding/block_end_marker.ts +55 -0
- package/src/encoding/block_end_state_field.ts +59 -0
- package/src/encoding/checkpoint_blob_data.ts +95 -0
- package/src/encoding/checkpoint_end_marker.ts +40 -0
- package/src/encoding/fixtures.ts +210 -0
- package/src/encoding/index.ts +9 -0
- package/src/encoding/tx_blob_data.ts +116 -0
- package/src/{encoding.ts → encoding/tx_start_marker.ts} +19 -76
- package/src/hash.ts +20 -8
- package/src/index.ts +3 -3
- package/src/kzg_context.ts +12 -1
- package/src/sponge_blob.ts +23 -36
- package/src/testing.ts +47 -73
- package/src/types.ts +1 -0
- package/dest/deserialize.d.ts +0 -14
- package/dest/deserialize.d.ts.map +0 -1
- package/dest/deserialize.js +0 -33
- package/dest/encoding.d.ts +0 -26
- package/dest/encoding.d.ts.map +0 -1
- package/src/deserialize.ts +0 -38
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH, MAX_CONTRACT_CLASS_LOGS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_PRIVATE_LOGS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, PRIVATE_LOG_SIZE_IN_FIELDS } from '@aztec/constants';
|
|
2
|
+
import { makeTuple } from '@aztec/foundation/array';
|
|
3
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
|
+
import { getTotalNumBlobFieldsFromTxs } from './checkpoint_blob_data.js';
|
|
6
|
+
import { getNumTxBlobFields } from './tx_blob_data.js';
|
|
7
|
+
const fr = (seed)=>new Fr(BigInt(seed));
|
|
8
|
+
export function makeTxStartMarker({ isFullTx = false, ...overrides } = {}) {
|
|
9
|
+
const partialTxStartMarker = {
|
|
10
|
+
revertCode: 0,
|
|
11
|
+
numNoteHashes: isFullTx ? MAX_NOTE_HASHES_PER_TX : 1,
|
|
12
|
+
numNullifiers: isFullTx ? MAX_NULLIFIERS_PER_TX : 1,
|
|
13
|
+
numL2ToL1Msgs: isFullTx ? MAX_L2_TO_L1_MSGS_PER_TX : 1,
|
|
14
|
+
numPublicDataWrites: isFullTx ? MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX : 1,
|
|
15
|
+
numPrivateLogs: isFullTx ? MAX_PRIVATE_LOGS_PER_TX : 1,
|
|
16
|
+
privateLogsLength: isFullTx ? PRIVATE_LOG_SIZE_IN_FIELDS * MAX_PRIVATE_LOGS_PER_TX : 1,
|
|
17
|
+
publicLogsLength: isFullTx ? FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH : 1,
|
|
18
|
+
contractClassLogLength: isFullTx ? MAX_CONTRACT_CLASS_LOGS_PER_TX : 1,
|
|
19
|
+
...overrides
|
|
20
|
+
};
|
|
21
|
+
const numBlobFields = overrides.numBlobFields ?? getNumTxBlobFields(partialTxStartMarker);
|
|
22
|
+
return {
|
|
23
|
+
...partialTxStartMarker,
|
|
24
|
+
numBlobFields
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function makeTxBlobData({ isFullTx = false, seed = 1, ...overrides } = {}) {
|
|
28
|
+
const { txStartMarker: txStartMarkerOverrides, ...txBlobDataOverrides } = overrides;
|
|
29
|
+
const txStartMarker = makeTxStartMarker({
|
|
30
|
+
isFullTx,
|
|
31
|
+
...txStartMarkerOverrides
|
|
32
|
+
});
|
|
33
|
+
const noteHashes = makeTuple(txStartMarker.numNoteHashes, fr, seed);
|
|
34
|
+
const nullifiers = makeTuple(txStartMarker.numNullifiers, fr, seed + 0x100);
|
|
35
|
+
const l2ToL1Msgs = makeTuple(txStartMarker.numL2ToL1Msgs, fr, seed + 0x200);
|
|
36
|
+
const publicDataWrites = makeTuple(txStartMarker.numPublicDataWrites, (i)=>[
|
|
37
|
+
fr(seed + i * 2),
|
|
38
|
+
fr(seed + i * 2 + 1)
|
|
39
|
+
], seed + 0x300);
|
|
40
|
+
const privateLogs = [];
|
|
41
|
+
if (txStartMarker.privateLogsLength > txStartMarker.numPrivateLogs * PRIVATE_LOG_SIZE_IN_FIELDS) {
|
|
42
|
+
throw new Error('Private logs length is too large');
|
|
43
|
+
}
|
|
44
|
+
if (txStartMarker.privateLogsLength < txStartMarker.numPrivateLogs) {
|
|
45
|
+
throw new Error('Private logs length is too small');
|
|
46
|
+
}
|
|
47
|
+
let remainingNumPrivateLogs = txStartMarker.numPrivateLogs;
|
|
48
|
+
let remainingPrivateLogsLength = txStartMarker.privateLogsLength;
|
|
49
|
+
for(let i = 0; i < txStartMarker.numPrivateLogs; i++){
|
|
50
|
+
const minLength = Math.max(1, remainingPrivateLogsLength - (remainingNumPrivateLogs - 1) * PRIVATE_LOG_SIZE_IN_FIELDS);
|
|
51
|
+
const length = Math.max(minLength, Math.floor(remainingPrivateLogsLength / remainingNumPrivateLogs));
|
|
52
|
+
privateLogs.push(makeTuple(length, fr, seed + 0x400 + i * PRIVATE_LOG_SIZE_IN_FIELDS));
|
|
53
|
+
remainingNumPrivateLogs -= 1;
|
|
54
|
+
remainingPrivateLogsLength -= length;
|
|
55
|
+
}
|
|
56
|
+
const publicLogs = makeTuple(txStartMarker.publicLogsLength, fr, seed + 0x500);
|
|
57
|
+
const contractClassLogBlobDataLength = txStartMarker.contractClassLogLength > 0 ? txStartMarker.contractClassLogLength + 1 : 0; // If the log exists, +1 for the contract address
|
|
58
|
+
const contractClassLog = makeTuple(contractClassLogBlobDataLength, fr, seed + 0x600);
|
|
59
|
+
return {
|
|
60
|
+
txStartMarker,
|
|
61
|
+
txHash: fr(seed + 0x700),
|
|
62
|
+
transactionFee: fr(seed + 0x800),
|
|
63
|
+
noteHashes,
|
|
64
|
+
nullifiers,
|
|
65
|
+
l2ToL1Msgs,
|
|
66
|
+
publicDataWrites,
|
|
67
|
+
privateLogs,
|
|
68
|
+
publicLogs,
|
|
69
|
+
contractClassLog,
|
|
70
|
+
...txBlobDataOverrides
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function makeBlockEndMarker({ seed = 1, ...overrides } = {}) {
|
|
74
|
+
return {
|
|
75
|
+
numTxs: seed,
|
|
76
|
+
blockNumber: BlockNumber(seed + 1),
|
|
77
|
+
timestamp: BigInt(seed + 2),
|
|
78
|
+
...overrides
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export function makeBlockEndStateField({ seed = 1, ...overrides } = {}) {
|
|
82
|
+
return {
|
|
83
|
+
l1ToL2MessageNextAvailableLeafIndex: seed,
|
|
84
|
+
noteHashNextAvailableLeafIndex: seed + 0x10,
|
|
85
|
+
nullifierNextAvailableLeafIndex: seed + 0x20,
|
|
86
|
+
publicDataNextAvailableLeafIndex: seed + 0x30,
|
|
87
|
+
totalManaUsed: BigInt(seed + 0x40),
|
|
88
|
+
...overrides
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export function makeBlockEndBlobData({ isFirstBlock = true, seed = 1, ...overrides } = {}) {
|
|
92
|
+
const { blockEndMarker: blockEndMarkerOverrides, blockEndStateField: blockEndStateFieldOverrides, ...blockEndBlobDataOverrides } = overrides;
|
|
93
|
+
return {
|
|
94
|
+
blockEndMarker: makeBlockEndMarker({
|
|
95
|
+
seed,
|
|
96
|
+
...blockEndMarkerOverrides
|
|
97
|
+
}),
|
|
98
|
+
blockEndStateField: makeBlockEndStateField({
|
|
99
|
+
seed: seed + 0x100,
|
|
100
|
+
...blockEndStateFieldOverrides
|
|
101
|
+
}),
|
|
102
|
+
lastArchiveRoot: fr(seed + 0x200),
|
|
103
|
+
noteHashRoot: fr(seed + 0x300),
|
|
104
|
+
nullifierRoot: fr(seed + 0x400),
|
|
105
|
+
publicDataRoot: fr(seed + 0x500),
|
|
106
|
+
l1ToL2MessageRoot: isFirstBlock ? fr(seed + 0x600) : undefined,
|
|
107
|
+
...blockEndBlobDataOverrides
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
export function makeBlockBlobData({ numTxs = 1, isFirstBlock = true, isFullTx = false, seed = 1, ...overrides } = {}) {
|
|
111
|
+
return {
|
|
112
|
+
txs: makeTuple(numTxs, (i)=>makeTxBlobData({
|
|
113
|
+
isFullTx,
|
|
114
|
+
seed: seed + i * 0x100
|
|
115
|
+
}), seed),
|
|
116
|
+
...makeBlockEndBlobData({
|
|
117
|
+
seed: seed + 0x1000 * numTxs,
|
|
118
|
+
blockEndMarker: {
|
|
119
|
+
numTxs
|
|
120
|
+
},
|
|
121
|
+
isFirstBlock,
|
|
122
|
+
...overrides
|
|
123
|
+
})
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export function makeCheckpointBlobData({ numBlocks = 1, numTxsPerBlock = 1, isFullTx = false, seed = 1, ...overrides } = {}) {
|
|
127
|
+
const blocks = overrides.blocks ?? makeTuple(numBlocks, (i)=>makeBlockBlobData({
|
|
128
|
+
numTxs: numTxsPerBlock,
|
|
129
|
+
isFirstBlock: i === seed,
|
|
130
|
+
isFullTx,
|
|
131
|
+
seed: seed + i * 0x1000
|
|
132
|
+
}), seed);
|
|
133
|
+
const numBlobFields = overrides.checkpointEndMarker?.numBlobFields ?? getTotalNumBlobFieldsFromTxs(blocks.map((block)=>block.txs.map((tx)=>tx.txStartMarker)));
|
|
134
|
+
return {
|
|
135
|
+
blocks,
|
|
136
|
+
checkpointEndMarker: {
|
|
137
|
+
numBlobFields
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './block_blob_data.js';
|
|
2
|
+
export * from './block_end_marker.js';
|
|
3
|
+
export * from './block_end_state_field.js';
|
|
4
|
+
export * from './checkpoint_blob_data.js';
|
|
5
|
+
export * from './checkpoint_end_marker.js';
|
|
6
|
+
export * from './fixtures.js';
|
|
7
|
+
export * from './tx_blob_data.js';
|
|
8
|
+
export * from './tx_start_marker.js';
|
|
9
|
+
export { BlobDeserializationError } from '../errors.js';
|
|
10
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9lbmNvZGluZy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLHNCQUFzQixDQUFDO0FBQ3JDLGNBQWMsdUJBQXVCLENBQUM7QUFDdEMsY0FBYyw0QkFBNEIsQ0FBQztBQUMzQyxjQUFjLDJCQUEyQixDQUFDO0FBQzFDLGNBQWMsNEJBQTRCLENBQUM7QUFDM0MsY0FBYyxlQUFlLENBQUM7QUFDOUIsY0FBYyxtQkFBbUIsQ0FBQztBQUNsQyxjQUFjLHNCQUFzQixDQUFDO0FBQ3JDLE9BQU8sRUFBRSx3QkFBd0IsRUFBRSxNQUFNLGNBQWMsQ0FBQyJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/encoding/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './block_blob_data.js';
|
|
2
|
+
export * from './block_end_marker.js';
|
|
3
|
+
export * from './block_end_state_field.js';
|
|
4
|
+
export * from './checkpoint_blob_data.js';
|
|
5
|
+
export * from './checkpoint_end_marker.js';
|
|
6
|
+
export * from './fixtures.js';
|
|
7
|
+
export * from './tx_blob_data.js';
|
|
8
|
+
export * from './tx_start_marker.js';
|
|
9
|
+
export { BlobDeserializationError } from '../errors.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { FieldReader } from '@aztec/foundation/serialize';
|
|
3
|
+
import { type TxStartMarker } from './tx_start_marker.js';
|
|
4
|
+
export interface TxBlobData {
|
|
5
|
+
txStartMarker: TxStartMarker;
|
|
6
|
+
txHash: Fr;
|
|
7
|
+
transactionFee: Fr;
|
|
8
|
+
noteHashes: Fr[];
|
|
9
|
+
nullifiers: Fr[];
|
|
10
|
+
l2ToL1Msgs: Fr[];
|
|
11
|
+
publicDataWrites: [Fr, Fr][];
|
|
12
|
+
privateLogs: Fr[][];
|
|
13
|
+
publicLogs: Fr[];
|
|
14
|
+
contractClassLog: Fr[];
|
|
15
|
+
}
|
|
16
|
+
export declare function encodeTxBlobData(txBlobData: TxBlobData): Fr[];
|
|
17
|
+
export declare function decodeTxBlobData(fields: Fr[] | FieldReader): TxBlobData;
|
|
18
|
+
export declare function getNumTxBlobFields(txStartMarker: Omit<TxStartMarker, 'revertCode' | 'numBlobFields'>): number;
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfYmxvYl9kYXRhLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZW5jb2RpbmcvdHhfYmxvYl9kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUNwRCxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFHMUQsT0FBTyxFQUFFLEtBQUssYUFBYSxFQUE0QyxNQUFNLHNCQUFzQixDQUFDO0FBSXBHLE1BQU0sV0FBVyxVQUFVO0lBQ3pCLGFBQWEsRUFBRSxhQUFhLENBQUM7SUFDN0IsTUFBTSxFQUFFLEVBQUUsQ0FBQztJQUNYLGNBQWMsRUFBRSxFQUFFLENBQUM7SUFDbkIsVUFBVSxFQUFFLEVBQUUsRUFBRSxDQUFDO0lBQ2pCLFVBQVUsRUFBRSxFQUFFLEVBQUUsQ0FBQztJQUNqQixVQUFVLEVBQUUsRUFBRSxFQUFFLENBQUM7SUFDakIsZ0JBQWdCLEVBQUUsQ0FBQyxFQUFFLEVBQUUsRUFBRSxDQUFDLEVBQUUsQ0FBQztJQUM3QixXQUFXLEVBQUUsRUFBRSxFQUFFLEVBQUUsQ0FBQztJQUNwQixVQUFVLEVBQUUsRUFBRSxFQUFFLENBQUM7SUFDakIsZ0JBQWdCLEVBQUUsRUFBRSxFQUFFLENBQUM7Q0FDeEI7QUFFRCx3QkFBZ0IsZ0JBQWdCLENBQUMsVUFBVSxFQUFFLFVBQVUsR0FBRyxFQUFFLEVBQUUsQ0FhN0Q7QUFFRCx3QkFBZ0IsZ0JBQWdCLENBQUMsTUFBTSxFQUFFLEVBQUUsRUFBRSxHQUFHLFdBQVcsR0FBRyxVQUFVLENBNkR2RTtBQUVELHdCQUFnQixrQkFBa0IsQ0FBQyxhQUFhLEVBQUUsSUFBSSxDQUFDLGFBQWEsRUFBRSxZQUFZLEdBQUcsZUFBZSxDQUFDLFVBZXBHIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx_blob_data.d.ts","sourceRoot":"","sources":["../../src/encoding/tx_blob_data.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAG1D,OAAO,EAAE,KAAK,aAAa,EAA4C,MAAM,sBAAsB,CAAC;AAIpG,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,aAAa,CAAC;IAC7B,MAAM,EAAE,EAAE,CAAC;IACX,cAAc,EAAE,EAAE,CAAC;IACnB,UAAU,EAAE,EAAE,EAAE,CAAC;IACjB,UAAU,EAAE,EAAE,EAAE,CAAC;IACjB,UAAU,EAAE,EAAE,EAAE,CAAC;IACjB,gBAAgB,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;IAC7B,WAAW,EAAE,EAAE,EAAE,EAAE,CAAC;IACpB,UAAU,EAAE,EAAE,EAAE,CAAC;IACjB,gBAAgB,EAAE,EAAE,EAAE,CAAC;CACxB;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,EAAE,EAAE,CAa7D;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,GAAG,UAAU,CA6DvE;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,YAAY,GAAG,eAAe,CAAC,UAepG"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { chunk } from '@aztec/foundation/collection';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { FieldReader } from '@aztec/foundation/serialize';
|
|
4
|
+
import { BlobDeserializationError } from '../errors.js';
|
|
5
|
+
import { decodeTxStartMarker, encodeTxStartMarker } from './tx_start_marker.js';
|
|
6
|
+
export function encodeTxBlobData(txBlobData) {
|
|
7
|
+
return [
|
|
8
|
+
encodeTxStartMarker(txBlobData.txStartMarker),
|
|
9
|
+
txBlobData.txHash,
|
|
10
|
+
txBlobData.transactionFee,
|
|
11
|
+
...txBlobData.noteHashes,
|
|
12
|
+
...txBlobData.nullifiers,
|
|
13
|
+
...txBlobData.l2ToL1Msgs,
|
|
14
|
+
...txBlobData.publicDataWrites.flat(),
|
|
15
|
+
...txBlobData.privateLogs.map((log)=>[
|
|
16
|
+
new Fr(log.length),
|
|
17
|
+
...log
|
|
18
|
+
]).flat(),
|
|
19
|
+
...txBlobData.publicLogs,
|
|
20
|
+
...txBlobData.contractClassLog
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
export function decodeTxBlobData(fields) {
|
|
24
|
+
const reader = FieldReader.asReader(fields);
|
|
25
|
+
if (reader.isFinished()) {
|
|
26
|
+
throw new BlobDeserializationError(`Incorrect encoding of blob fields: not enough fields for tx blob data.`);
|
|
27
|
+
}
|
|
28
|
+
const txStartMarker = decodeTxStartMarker(reader.readField());
|
|
29
|
+
const checkRemainingFields = (requiredFields, type)=>{
|
|
30
|
+
if (requiredFields > reader.remainingFields()) {
|
|
31
|
+
throw new BlobDeserializationError(`Incorrect encoding of blob fields: not enough fields for ${type}. Expected ${requiredFields} fields, only ${reader.remainingFields()} remaining.`);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const numTxEffectFields = txStartMarker.numBlobFields - 1; // -1 because we already read the tx start marker.
|
|
35
|
+
checkRemainingFields(numTxEffectFields, 'tx effect');
|
|
36
|
+
const txHash = reader.readField();
|
|
37
|
+
const transactionFee = reader.readField();
|
|
38
|
+
checkRemainingFields(txStartMarker.numNoteHashes, 'note hashes');
|
|
39
|
+
const noteHashes = reader.readFieldArray(txStartMarker.numNoteHashes);
|
|
40
|
+
checkRemainingFields(txStartMarker.numNullifiers, 'nullifiers');
|
|
41
|
+
const nullifiers = reader.readFieldArray(txStartMarker.numNullifiers);
|
|
42
|
+
checkRemainingFields(txStartMarker.numL2ToL1Msgs, 'l2-to-l1 messages');
|
|
43
|
+
const l2ToL1Msgs = reader.readFieldArray(txStartMarker.numL2ToL1Msgs);
|
|
44
|
+
checkRemainingFields(txStartMarker.numPublicDataWrites * 2, 'public data writes'); // *2 for leaf slot and value
|
|
45
|
+
const publicDataWrites = chunk(reader.readFieldArray(txStartMarker.numPublicDataWrites * 2), 2);
|
|
46
|
+
const privateLogs = Array.from({
|
|
47
|
+
length: txStartMarker.numPrivateLogs
|
|
48
|
+
}, ()=>{
|
|
49
|
+
const length = reader.readU32();
|
|
50
|
+
checkRemainingFields(length, 'private log');
|
|
51
|
+
return reader.readFieldArray(length);
|
|
52
|
+
});
|
|
53
|
+
checkRemainingFields(txStartMarker.publicLogsLength, 'public logs');
|
|
54
|
+
const publicLogs = reader.readFieldArray(txStartMarker.publicLogsLength);
|
|
55
|
+
const contractClassLogBlobDataLength = txStartMarker.contractClassLogLength > 0 ? txStartMarker.contractClassLogLength + 1 : 0; // If the log exists, +1 for the contract address
|
|
56
|
+
checkRemainingFields(contractClassLogBlobDataLength, 'contract class logs');
|
|
57
|
+
const contractClassLog = reader.readFieldArray(contractClassLogBlobDataLength);
|
|
58
|
+
return {
|
|
59
|
+
txStartMarker,
|
|
60
|
+
txHash,
|
|
61
|
+
transactionFee,
|
|
62
|
+
noteHashes,
|
|
63
|
+
nullifiers,
|
|
64
|
+
l2ToL1Msgs,
|
|
65
|
+
publicDataWrites,
|
|
66
|
+
privateLogs,
|
|
67
|
+
publicLogs,
|
|
68
|
+
contractClassLog
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function getNumTxBlobFields(txStartMarker) {
|
|
72
|
+
return 1 + // tx start marker
|
|
73
|
+
1 + // tx hash
|
|
74
|
+
1 + // transaction fee
|
|
75
|
+
txStartMarker.numNoteHashes + txStartMarker.numNullifiers + txStartMarker.numL2ToL1Msgs + txStartMarker.numPublicDataWrites * 2 + // *2 for leaf slot and value per public data write
|
|
76
|
+
txStartMarker.numPrivateLogs + // +1 length field for each private log
|
|
77
|
+
txStartMarker.privateLogsLength + txStartMarker.publicLogsLength + txStartMarker.contractClassLogLength + (txStartMarker.contractClassLogLength > 0 ? 1 : 0 // +1 for contract address of the contract class log
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
export interface TxStartMarker {
|
|
3
|
+
numBlobFields: number;
|
|
4
|
+
revertCode: number;
|
|
5
|
+
numNoteHashes: number;
|
|
6
|
+
numNullifiers: number;
|
|
7
|
+
numL2ToL1Msgs: number;
|
|
8
|
+
numPublicDataWrites: number;
|
|
9
|
+
numPrivateLogs: number;
|
|
10
|
+
privateLogsLength: number;
|
|
11
|
+
publicLogsLength: number;
|
|
12
|
+
contractClassLogLength: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function encodeTxStartMarker(txStartMarker: TxStartMarker): Fr;
|
|
15
|
+
export declare function decodeTxStartMarker(field: Fr): TxStartMarker;
|
|
16
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfc3RhcnRfbWFya2VyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZW5jb2RpbmcvdHhfc3RhcnRfbWFya2VyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQWlCcEQsTUFBTSxXQUFXLGFBQWE7SUFDNUIsYUFBYSxFQUFFLE1BQU0sQ0FBQztJQUN0QixVQUFVLEVBQUUsTUFBTSxDQUFDO0lBQ25CLGFBQWEsRUFBRSxNQUFNLENBQUM7SUFDdEIsYUFBYSxFQUFFLE1BQU0sQ0FBQztJQUN0QixhQUFhLEVBQUUsTUFBTSxDQUFDO0lBQ3RCLG1CQUFtQixFQUFFLE1BQU0sQ0FBQztJQUM1QixjQUFjLEVBQUUsTUFBTSxDQUFDO0lBQ3ZCLGlCQUFpQixFQUFFLE1BQU0sQ0FBQztJQUMxQixnQkFBZ0IsRUFBRSxNQUFNLENBQUM7SUFDekIsc0JBQXNCLEVBQUUsTUFBTSxDQUFDO0NBQ2hDO0FBRUQsd0JBQWdCLG1CQUFtQixDQUFDLGFBQWEsRUFBRSxhQUFhLEdBQUcsRUFBRSxDQXVCcEU7QUFFRCx3QkFBZ0IsbUJBQW1CLENBQUMsS0FBSyxFQUFFLEVBQUUsR0FBRyxhQUFhLENBd0M1RCJ9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tx_start_marker.d.ts","sourceRoot":"","sources":["../../src/encoding/tx_start_marker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAiBpD,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB,EAAE,MAAM,CAAC;CAChC;AAED,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,EAAE,CAuBpE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,EAAE,GAAG,aAAa,CAwC5D"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
3
|
-
import {
|
|
1
|
+
import { TX_START_PREFIX } from '@aztec/constants';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { BlobDeserializationError } from '../errors.js';
|
|
4
|
+
// Must match the implementation in `noir-protocol-circuits/crates/types/src/blob_data/tx_blob_data.nr`.
|
|
4
5
|
const NUM_BLOB_FIELDS_BIT_SIZE = 32n;
|
|
5
6
|
const REVERT_CODE_BIT_SIZE = 8n;
|
|
6
7
|
const NUM_NOTE_HASH_BIT_SIZE = 16n;
|
|
@@ -8,9 +9,9 @@ const NUM_NULLIFIER_BIT_SIZE = 16n;
|
|
|
8
9
|
const NUM_L2_TO_L1_MSG_BIT_SIZE = 16n;
|
|
9
10
|
const NUM_PUBLIC_DATA_WRITE_BIT_SIZE = 16n;
|
|
10
11
|
const NUM_PRIVATE_LOG_BIT_SIZE = 16n;
|
|
12
|
+
const PRIVATE_LOGS_LENGTH_BIT_SIZE = 16n;
|
|
11
13
|
const PUBLIC_LOGS_LENGTH_BIT_SIZE = 32n;
|
|
12
14
|
const CONTRACT_CLASS_LOG_LENGTH_BIT_SIZE = 16n;
|
|
13
|
-
// Must match the implementation in `noir-protocol-circuits/crates/rollup-lib/src/tx_base/components/tx_blob_data.nr`.
|
|
14
15
|
export function encodeTxStartMarker(txStartMarker) {
|
|
15
16
|
let value = TX_START_PREFIX;
|
|
16
17
|
value <<= NUM_NOTE_HASH_BIT_SIZE;
|
|
@@ -23,6 +24,8 @@ export function encodeTxStartMarker(txStartMarker) {
|
|
|
23
24
|
value += BigInt(txStartMarker.numPublicDataWrites);
|
|
24
25
|
value <<= NUM_PRIVATE_LOG_BIT_SIZE;
|
|
25
26
|
value += BigInt(txStartMarker.numPrivateLogs);
|
|
27
|
+
value <<= PRIVATE_LOGS_LENGTH_BIT_SIZE;
|
|
28
|
+
value += BigInt(txStartMarker.privateLogsLength);
|
|
26
29
|
value <<= PUBLIC_LOGS_LENGTH_BIT_SIZE;
|
|
27
30
|
value += BigInt(txStartMarker.publicLogsLength);
|
|
28
31
|
value <<= CONTRACT_CLASS_LOG_LENGTH_BIT_SIZE;
|
|
@@ -43,6 +46,8 @@ export function decodeTxStartMarker(field) {
|
|
|
43
46
|
value >>= CONTRACT_CLASS_LOG_LENGTH_BIT_SIZE;
|
|
44
47
|
const publicLogsLength = Number(value & 2n ** PUBLIC_LOGS_LENGTH_BIT_SIZE - 1n);
|
|
45
48
|
value >>= PUBLIC_LOGS_LENGTH_BIT_SIZE;
|
|
49
|
+
const privateLogsLength = Number(value & 2n ** PRIVATE_LOGS_LENGTH_BIT_SIZE - 1n);
|
|
50
|
+
value >>= PRIVATE_LOGS_LENGTH_BIT_SIZE;
|
|
46
51
|
const numPrivateLogs = Number(value & 2n ** NUM_PRIVATE_LOG_BIT_SIZE - 1n);
|
|
47
52
|
value >>= NUM_PRIVATE_LOG_BIT_SIZE;
|
|
48
53
|
const numPublicDataWrites = Number(value & 2n ** NUM_PUBLIC_DATA_WRITE_BIT_SIZE - 1n);
|
|
@@ -53,11 +58,11 @@ export function decodeTxStartMarker(field) {
|
|
|
53
58
|
value >>= NUM_NULLIFIER_BIT_SIZE;
|
|
54
59
|
const numNoteHashes = Number(value & 2n ** NUM_NOTE_HASH_BIT_SIZE - 1n);
|
|
55
60
|
value >>= NUM_NOTE_HASH_BIT_SIZE;
|
|
56
|
-
// Do not throw if the prefix doesn't match.
|
|
57
|
-
// The caller function can check it by calling `isValidTxStartMarker`, and decide what to do if it's incorrect.
|
|
58
61
|
const prefix = value;
|
|
62
|
+
if (prefix !== TX_START_PREFIX) {
|
|
63
|
+
throw new BlobDeserializationError(`Incorrect encoding of blob fields: invalid tx start marker.`);
|
|
64
|
+
}
|
|
59
65
|
return {
|
|
60
|
-
prefix,
|
|
61
66
|
numBlobFields,
|
|
62
67
|
revertCode,
|
|
63
68
|
numNoteHashes,
|
|
@@ -65,59 +70,8 @@ export function decodeTxStartMarker(field) {
|
|
|
65
70
|
numL2ToL1Msgs,
|
|
66
71
|
numPublicDataWrites,
|
|
67
72
|
numPrivateLogs,
|
|
73
|
+
privateLogsLength,
|
|
68
74
|
publicLogsLength,
|
|
69
75
|
contractClassLogLength
|
|
70
76
|
};
|
|
71
77
|
}
|
|
72
|
-
export function getNumBlobFieldsFromTxStartMarker(field) {
|
|
73
|
-
return Number(field.toBigInt() & 2n ** NUM_BLOB_FIELDS_BIT_SIZE - 1n);
|
|
74
|
-
}
|
|
75
|
-
export function isValidTxStartMarker(txStartMarker) {
|
|
76
|
-
return txStartMarker.prefix === TX_START_PREFIX;
|
|
77
|
-
}
|
|
78
|
-
export function createBlockEndMarker(numTxs) {
|
|
79
|
-
// Must match the implementation in `block_rollup_public_inputs_composer.nr > create_block_end_marker`.
|
|
80
|
-
return new Fr(BLOCK_END_PREFIX * 256n * 256n + BigInt(numTxs));
|
|
81
|
-
}
|
|
82
|
-
export function getNumTxsFromBlockEndMarker(field) {
|
|
83
|
-
return Number(field.toBigInt() & 0xffffn);
|
|
84
|
-
}
|
|
85
|
-
export function isBlockEndMarker(field) {
|
|
86
|
-
const value = field.toBigInt();
|
|
87
|
-
const numTxs = value & 0xffffn;
|
|
88
|
-
return value - numTxs === BLOCK_END_PREFIX * 256n * 256n;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Check that the fields are emitted from the circuits and conform to the encoding.
|
|
92
|
-
* @param blobFields - The concatenated fields from all blobs of an L1 block.
|
|
93
|
-
*/ export function checkBlobFieldsEncoding(blobFields) {
|
|
94
|
-
const reader = FieldReader.asReader(blobFields);
|
|
95
|
-
const checkpointPrefix = reader.readField();
|
|
96
|
-
if (checkpointPrefix.toBigInt() !== BigInt(blobFields.length)) {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
const numFieldsInCheckpoint = checkpointPrefix.toNumber();
|
|
100
|
-
let seenNumTxs = 0;
|
|
101
|
-
while(reader.cursor < numFieldsInCheckpoint){
|
|
102
|
-
const currentField = reader.readField();
|
|
103
|
-
if (isBlockEndMarker(currentField)) {
|
|
104
|
-
// Found a block end marker. Confirm that the number of txs in this block is correct.
|
|
105
|
-
const numTxs = getNumTxsFromBlockEndMarker(currentField);
|
|
106
|
-
if (numTxs !== seenNumTxs) {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
seenNumTxs = 0;
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
// If the field is not a block end marker, it must be a tx start marker.
|
|
113
|
-
const txStartMarker = decodeTxStartMarker(currentField);
|
|
114
|
-
if (!isValidTxStartMarker(txStartMarker)) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
seenNumTxs += 1;
|
|
118
|
-
// Skip the remaining fields in this tx. -1 because we already read the tx start marker.
|
|
119
|
-
reader.skip(txStartMarker.numBlobFields - 1);
|
|
120
|
-
// TODO: Check the encoding of the tx if we want to be more strict.
|
|
121
|
-
}
|
|
122
|
-
return true;
|
|
123
|
-
}
|
package/dest/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare class BlobDeserializationError extends Error {
|
|
2
2
|
constructor(message: string);
|
|
3
3
|
}
|
|
4
|
-
//# sourceMappingURL=
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvZXJyb3JzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLHFCQUFhLHdCQUF5QixTQUFRLEtBQUs7SUFDakQsWUFBWSxPQUFPLEVBQUUsTUFBTSxFQUcxQjtDQUNGIn0=
|
package/dest/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,wBAAyB,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF"}
|
package/dest/hash.d.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { BLS12Fr
|
|
1
|
+
import { BLS12Fr } from '@aztec/foundation/curves/bls12';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
/**
|
|
3
4
|
* Returns ethereum's versioned blob hash, following kzg_to_versioned_hash: https://eips.ethereum.org/EIPS/eip-4844#helpers
|
|
4
5
|
*/
|
|
5
6
|
export declare function computeEthVersionedBlobHash(commitment: Buffer): Buffer;
|
|
6
7
|
export declare function computeBlobsHash(evmVersionedBlobHashes: Buffer[]): Fr;
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* This
|
|
9
|
+
* Computes a non-standard Poseidon2 hash over the provided fields.
|
|
10
|
+
*
|
|
11
|
+
* This function is used to compute:
|
|
12
|
+
* - `blobFieldsHash` of a checkpoint:
|
|
13
|
+
* Verified in the circuit against all fields absorbed into the blob sponge over the entire checkpoint.
|
|
14
|
+
* The exact number of fields is encoded in the checkpoint end marker (the last field).
|
|
15
|
+
* This hash is used when generating the challenge `z` for all blobs in the checkpoint.
|
|
16
|
+
* - `spongeBlobHash` of a block:
|
|
17
|
+
* Computed from the block's tx effects, its end-state, and the blob fields of all prior blocks in the same checkpoint.
|
|
18
|
+
* This hash is included in the block header.
|
|
11
19
|
*/
|
|
12
20
|
export declare function computeBlobFieldsHash(fields: Fr[]): Promise<Fr>;
|
|
13
21
|
export declare function computeBlobCommitment(data: Uint8Array): Buffer;
|
|
@@ -32,4 +40,4 @@ export declare function computeChallengeZ(blobFieldsHash: Fr, commitment: Buffer
|
|
|
32
40
|
* rollup circuits.
|
|
33
41
|
*/
|
|
34
42
|
export declare function hashNoirBigNumLimbs(field: BLS12Fr): Promise<Fr>;
|
|
35
|
-
//# sourceMappingURL=
|
|
43
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGFzaC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2hhc2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ3pELE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQU9wRDs7R0FFRztBQUNILHdCQUFnQiwyQkFBMkIsQ0FBQyxVQUFVLEVBQUUsTUFBTSxHQUFHLE1BQU0sQ0FJdEU7QUFPRCx3QkFBZ0IsZ0JBQWdCLENBQUMsc0JBQXNCLEVBQUUsTUFBTSxFQUFFLEdBQUcsRUFBRSxDQUVyRTtBQUVEOzs7Ozs7Ozs7OztHQVdHO0FBQ0gsd0JBQXNCLHFCQUFxQixDQUFDLE1BQU0sRUFBRSxFQUFFLEVBQUUsR0FBRyxPQUFPLENBQUMsRUFBRSxDQUFDLENBSXJFO0FBRUQsd0JBQWdCLHFCQUFxQixDQUFDLElBQUksRUFBRSxVQUFVLEdBQUcsTUFBTSxDQU05RDtBQUVEOzs7Ozs7Ozs7Ozs7O0dBYUc7QUFDSCx3QkFBZ0Isa0JBQWtCLENBQUMsVUFBVSxFQUFFLE1BQU0sR0FBRyxDQUFDLEVBQUUsRUFBRSxFQUFFLENBQUMsQ0FNL0Q7QUFFRCx3QkFBc0IsaUJBQWlCLENBQUMsY0FBYyxFQUFFLEVBQUUsRUFBRSxVQUFVLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxFQUFFLENBQUMsQ0FHM0Y7QUFFRDs7O0dBR0c7QUFDSCx3QkFBc0IsbUJBQW1CLENBQUMsS0FBSyxFQUFFLE9BQU8sR0FBRyxPQUFPLENBQUMsRUFBRSxDQUFDLENBR3JFIn0=
|
package/dest/hash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAOpD;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAItE;AAOD,wBAAgB,gBAAgB,CAAC,sBAAsB,EAAE,MAAM,EAAE,GAAG,EAAE,CAErE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,CAIrE;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAM9D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAM/D;AAED,wBAAsB,iBAAiB,CAAC,cAAc,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC,CAG3F;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC,CAGrE"}
|
package/dest/hash.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { poseidon2Hash
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
2
|
+
import { sha256, sha256ToField } from '@aztec/foundation/crypto/sha256';
|
|
3
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
+
import { BYTES_PER_BLOB, BYTES_PER_COMMITMENT, getKzg } from './kzg_context.js';
|
|
5
|
+
import { SpongeBlob } from './sponge_blob.js';
|
|
4
6
|
const VERSIONED_HASH_VERSION_KZG = 0x01;
|
|
5
7
|
/**
|
|
6
8
|
* Returns ethereum's versioned blob hash, following kzg_to_versioned_hash: https://eips.ethereum.org/EIPS/eip-4844#helpers
|
|
@@ -18,17 +20,26 @@ export function computeBlobsHash(evmVersionedBlobHashes) {
|
|
|
18
20
|
return sha256ToField(evmVersionedBlobHashes);
|
|
19
21
|
}
|
|
20
22
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* This
|
|
23
|
+
* Computes a non-standard Poseidon2 hash over the provided fields.
|
|
24
|
+
*
|
|
25
|
+
* This function is used to compute:
|
|
26
|
+
* - `blobFieldsHash` of a checkpoint:
|
|
27
|
+
* Verified in the circuit against all fields absorbed into the blob sponge over the entire checkpoint.
|
|
28
|
+
* The exact number of fields is encoded in the checkpoint end marker (the last field).
|
|
29
|
+
* This hash is used when generating the challenge `z` for all blobs in the checkpoint.
|
|
30
|
+
* - `spongeBlobHash` of a block:
|
|
31
|
+
* Computed from the block's tx effects, its end-state, and the blob fields of all prior blocks in the same checkpoint.
|
|
32
|
+
* This hash is included in the block header.
|
|
24
33
|
*/ export async function computeBlobFieldsHash(fields) {
|
|
25
|
-
|
|
34
|
+
const sponge = SpongeBlob.init();
|
|
35
|
+
await sponge.absorb(fields);
|
|
36
|
+
return sponge.squeeze();
|
|
26
37
|
}
|
|
27
38
|
export function computeBlobCommitment(data) {
|
|
28
39
|
if (data.length !== BYTES_PER_BLOB) {
|
|
29
40
|
throw new Error(`Expected ${BYTES_PER_BLOB} bytes per blob. Got ${data.length}.`);
|
|
30
41
|
}
|
|
31
|
-
return Buffer.from(
|
|
42
|
+
return Buffer.from(getKzg().blobToKzgCommitment(data));
|
|
32
43
|
}
|
|
33
44
|
/**
|
|
34
45
|
* Get the commitment fields of the blob, to compute the challenge z.
|
package/dest/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
export * from './batched_blob.js';
|
|
1
2
|
export * from './blob.js';
|
|
2
3
|
export * from './blob_batching.js';
|
|
3
4
|
export * from './blob_utils.js';
|
|
4
5
|
export * from './circuit_types/index.js';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './encoding.js';
|
|
7
|
-
export * from './errors.js';
|
|
6
|
+
export * from './encoding/index.js';
|
|
8
7
|
export * from './hash.js';
|
|
9
8
|
export * from './interface.js';
|
|
10
9
|
export * from './sponge_blob.js';
|
|
11
|
-
|
|
10
|
+
export * from './kzg_context.js';
|
|
11
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLG1CQUFtQixDQUFDO0FBQ2xDLGNBQWMsV0FBVyxDQUFDO0FBQzFCLGNBQWMsb0JBQW9CLENBQUM7QUFDbkMsY0FBYyxpQkFBaUIsQ0FBQztBQUNoQyxjQUFjLDBCQUEwQixDQUFDO0FBQ3pDLGNBQWMscUJBQXFCLENBQUM7QUFDcEMsY0FBYyxXQUFXLENBQUM7QUFDMUIsY0FBYyxnQkFBZ0IsQ0FBQztBQUMvQixjQUFjLGtCQUFrQixDQUFDO0FBQ2pDLGNBQWMsa0JBQWtCLENBQUMifQ==
|
package/dest/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
package/dest/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
export * from './batched_blob.js';
|
|
1
2
|
export * from './blob.js';
|
|
2
3
|
export * from './blob_batching.js';
|
|
3
4
|
export * from './blob_utils.js';
|
|
4
5
|
export * from './circuit_types/index.js';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './encoding.js';
|
|
7
|
-
export * from './errors.js';
|
|
6
|
+
export * from './encoding/index.js';
|
|
8
7
|
export * from './hash.js';
|
|
9
8
|
export * from './interface.js';
|
|
10
9
|
export * from './sponge_blob.js';
|
|
10
|
+
export * from './kzg_context.js';
|
package/dest/interface.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export interface BlobJson {
|
|
|
6
6
|
index: string;
|
|
7
7
|
kzg_commitment: string;
|
|
8
8
|
}
|
|
9
|
-
//# sourceMappingURL=
|
|
9
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW50ZXJmYWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW50ZXJmYWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxXQUFXLFFBQVE7SUFDdkIsSUFBSSxFQUFFLE1BQU0sQ0FBQztJQUNiLEtBQUssRUFBRSxNQUFNLENBQUM7SUFDZCxjQUFjLEVBQUUsTUFBTSxDQUFDO0NBQ3hCIn0=
|
package/dest/kzg_context.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { DasContextJs } from '@crate-crypto/node-eth-kzg';
|
|
2
2
|
export * from '@crate-crypto/node-eth-kzg';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Returns the lazily-initialized KZG context.
|
|
5
|
+
* The first call takes ~3 seconds to initialize the precomputation tables.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getKzg(): DasContextJs;
|
|
8
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoia3pnX2NvbnRleHQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9remdfY29udGV4dC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sNEJBQTRCLENBQUM7QUFFMUQsY0FBYyw0QkFBNEIsQ0FBQztBQUkzQzs7O0dBR0c7QUFDSCx3QkFBZ0IsTUFBTSxJQUFJLFlBQVksQ0FLckMifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kzg_context.d.ts","sourceRoot":"","sources":["../src/kzg_context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,cAAc,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"kzg_context.d.ts","sourceRoot":"","sources":["../src/kzg_context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,cAAc,4BAA4B,CAAC;AAI3C;;;GAGG;AACH,wBAAgB,MAAM,IAAI,YAAY,CAKrC"}
|
package/dest/kzg_context.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { DasContextJs } from '@crate-crypto/node-eth-kzg';
|
|
2
2
|
export * from '@crate-crypto/node-eth-kzg';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
let kzgInstance;
|
|
4
|
+
/**
|
|
5
|
+
* Returns the lazily-initialized KZG context.
|
|
6
|
+
* The first call takes ~3 seconds to initialize the precomputation tables.
|
|
7
|
+
*/ export function getKzg() {
|
|
8
|
+
if (!kzgInstance) {
|
|
9
|
+
kzgInstance = DasContextJs.create({
|
|
10
|
+
usePrecomp: true
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return kzgInstance;
|
|
14
|
+
}
|