@aztec/blob-lib 0.0.1-fake-c83136db25 → 0.0.1-fake-ceab37513c
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/blob.d.ts +98 -52
- package/dest/blob.d.ts.map +1 -1
- package/dest/blob.js +167 -73
- package/dest/blob_batching.d.ts +48 -15
- package/dest/blob_batching.d.ts.map +1 -1
- package/dest/blob_batching.js +120 -81
- package/dest/blob_batching_public_inputs.d.ts +71 -0
- package/dest/blob_batching_public_inputs.d.ts.map +1 -0
- package/dest/blob_batching_public_inputs.js +168 -0
- package/dest/encoding.d.ts +62 -22
- package/dest/encoding.d.ts.map +1 -1
- package/dest/encoding.js +104 -114
- package/dest/index.d.ts +2 -5
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +15 -5
- package/dest/sponge_blob.d.ts +9 -13
- package/dest/sponge_blob.d.ts.map +1 -1
- package/dest/sponge_blob.js +17 -28
- package/dest/testing.d.ts +12 -7
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +41 -54
- package/dest/types.d.ts +0 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +0 -2
- package/package.json +4 -5
- package/src/blob.ts +198 -76
- package/src/blob_batching.ts +137 -109
- package/src/blob_batching_public_inputs.ts +252 -0
- package/src/encoding.ts +120 -136
- package/src/index.ts +18 -5
- package/src/sponge_blob.ts +14 -24
- package/src/testing.ts +40 -55
- package/src/types.ts +2 -2
- package/dest/blob_utils.d.ts +0 -30
- package/dest/blob_utils.d.ts.map +0 -1
- package/dest/blob_utils.js +0 -60
- package/dest/circuit_types/blob_accumulator.d.ts +0 -21
- package/dest/circuit_types/blob_accumulator.d.ts.map +0 -1
- package/dest/circuit_types/blob_accumulator.js +0 -58
- package/dest/circuit_types/final_blob_accumulator.d.ts +0 -22
- package/dest/circuit_types/final_blob_accumulator.d.ts.map +0 -1
- package/dest/circuit_types/final_blob_accumulator.js +0 -63
- package/dest/circuit_types/final_blob_batching_challenges.d.ts +0 -15
- package/dest/circuit_types/final_blob_batching_challenges.d.ts.map +0 -1
- package/dest/circuit_types/final_blob_batching_challenges.js +0 -25
- package/dest/circuit_types/index.d.ts +0 -4
- package/dest/circuit_types/index.d.ts.map +0 -1
- package/dest/circuit_types/index.js +0 -4
- package/dest/deserialize.d.ts +0 -14
- package/dest/deserialize.d.ts.map +0 -1
- package/dest/deserialize.js +0 -33
- package/dest/hash.d.ts +0 -35
- package/dest/hash.d.ts.map +0 -1
- package/dest/hash.js +0 -69
- package/dest/kzg_context.d.ts +0 -4
- package/dest/kzg_context.d.ts.map +0 -1
- package/dest/kzg_context.js +0 -5
- package/src/blob_utils.ts +0 -71
- package/src/circuit_types/blob_accumulator.ts +0 -84
- package/src/circuit_types/final_blob_accumulator.ts +0 -75
- package/src/circuit_types/final_blob_batching_challenges.ts +0 -29
- package/src/circuit_types/index.ts +0 -4
- package/src/deserialize.ts +0 -38
- package/src/hash.ts +0 -77
- package/src/kzg_context.ts +0 -5
package/dest/sponge_blob.js
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
import { TWO_POW_64 } from '@aztec/constants';
|
|
2
1
|
import { makeTuple } from '@aztec/foundation/array';
|
|
3
2
|
import { poseidon2Permutation } from '@aztec/foundation/crypto';
|
|
4
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
4
|
import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize';
|
|
6
5
|
/**
|
|
7
|
-
* A Poseidon2 sponge used to accumulate data that will be added to
|
|
6
|
+
* A Poseidon2 sponge used to accumulate data that will be added to a blob.
|
|
8
7
|
* See noir-projects/noir-protocol-circuits/crates/types/src/abis/sponge_blob.nr.
|
|
9
8
|
*/ export class SpongeBlob {
|
|
10
9
|
sponge;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
constructor(/** Sponge with absorbed
|
|
10
|
+
fields;
|
|
11
|
+
expectedFields;
|
|
12
|
+
constructor(/** Sponge with absorbed tx effects that will go into a blob. */ sponge, /** Number of effects absorbed so far. */ fields, /** Number of effects that will be absorbed. */ expectedFields){
|
|
14
13
|
this.sponge = sponge;
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
14
|
+
this.fields = fields;
|
|
15
|
+
this.expectedFields = expectedFields;
|
|
17
16
|
}
|
|
18
17
|
static fromBuffer(buffer) {
|
|
19
18
|
const reader = BufferReader.asReader(buffer);
|
|
20
19
|
return new SpongeBlob(reader.readObject(Poseidon2Sponge), reader.readNumber(), reader.readNumber());
|
|
21
20
|
}
|
|
22
21
|
toBuffer() {
|
|
23
|
-
return serializeToBuffer(
|
|
22
|
+
return serializeToBuffer(this.sponge, this.fields, this.expectedFields);
|
|
24
23
|
}
|
|
25
24
|
static getFields(fields) {
|
|
26
25
|
return [
|
|
27
26
|
fields.sponge,
|
|
28
|
-
fields.
|
|
29
|
-
fields.
|
|
27
|
+
fields.fields,
|
|
28
|
+
fields.expectedFields
|
|
30
29
|
];
|
|
31
30
|
}
|
|
32
31
|
toFields() {
|
|
@@ -40,16 +39,16 @@ import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from
|
|
|
40
39
|
return SpongeBlob.fromBuffer(this.toBuffer());
|
|
41
40
|
}
|
|
42
41
|
async absorb(fields) {
|
|
43
|
-
if (this.
|
|
44
|
-
throw new Error(`Attempted to fill
|
|
42
|
+
if (this.fields + fields.length > this.expectedFields) {
|
|
43
|
+
throw new Error(`Attempted to fill spongeblob with ${this.fields + fields.length}, but it has a max of ${this.expectedFields}`);
|
|
45
44
|
}
|
|
46
45
|
await this.sponge.absorb(fields);
|
|
47
|
-
this.
|
|
46
|
+
this.fields += fields.length;
|
|
48
47
|
}
|
|
49
48
|
async squeeze() {
|
|
50
49
|
// If the blob sponge is not 'full', we append 1 to match Poseidon2::hash_internal()
|
|
51
50
|
// NB: There is currently no use case in which we don't 'fill' a blob sponge, but adding for completeness
|
|
52
|
-
if (this.
|
|
51
|
+
if (this.fields != this.expectedFields) {
|
|
53
52
|
await this.sponge.absorb([
|
|
54
53
|
Fr.ONE
|
|
55
54
|
]);
|
|
@@ -59,18 +58,8 @@ import { BufferReader, FieldReader, serializeToBuffer, serializeToFields } from
|
|
|
59
58
|
static empty() {
|
|
60
59
|
return new SpongeBlob(Poseidon2Sponge.empty(), 0, 0);
|
|
61
60
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
* Note: `numExpectedFields` includes the first field absorbed in this method.
|
|
65
|
-
*/ static async init(numExpectedFields) {
|
|
66
|
-
// This must match what the checkpoint root rollup circuit expects.
|
|
67
|
-
// See noir-projects/noir-protocol-circuits/types/src/abis/sponge_blob.nr -> init_for_checkpoint.
|
|
68
|
-
const sponge = Poseidon2Sponge.init(numExpectedFields);
|
|
69
|
-
await sponge.absorb([
|
|
70
|
-
new Fr(numExpectedFields)
|
|
71
|
-
]);
|
|
72
|
-
const numAbsorbedFields = 1;
|
|
73
|
-
return new SpongeBlob(sponge, numAbsorbedFields, numExpectedFields);
|
|
61
|
+
static init(expectedFields) {
|
|
62
|
+
return new SpongeBlob(Poseidon2Sponge.init(expectedFields), 0, expectedFields);
|
|
74
63
|
}
|
|
75
64
|
}
|
|
76
65
|
// This is just noir's stdlib version of the poseidon2 sponge. We use it for a blob-specific implmentation of the hasher.
|
|
@@ -110,8 +99,8 @@ export class Poseidon2Sponge {
|
|
|
110
99
|
static empty() {
|
|
111
100
|
return new Poseidon2Sponge(makeTuple(3, ()=>Fr.ZERO), makeTuple(4, ()=>Fr.ZERO), 0, false);
|
|
112
101
|
}
|
|
113
|
-
static init(
|
|
114
|
-
const iv = new Fr(
|
|
102
|
+
static init(expectedFields) {
|
|
103
|
+
const iv = new Fr(expectedFields).mul(new Fr(BigInt('18446744073709551616')));
|
|
115
104
|
const sponge = Poseidon2Sponge.empty();
|
|
116
105
|
sponge.state[3] = iv;
|
|
117
106
|
return sponge;
|
package/dest/testing.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { Blob } from './blob.js';
|
|
3
3
|
import { BatchedBlobAccumulator } from './blob_batching.js';
|
|
4
|
+
import { BlockBlobPublicInputs } from './blob_batching_public_inputs.js';
|
|
4
5
|
import { SpongeBlob } from './sponge_blob.js';
|
|
5
6
|
/**
|
|
6
7
|
* Makes arbitrary poseidon sponge for blob inputs.
|
|
@@ -16,9 +17,13 @@ export declare function makeSpongeBlob(seed?: number): SpongeBlob;
|
|
|
16
17
|
* @returns A blob accumulator instance.
|
|
17
18
|
*/
|
|
18
19
|
export declare function makeBatchedBlobAccumulator(seed?: number): BatchedBlobAccumulator;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Makes arbitrary block blob public inputs.
|
|
22
|
+
* Note: will not verify inside the circuit.
|
|
23
|
+
* @param seed - The seed to use for generating the blob inputs.
|
|
24
|
+
* @returns A block blob public inputs instance.
|
|
25
|
+
*/
|
|
26
|
+
export declare function makeBlockBlobPublicInputs(seed?: number): BlockBlobPublicInputs;
|
|
22
27
|
/**
|
|
23
28
|
* Make an encoded blob with the given length
|
|
24
29
|
*
|
|
@@ -26,14 +31,14 @@ export declare function makeEncodedBlobFields(length: number): Fr[];
|
|
|
26
31
|
* @param length
|
|
27
32
|
* @returns
|
|
28
33
|
*/
|
|
29
|
-
export declare function makeEncodedBlob(length: number): Blob
|
|
30
|
-
export declare function makeEncodedBlobs(length: number): Blob[];
|
|
34
|
+
export declare function makeEncodedBlob(length: number): Promise<Blob>;
|
|
31
35
|
/**
|
|
32
|
-
* Make
|
|
36
|
+
* Make an unencoded blob with the given length
|
|
33
37
|
*
|
|
34
38
|
* This will fail deserialisation in the archiver
|
|
35
39
|
* @param length
|
|
36
40
|
* @returns
|
|
37
41
|
*/
|
|
38
|
-
export declare function
|
|
42
|
+
export declare function makeUnencodedBlob(length: number): Promise<Blob>;
|
|
43
|
+
export declare function makeEncodedBlobFields(fields: Fr[]): Promise<Blob>;
|
|
39
44
|
//# sourceMappingURL=testing.d.ts.map
|
package/dest/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,sBAAsB,EAA+B,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAA+B,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAEtG,OAAO,EAAmB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE/D;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,SAAI,GAAG,UAAU,CAWnD;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,SAAI,GAAG,sBAAsB,CAW3E;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,SAAI,GAAG,qBAAqB,CAOzE;AAmBD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/D;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjE"}
|
package/dest/testing.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { FIELDS_PER_BLOB } from '@aztec/constants';
|
|
2
1
|
import { makeTuple } from '@aztec/foundation/array';
|
|
3
|
-
import {
|
|
2
|
+
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
|
|
4
3
|
import { BLS12Fr, BLS12Point, Fr } from '@aztec/foundation/fields';
|
|
5
4
|
import { Blob } from './blob.js';
|
|
6
|
-
import { BatchedBlobAccumulator } from './blob_batching.js';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { createBlockEndMarker, encodeTxStartMarker } from './encoding.js';
|
|
5
|
+
import { BatchedBlobAccumulator, FinalBlobBatchingChallenges } from './blob_batching.js';
|
|
6
|
+
import { BlobAccumulatorPublicInputs, BlockBlobPublicInputs } from './blob_batching_public_inputs.js';
|
|
7
|
+
import { TX_START_PREFIX, TX_START_PREFIX_BYTES_LENGTH } from './encoding.js';
|
|
10
8
|
import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
|
|
11
9
|
/**
|
|
12
10
|
* Makes arbitrary poseidon sponge for blob inputs.
|
|
@@ -24,45 +22,30 @@ import { Poseidon2Sponge, SpongeBlob } from './sponge_blob.js';
|
|
|
24
22
|
*/ export function makeBatchedBlobAccumulator(seed = 1) {
|
|
25
23
|
return new BatchedBlobAccumulator(new Fr(seed), new Fr(seed + 1), new BLS12Fr(seed + 2), BLS12Point.random(), BLS12Point.random(), new Fr(seed + 3), new BLS12Fr(seed + 4), new FinalBlobBatchingChallenges(new Fr(seed + 5), new BLS12Fr(seed + 6)));
|
|
26
24
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
numNullifiers: 0,
|
|
36
|
-
numL2ToL1Msgs: 0,
|
|
37
|
-
numPublicDataWrites: 0,
|
|
38
|
-
numPrivateLogs: 0,
|
|
39
|
-
publicLogsLength: 0,
|
|
40
|
-
contractClassLogLength: 0
|
|
41
|
-
};
|
|
42
|
-
return [
|
|
43
|
-
encodeTxStartMarker(txStartMarker),
|
|
44
|
-
...Array.from({
|
|
45
|
-
length: length - 1
|
|
46
|
-
}, ()=>new Fr(randomInt(Number.MAX_SAFE_INTEGER)))
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
export function makeEncodedBlockBlobFields(...lengths) {
|
|
50
|
-
return [
|
|
51
|
-
...lengths.length > 0 ? makeEncodedTxBlobFields(lengths[0] - 1) : [],
|
|
52
|
-
...lengths.slice(1).flatMap((length)=>makeEncodedTxBlobFields(length)),
|
|
53
|
-
createBlockEndMarker(lengths.length)
|
|
54
|
-
];
|
|
25
|
+
/**
|
|
26
|
+
* Makes arbitrary block blob public inputs.
|
|
27
|
+
* Note: will not verify inside the circuit.
|
|
28
|
+
* @param seed - The seed to use for generating the blob inputs.
|
|
29
|
+
* @returns A block blob public inputs instance.
|
|
30
|
+
*/ export function makeBlockBlobPublicInputs(seed = 1) {
|
|
31
|
+
const startBlobAccumulator = makeBatchedBlobAccumulator(seed);
|
|
32
|
+
return new BlockBlobPublicInputs(BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(startBlobAccumulator), BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(makeBatchedBlobAccumulator(seed + 1)), startBlobAccumulator.finalBlobChallenges);
|
|
55
33
|
}
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
34
|
+
// TODO: copied form stdlib tx effect
|
|
35
|
+
function encodeFirstField(length) {
|
|
36
|
+
const lengthBuf = Buffer.alloc(2);
|
|
37
|
+
lengthBuf.writeUInt16BE(length, 0);
|
|
38
|
+
return new Fr(Buffer.concat([
|
|
39
|
+
toBufferBE(TX_START_PREFIX, TX_START_PREFIX_BYTES_LENGTH),
|
|
40
|
+
Buffer.alloc(1),
|
|
41
|
+
lengthBuf,
|
|
42
|
+
Buffer.alloc(1),
|
|
43
|
+
Buffer.from([
|
|
44
|
+
1
|
|
45
|
+
]),
|
|
46
|
+
Buffer.alloc(1),
|
|
47
|
+
Buffer.alloc(1)
|
|
48
|
+
]));
|
|
66
49
|
}
|
|
67
50
|
/**
|
|
68
51
|
* Make an encoded blob with the given length
|
|
@@ -71,25 +54,29 @@ export function makeEncodedBlobFields(length) {
|
|
|
71
54
|
* @param length
|
|
72
55
|
* @returns
|
|
73
56
|
*/ export function makeEncodedBlob(length) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const fields = makeEncodedBlobFields(length);
|
|
81
|
-
return getBlobsPerL1Block(fields);
|
|
57
|
+
return Blob.fromFields([
|
|
58
|
+
encodeFirstField(length + 1),
|
|
59
|
+
...Array.from({
|
|
60
|
+
length: length
|
|
61
|
+
}, ()=>Fr.random())
|
|
62
|
+
]);
|
|
82
63
|
}
|
|
83
64
|
/**
|
|
84
|
-
* Make
|
|
65
|
+
* Make an unencoded blob with the given length
|
|
85
66
|
*
|
|
86
67
|
* This will fail deserialisation in the archiver
|
|
87
68
|
* @param length
|
|
88
69
|
* @returns
|
|
89
|
-
*/ export function
|
|
70
|
+
*/ export function makeUnencodedBlob(length) {
|
|
90
71
|
return Blob.fromFields([
|
|
91
72
|
...Array.from({
|
|
92
73
|
length: length
|
|
93
74
|
}, ()=>Fr.random())
|
|
94
75
|
]);
|
|
95
76
|
}
|
|
77
|
+
export function makeEncodedBlobFields(fields) {
|
|
78
|
+
return Blob.fromFields([
|
|
79
|
+
encodeFirstField(fields.length + 1),
|
|
80
|
+
...fields
|
|
81
|
+
]);
|
|
82
|
+
}
|
package/dest/types.d.ts
CHANGED
package/dest/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AAIjC;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,wDAAwD;IACxD,mBAAmB,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC;IAClD,kDAAkD;IAClD,mBAAmB,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;IAC1E,8FAA8F;IAC9F,wBAAwB,CAAC,IAAI,EAAE,UAAU,GAAG,CAAC,UAAU,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;CAC1E"}
|
package/dest/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/blob-lib",
|
|
3
|
-
"version": "0.0.1-fake-
|
|
3
|
+
"version": "0.0.1-fake-ceab37513c",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
7
|
-
"./encoding": "./dest/encoding.js",
|
|
8
7
|
"./types": "./dest/types.js",
|
|
9
8
|
"./testing": "./dest/testing.js"
|
|
10
9
|
},
|
|
@@ -27,9 +26,9 @@
|
|
|
27
26
|
"../package.common.json"
|
|
28
27
|
],
|
|
29
28
|
"dependencies": {
|
|
30
|
-
"@aztec/constants": "0.0.1-fake-
|
|
31
|
-
"@aztec/foundation": "0.0.1-fake-
|
|
32
|
-
"
|
|
29
|
+
"@aztec/constants": "0.0.1-fake-ceab37513c",
|
|
30
|
+
"@aztec/foundation": "0.0.1-fake-ceab37513c",
|
|
31
|
+
"c-kzg": "4.1.0",
|
|
33
32
|
"tslib": "^2.4.0"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|