Skip to content

Commit 335f063

Browse files
author
jagdeep sidhu
committed
fix for BitcoinDA - support fallback for 64 byte DA input
the DA input should fall back to check that it matches what the RollupL2DAValidator outputs (which is what the RollupL1DAValidator input expects and validates against) which is the 2 32 byte hashes of pubdata (DA for precompile) and state diff hash.
1 parent 7947e09 commit 335f063

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

da-contracts/contracts/CalldataDA.sol

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,15 @@ abstract contract CalldataDA {
6969
uint256 ptr = BLOB_DATA_OFFSET + 32 * blobsProvided;
7070

7171
// Now, we need to double check that the provided input was indeed returned by the L2 DA validator.
72-
if (keccak256(_operatorDAInput[:ptr]) != _l2DAValidatorOutputHash) {
73-
revert InvalidL2DAOutputHash(_l2DAValidatorOutputHash);
72+
// SYSCOIN Accept either the full-header hash (preferred) or the short 64-byte variant used by some L2 DA validators.
73+
{
74+
bytes32 hFull = keccak256(_operatorDAInput[:ptr]);
75+
if (hFull != _l2DAValidatorOutputHash) {
76+
// Fallback: compare against the short (64-byte) prefix (stateDiffHash || fullPubdataHash).
77+
if (keccak256(_operatorDAInput[:64]) != _l2DAValidatorOutputHash) {
78+
revert InvalidL2DAOutputHash(_l2DAValidatorOutputHash);
79+
}
80+
}
7481
}
7582

7683
// The rest of the output was provided specifically by the operator

l1-contracts/contracts/state-transition/data-availability/CalldataDA.sol

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,15 @@ abstract contract CalldataDA {
6969
uint256 ptr = BLOB_DATA_OFFSET + 32 * blobsProvided;
7070

7171
// Now, we need to double check that the provided input was indeed returned by the L2 DA validator.
72-
if (keccak256(_operatorDAInput[:ptr]) != _l2DAValidatorOutputHash) {
73-
revert InvalidL2DAOutputHash(_l2DAValidatorOutputHash);
72+
// SYSCOIN Accept either the full-header hash (preferred) or the short 64-byte variant used by some L2 DA validators.
73+
{
74+
bytes32 hFull = keccak256(_operatorDAInput[:ptr]);
75+
if (hFull != _l2DAValidatorOutputHash) {
76+
// Fallback: compare against the short (64-byte) prefix (stateDiffHash || fullPubdataHash).
77+
if (keccak256(_operatorDAInput[:64]) != _l2DAValidatorOutputHash) {
78+
revert InvalidL2DAOutputHash(_l2DAValidatorOutputHash);
79+
}
80+
}
7481
}
7582

7683
// The rest of the output was provided specifically by the operator

l1-contracts/test/foundry/l1/unit/concrete/state-transition/data-availability/CalldataDA.t.sol

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,36 @@ contract CalldataDATest is Test {
112112
assertEq(blobsLinearHashes[0], blobLinearHash, "blobsLinearHashes");
113113
assertEq(outputL1DaInput, l1DaInput, "l1DaInput");
114114
}
115+
// SYSCOIN
116+
function test_ProcessL2RollupDAValidatorOutputHashWithShortHash() public {
117+
bytes32 stateDiffHash = Utils.randomBytes32("stateDiffHash");
118+
bytes32 fullPubdataHash = Utils.randomBytes32("fullPubdataHash");
119+
uint8 blobsProvided = 1;
120+
bytes32 blobLinearHash = Utils.randomBytes32("blobLinearHash");
121+
122+
bytes memory shortData = abi.encodePacked(stateDiffHash, fullPubdataHash);
123+
bytes memory l1DaInput = "verifydonttrust";
124+
125+
// Use the short (64-byte) hash as the l2DAValidatorOutputHash
126+
bytes32 l2DAValidatorOutputHash = keccak256(shortData);
127+
128+
// Full operator input includes all data
129+
bytes memory operatorDAInput = abi.encodePacked(stateDiffHash, fullPubdataHash, blobsProvided, blobLinearHash, l1DaInput);
130+
131+
(
132+
bytes32 outputStateDiffHash,
133+
bytes32 outputFullPubdataHash,
134+
bytes32[] memory blobsLinearHashes,
135+
uint256 outputBlobsProvided,
136+
bytes memory outputL1DaInput
137+
) = calldataDA.processL2RollupDAValidatorOutputHash(l2DAValidatorOutputHash, blobsProvided, operatorDAInput);
138+
139+
assertEq(outputStateDiffHash, stateDiffHash, "stateDiffHash");
140+
assertEq(outputFullPubdataHash, fullPubdataHash, "fullPubdataHash");
141+
assertEq(blobsLinearHashes.length, 1, "blobsLinearHashesLength");
142+
assertEq(blobsLinearHashes[0], blobLinearHash, "blobsLinearHashes");
143+
assertEq(outputL1DaInput, l1DaInput, "l1DaInput");
144+
}
115145

116146
/*//////////////////////////////////////////////////////////////////////////
117147
CalldataDA::_processCalldataDA

0 commit comments

Comments
 (0)