Skip to content

Commit ed6ff65

Browse files
committed
add blob type 3: validium
1 parent 0502a81 commit ed6ff65

File tree

5 files changed

+72
-12
lines changed

5 files changed

+72
-12
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"eslint:fix": "npx eslint 'src/**/**.js' 'test/**/**.test.js' --fix && npx eslint tools --fix",
1515
"test:update": "./tools/update-tests/update-tests.sh",
1616
"test:database": "npx mocha ./test/database.test.js",
17-
"build:inputs": "npx mocha ./test/processor.test.js --update --geninputs && npx mocha ./test/processor.test.js --etrog --update --geninputs"
17+
"build:inputs": "npx mocha ./test/processor.test.js --update --geninputs && npx mocha ./test/processor.test.js --etrog --update --geninputs",
18+
"build:blob-inputs": "npx mocha ./test/blob-inner/blob-inner-processor.test.js --update --geninput"
1819
},
1920
"repository": {
2021
"type": "git",

src/blob-inner/blob-constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports.BLOB_TYPE = {
1919
CALLDATA: 0,
2020
EIP4844: 1,
2121
FORCED: 2,
22+
VALIDIUM: 3,
2223
};
2324

2425
// Blob compression type

src/blob-inner/blob-processor.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { getCurrentDB } = require('../smt-utils');
1111
const getKzg = require('./kzg-utils');
1212

1313
const {
14-
isHex, computeBlobAccInputHash, computeBlobL2HashData,
14+
isHex, computeBlobAccInputHash, computeBlobL2HashKData, computeBlobL2HashPData,
1515
computeBatchL2HashData, computeBatchAccInputHash, computeBlobDataFromBatches, parseBlobData,
1616
computeVersionedHash, reduceBlobData,
1717
} = require('./blob-utils');
@@ -188,7 +188,8 @@ module.exports = class BlobProcessor {
188188
_checkBlobType() {
189189
if (this.blobType !== blobConstants.BLOB_TYPE.CALLDATA
190190
&& this.blobType !== blobConstants.BLOB_TYPE.EIP4844
191-
&& this.blobType !== blobConstants.BLOB_TYPE.FORCED) {
191+
&& this.blobType !== blobConstants.BLOB_TYPE.FORCED
192+
&& this.blobType !== blobConstants.BLOB_TYPE.VALIDIUM) {
192193
if (this.addingBatchData === true) {
193194
throw new Error('BlobProcessor:executeBlob: invalid blob type not compatible with batch data');
194195
}
@@ -248,7 +249,7 @@ module.exports = class BlobProcessor {
248249
// compute points Z & Y dependng on the blob type. Otherwise, compute batchL2HashData
249250
if (this.blobType === blobConstants.BLOB_TYPE.CALLDATA || this.blobType === blobConstants.BLOB_TYPE.FORCED) {
250251
// compute blobL2HashData
251-
this.blobL2HashData = await computeBlobL2HashData(this.blobData);
252+
this.blobL2HashData = await computeBlobL2HashKData(this.blobData);
252253
// points not used
253254
this.kzgCommitment = Constants.ZERO_BYTES32;
254255
this.versionedHash = Constants.ZERO_BYTES32;
@@ -266,6 +267,15 @@ module.exports = class BlobProcessor {
266267
const { proof, pointY } = this.kzg.computeKzgProof(reducedBlobData, this.pointZ);
267268
this.pointY = pointY;
268269
this.kzgProof = proof;
270+
} else if (this.blobType === blobConstants.BLOB_TYPE.VALIDIUM) {
271+
// compute blobL2HashData
272+
this.blobL2HashData = await computeBlobL2HashPData(this.blobData);
273+
// points not used
274+
this.kzgCommitment = Constants.ZERO_BYTES32;
275+
this.versionedHash = Constants.ZERO_BYTES32;
276+
this.pointZ = Constants.ZERO_BYTES32;
277+
this.pointY = Constants.ZERO_BYTES32;
278+
this.proof = Constants.ZERO_BYTES32;
269279
} else {
270280
// enter here only if blobType is invalid. Hence, blobData has been added previously
271281
// blobL2HashData not used

src/blob-inner/blob-utils.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ async function computeBatchAccInputHash(
105105
}
106106

107107
/**
108-
* Blob hash data
108+
* Blob hash data (keccak256)
109109
* @param {String} blobData - Blob data
110-
* @returns {String} - Blob hash data
110+
* @returns {String} - Blob hash data (keccak256)
111111
*/
112-
function computeBlobL2HashData(blobData) {
112+
function computeBlobL2HashKData(blobData) {
113113
blobData = blobData.startsWith('0x') ? blobData : `0x${blobData}`;
114114

115115
return ethers.utils.solidityKeccak256(
@@ -118,6 +118,17 @@ function computeBlobL2HashData(blobData) {
118118
);
119119
}
120120

121+
/**
122+
* Blob hash data (poseidon)
123+
* @param {String} blobData - Blob data
124+
* @returns {String} - Blob hash data (poseidon)
125+
*/
126+
function computeBlobL2HashPData(blobData) {
127+
blobData = blobData.startsWith('0x') ? blobData : `0x${blobData}`;
128+
129+
return linearPoseidon(blobData);
130+
}
131+
121132
/**
122133
* Batch hash data
123134
* @param {String} batchL2Data - Batch L2 data input in hex string
@@ -233,7 +244,7 @@ function computeBlobDataFromBatches(batches, blobType) {
233244
resBlobdata += batchesData;
234245

235246
let blobData;
236-
if (blobType === blobConstants.BLOB_TYPE.CALLDATA || blobType === blobConstants.BLOB_TYPE.FORCED) {
247+
if (blobType === blobConstants.BLOB_TYPE.CALLDATA || blobType === blobConstants.BLOB_TYPE.FORCED || blobType === blobConstants.BLOB_TYPE.VALIDIUM) {
237248
blobData = resBlobdata;
238249
} else if (blobType === blobConstants.BLOB_TYPE.EIP4844) {
239250
// build blob data with no spaces and then add 0x00 each 32 bytes
@@ -265,7 +276,7 @@ function parseBlobData(blobData, blobType) {
265276
const batches = [];
266277

267278
// if blobData is calldata or forced, no need to check and remove MSB each 32 bytes
268-
if (blobType === blobConstants.BLOB_TYPE.CALLDATA || blobType === blobConstants.BLOB_TYPE.FORCED) {
279+
if (blobType === blobConstants.BLOB_TYPE.CALLDATA || blobType === blobConstants.BLOB_TYPE.FORCED || blobType === blobConstants.BLOB_TYPE.VALIDIUM) {
269280
tmpBlobdata = blobData;
270281
} else if (blobType === blobConstants.BLOB_TYPE.EIP4844) {
271282
// assure the most significant byte is '00' each slot of 32 bytes
@@ -372,7 +383,8 @@ function reduceBlobData(_blobData) {
372383
module.exports = {
373384
isHex,
374385
computeBlobAccInputHash,
375-
computeBlobL2HashData,
386+
computeBlobL2HashKData,
387+
computeBlobL2HashPData,
376388
buildPointZData,
377389
computePointZ,
378390
computePointY,

test/helpers/test-vectors/blob-inner/blob-inner-data.json

Lines changed: 38 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)