Skip to content

Commit

Permalink
Add status byte to final digest (#9310)
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby authored Feb 2, 2024
1 parent 0872e3e commit ab6e51d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion op-bindings/bindings/alphabetvm.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion op-bindings/bindings/preimageoracle.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion op-bindings/bindings/preimageoracle_more.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/contracts-bedrock/src/cannon/PreimageOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,9 @@ contract PreimageOracle is IPreimageOracle {
LibKeccak.absorb(_stateMatrix, _postState.input);
LibKeccak.permutation(_stateMatrix);
bytes32 finalDigest = LibKeccak.squeeze(_stateMatrix);
assembly {
finalDigest := or(and(finalDigest, not(shl(248, 0xFF))), shl(248, 0x02))
}

// Write the preimage part to the authorized preimage parts mapping.
uint256 partOffset = metaData.partOffset();
Expand Down
11 changes: 9 additions & 2 deletions packages/contracts-bedrock/test/cannon/PreimageOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ contract PreimageOracle_LargePreimageProposals_Test is Test {
_postStateProof: postProof
});

bytes32 finalDigest = keccak256(data);
bytes32 finalDigest = _setStatusByte(keccak256(data), 2);
bytes32 expectedPart = bytes32((~uint256(0) & ~(uint256(type(uint64).max) << 192)) | (data.length << 192));
assertTrue(oracle.preimagePartOk(finalDigest, 0));
assertEq(oracle.preimageLengths(finalDigest), data.length);
Expand Down Expand Up @@ -727,7 +727,7 @@ contract PreimageOracle_LargePreimageProposals_Test is Test {

// Validate the preimage part
{
bytes32 finalDigest = keccak256(data);
bytes32 finalDigest = _setStatusByte(keccak256(data), 2);
bytes32 expectedPart;
assembly {
switch lt(_partOffset, 0x08)
Expand Down Expand Up @@ -1269,3 +1269,10 @@ contract PreimageOracle_LargePreimageProposals_Test is Test {
(root_, proof_) = abi.decode(vm.ffi(commands), (bytes32, bytes32[]));
}
}

/// @notice Sets the status byte of a hash.
function _setStatusByte(bytes32 _hash, uint8 _status) pure returns (bytes32 out_) {
assembly {
out_ := or(and(not(shl(248, 0xFF)), _hash), shl(248, _status))
}
}

0 comments on commit ab6e51d

Please sign in to comment.