Commit ab6e51d0 authored by clabby's avatar clabby Committed by GitHub

Add status byte to final digest (#9310)

parent 0872e3ed
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -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();
......
......@@ -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);
......@@ -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)
......@@ -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))
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment