Skip to content

Commit

Permalink
Fix audittens L04 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless authored Dec 2, 2024
1 parent fd7e4cd commit ae91ae4
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions da-contracts/contracts/RollupL1DAValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ import {PubdataCommitmentsEmpty, InvalidPubdataCommitmentsSize, BlobHashCommitme

uint256 constant BLOBS_SUPPORTED = 6;

/// @dev The number of blocks within each we allow blob to be used for DA.
/// On Ethereum blobs expire within 4096 slots, i.e. 4096 * 32 blocks. We reserve
/// half of the time in order to ensure reader's ability to read the blob's content.
uint256 constant BLOB_EXPIRATION_BLOCKS = (4096 * 32) / 2;

contract RollupL1DAValidator is IL1DAValidator, CalldataDA {
/// @dev The published blob commitments. Note, that the correctness of blob commitment with relation to the linear hash
/// @notice The published blob commitments. Note, that the correctness of blob commitment with relation to the linear hash
/// is *not* checked in this contract, but is expected to be checked at the verification stage of the ZK contract.
mapping(bytes32 blobCommitment => bool isPublished) public publishedBlobCommitments;
mapping(bytes32 blobCommitment => uint256 blockOfPublishing) public publishedBlobCommitments;

/// @notice Publishes certain blobs, marking commitments to them as published.
/// @param _pubdataCommitments The commitments to the blobs to be published.
Expand All @@ -38,11 +43,19 @@ contract RollupL1DAValidator is IL1DAValidator, CalldataDA {
versionedHashIndex,
_pubdataCommitments[i:i + PUBDATA_COMMITMENT_SIZE]
);
publishedBlobCommitments[blobCommitment] = true;
publishedBlobCommitments[blobCommitment] = block.number;
++versionedHashIndex;
}
}

function isBlobAvailable(bytes32 _blobCommitment) public view returns (bool) {
uint256 blockOfPublishing = publishedBlobCommitments[_blobCommitment];

// While `block.number` on all used L1 networks is much higher than `BLOB_EXPIRATION_BLOCKS`,
// we still check that `blockOfPublishing > 0` just in case.
return blockOfPublishing > 0 && block.number - blockOfPublishing <= BLOB_EXPIRATION_BLOCKS;
}

/// @inheritdoc IL1DAValidator
function checkDA(
uint256, // _chainId
Expand Down Expand Up @@ -145,7 +158,7 @@ contract RollupL1DAValidator is IL1DAValidator, CalldataDA {
if (prepublishedCommitment != bytes32(0)) {
// We double check that this commitment has indeed been published.
// If that is the case, we do not care about the actual underlying data.
require(publishedBlobCommitments[prepublishedCommitment], "not published");
require(isBlobAvailable(prepublishedCommitment), "not published");

blobsCommitments[i] = prepublishedCommitment;
} else {
Expand Down

0 comments on commit ae91ae4

Please sign in to comment.