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

feat(ctb): Remove limbo state for LPPs (#9355)

* Remove limbo state for LPPs

* Revert instead of set `challenged = true`
parent aca9ac45
This diff is collapsed.
This diff is collapsed.
......@@ -472,7 +472,12 @@ contract PreimageOracle is IPreimageOracle {
);
// If the proposal is being finalized, set the timestamp to the current block timestamp. This begins the
// challenge period, which must be waited out before the proposal can be finalized.
if (_finalize) metaData = metaData.setTimestamp(uint64(block.timestamp));
if (_finalize) {
metaData = metaData.setTimestamp(uint64(block.timestamp));
// If the number of bytes processed is not equal to the claimed size, the proposal cannot be finalized.
if (metaData.bytesProcessed() != metaData.claimedSize()) revert InvalidInputSize();
}
// Perist the latest branch to storage.
proposalBranches[msg.sender][_uuid] = branch;
......@@ -586,10 +591,6 @@ contract PreimageOracle is IPreimageOracle {
revert StatesNotContiguous();
}
// The claimed size must match the actual size of the preimage.
uint256 claimedSize = metaData.claimedSize();
if (metaData.bytesProcessed() != claimedSize) revert InvalidInputSize();
// Absorb and permute the input bytes. We perform no final verification on the state matrix here, since the
// proposal has passed the challenge period and is considered valid.
LibKeccak.absorb(_stateMatrix, _postState.input);
......@@ -603,7 +604,7 @@ contract PreimageOracle is IPreimageOracle {
uint256 partOffset = metaData.partOffset();
preimagePartOk[finalDigest][partOffset] = true;
preimageParts[finalDigest][partOffset] = proposalParts[_claimant][_uuid];
preimageLengths[finalDigest] = claimedSize;
preimageLengths[finalDigest] = metaData.claimedSize();
}
/// @notice Gets the current merkle root of the large preimage proposal tree.
......
......@@ -250,6 +250,26 @@ contract PreimageOracle_LargePreimageProposals_Test is Test {
console.log("Gas for 4MB: %d", (gasUsed / data.length) * 4000000);
}
/// @notice Tests that `addLeavesLPP` sets the proposal as countered when `_finalize = true` and the number of
/// bytes processed is less than the claimed size.
function test_addLeaves_mismatchedSize_succeeds() public {
// Allocate the preimage data.
bytes memory data = new bytes(136);
for (uint256 i; i < data.length; i++) {
data[i] = 0xFF;
}
// Initialize the proposal.
oracle.initLPP(TEST_UUID, 0, uint32(data.length + 1));
// Add the leaves to the tree (2 keccak blocks.)
LibKeccak.StateMatrix memory stateMatrix;
bytes32[] memory stateCommitments = _generateStateCommitments(stateMatrix, data);
vm.expectRevert(InvalidInputSize.selector);
oracle.addLeavesLPP(TEST_UUID, 0, data, stateCommitments, true);
}
/// @notice Tests that the `addLeavesLPP` function may never be called when `tx.origin != msg.sender`
function test_addLeaves_notEOA_reverts() public {
// Allocate the preimage data.
......@@ -631,51 +651,6 @@ contract PreimageOracle_LargePreimageProposals_Test is Test {
});
}
/// @notice Tests that the `squeeze` function reverts when the claimed size is not equal to the bytes processed.
function test_squeeze_invalidClaimedSize_reverts() public {
// Allocate the preimage data.
bytes memory data = new bytes(136);
for (uint256 i; i < data.length; i++) {
data[i] = 0xFF;
}
// Initialize the proposal.
oracle.initLPP(TEST_UUID, 0, uint32(data.length) - 1);
// Add the leaves to the tree (2 keccak blocks.)
LibKeccak.StateMatrix memory stateMatrix;
bytes32[] memory stateCommitments = _generateStateCommitments(stateMatrix, data);
oracle.addLeavesLPP(TEST_UUID, 0, data, stateCommitments, true);
// Construct the leaf preimage data for the blocks added.
LibKeccak.StateMatrix memory matrix;
PreimageOracle.Leaf[] memory leaves = _generateLeaves(matrix, data);
// Create a proof array with 16 elements.
bytes32[] memory preProof = new bytes32[](16);
preProof[0] = _hashLeaf(leaves[1]);
bytes32[] memory postProof = new bytes32[](16);
postProof[0] = _hashLeaf(leaves[0]);
for (uint256 i = 1; i < preProof.length; i++) {
bytes32 zeroHash = oracle.zeroHashes(i);
preProof[i] = zeroHash;
postProof[i] = zeroHash;
}
vm.warp(block.timestamp + oracle.challengePeriod() + 1 seconds);
vm.expectRevert(InvalidInputSize.selector);
oracle.squeezeLPP({
_claimant: address(this),
_uuid: TEST_UUID,
_stateMatrix: _stateMatrixAtBlockIndex(data, 1),
_preState: leaves[0],
_preStateProof: preProof,
_postState: leaves[1],
_postStateProof: postProof
});
}
/// @notice Tests that squeezing a large preimage proposal after the challenge period has passed always succeeds and
/// persists the correct data.
function testFuzz_squeeze_succeeds(uint256 _numBlocks, uint32 _partOffset) public {
......
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