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

feat(ctb): Optimistic large preimages (#8947)

* init keccak proposals

* merklelization

* merk fixes

* Preimage parts, challenge tests

* Tests

* bindings + snapshots

* lint

* tests

* bind

* :broom:, checks, tests

* Contiguous state tests

* :broom:, r4r

* review

* rabbit

* @refcell review

* bindings

* bindings

* @tynes review

* @inphi review
parent 58c9b324
...@@ -20,3 +20,6 @@ ...@@ -20,3 +20,6 @@
[submodule "packages/contracts-bedrock/lib/solady"] [submodule "packages/contracts-bedrock/lib/solady"]
path = packages/contracts-bedrock/lib/solady path = packages/contracts-bedrock/lib/solady
url = https://github.com/Vectorized/solady url = https://github.com/Vectorized/solady
[submodule "packages/contracts-bedrock/lib/lib-keccak"]
path = packages/contracts-bedrock/lib/lib-keccak
url = https://github.com/ethereum-optimism/lib-keccak
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -13,7 +13,7 @@ const WETH9StorageLayoutJSON = "{\"storage\":[{\"astId\":1000,\"contract\":\"src ...@@ -13,7 +13,7 @@ const WETH9StorageLayoutJSON = "{\"storage\":[{\"astId\":1000,\"contract\":\"src
var WETH9StorageLayout = new(solc.StorageLayout) var WETH9StorageLayout = new(solc.StorageLayout)
var WETH9DeployedBin = "0x6080604052600436106100bc5760003560e01c8063313ce56711610074578063a9059cbb1161004e578063a9059cbb146102cb578063d0e30db0146100bc578063dd62ed3e14610311576100bc565b8063313ce5671461024b57806370a082311461027657806395d89b41146102b6576100bc565b806318160ddd116100a557806318160ddd146101aa57806323b872dd146101d15780632e1a7d4d14610221576100bc565b806306fdde03146100c6578063095ea7b314610150575b6100c4610359565b005b3480156100d257600080fd5b506100db6103a8565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101155781810151838201526020016100fd565b50505050905090810190601f1680156101425780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015c57600080fd5b506101966004803603604081101561017357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610454565b604080519115158252519081900360200190f35b3480156101b657600080fd5b506101bf6104c7565b60408051918252519081900360200190f35b3480156101dd57600080fd5b50610196600480360360608110156101f457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013590911690604001356104cb565b34801561022d57600080fd5b506100c46004803603602081101561024457600080fd5b503561066b565b34801561025757600080fd5b50610260610700565b6040805160ff9092168252519081900360200190f35b34801561028257600080fd5b506101bf6004803603602081101561029957600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610709565b3480156102c257600080fd5b506100db61071b565b3480156102d757600080fd5b50610196600480360360408110156102ee57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610793565b34801561031d57600080fd5b506101bf6004803603604081101561033457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160200135166107a7565b33600081815260036020908152604091829020805434908101909155825190815291517fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c9281900390910190a2565b6000805460408051602060026001851615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f8101849004840282018401909252818152929183018282801561044c5780601f106104215761010080835404028352916020019161044c565b820191906000526020600020905b81548152906001019060200180831161042f57829003601f168201915b505050505081565b33600081815260046020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b4790565b73ffffffffffffffffffffffffffffffffffffffff83166000908152600360205260408120548211156104fd57600080fd5b73ffffffffffffffffffffffffffffffffffffffff84163314801590610573575073ffffffffffffffffffffffffffffffffffffffff841660009081526004602090815260408083203384529091529020547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14155b156105ed5773ffffffffffffffffffffffffffffffffffffffff841660009081526004602090815260408083203384529091529020548211156105b557600080fd5b73ffffffffffffffffffffffffffffffffffffffff841660009081526004602090815260408083203384529091529020805483900390555b73ffffffffffffffffffffffffffffffffffffffff808516600081815260036020908152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b3360009081526003602052604090205481111561068757600080fd5b33600081815260036020526040808220805485900390555183156108fc0291849190818181858888f193505050501580156106c6573d6000803e3d6000fd5b5060408051828152905133917f7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65919081900360200190a250565b60025460ff1681565b60036020526000908152604090205481565b60018054604080516020600284861615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f8101849004840282018401909252818152929183018282801561044c5780601f106104215761010080835404028352916020019161044c565b60006107a03384846104cb565b9392505050565b60046020908152600092835260408084209091529082529020548156fea265627a7a72315820815b4d576ed6382f69c32a261321b184a7fbc2b81b87c3a52e66efdb3ee9602164736f6c63430005110032" var WETH9DeployedBin = "0x6080604052600436106100bc5760003560e01c8063313ce56711610074578063a9059cbb1161004e578063a9059cbb146102cb578063d0e30db0146100bc578063dd62ed3e14610311576100bc565b8063313ce5671461024b57806370a082311461027657806395d89b41146102b6576100bc565b806318160ddd116100a557806318160ddd146101aa57806323b872dd146101d15780632e1a7d4d14610221576100bc565b806306fdde03146100c6578063095ea7b314610150575b6100c4610359565b005b3480156100d257600080fd5b506100db6103a8565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101155781810151838201526020016100fd565b50505050905090810190601f1680156101425780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561015c57600080fd5b506101966004803603604081101561017357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610454565b604080519115158252519081900360200190f35b3480156101b657600080fd5b506101bf6104c7565b60408051918252519081900360200190f35b3480156101dd57600080fd5b50610196600480360360608110156101f457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013590911690604001356104cb565b34801561022d57600080fd5b506100c46004803603602081101561024457600080fd5b503561066b565b34801561025757600080fd5b50610260610700565b6040805160ff9092168252519081900360200190f35b34801561028257600080fd5b506101bf6004803603602081101561029957600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16610709565b3480156102c257600080fd5b506100db61071b565b3480156102d757600080fd5b50610196600480360360408110156102ee57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610793565b34801561031d57600080fd5b506101bf6004803603604081101561033457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160200135166107a7565b33600081815260036020908152604091829020805434908101909155825190815291517fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c9281900390910190a2565b6000805460408051602060026001851615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f8101849004840282018401909252818152929183018282801561044c5780601f106104215761010080835404028352916020019161044c565b820191906000526020600020905b81548152906001019060200180831161042f57829003601f168201915b505050505081565b33600081815260046020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716808552908352818420869055815186815291519394909390927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925928290030190a350600192915050565b4790565b73ffffffffffffffffffffffffffffffffffffffff83166000908152600360205260408120548211156104fd57600080fd5b73ffffffffffffffffffffffffffffffffffffffff84163314801590610573575073ffffffffffffffffffffffffffffffffffffffff841660009081526004602090815260408083203384529091529020547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14155b156105ed5773ffffffffffffffffffffffffffffffffffffffff841660009081526004602090815260408083203384529091529020548211156105b557600080fd5b73ffffffffffffffffffffffffffffffffffffffff841660009081526004602090815260408083203384529091529020805483900390555b73ffffffffffffffffffffffffffffffffffffffff808516600081815260036020908152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060019392505050565b3360009081526003602052604090205481111561068757600080fd5b33600081815260036020526040808220805485900390555183156108fc0291849190818181858888f193505050501580156106c6573d6000803e3d6000fd5b5060408051828152905133917f7fcf532c15f0a6db0bd6d0e038bea71d30d808c7d98cb3bf7268a95bf5081b65919081900360200190a250565b60025460ff1681565b60036020526000908152604090205481565b60018054604080516020600284861615610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190941693909304601f8101849004840282018401909252818152929183018282801561044c5780601f106104215761010080835404028352916020019161044c565b60006107a03384846104cb565b9392505050565b60046020908152600092835260408084209091529082529020548156fea265627a7a723158201668ab2847c86647a20370de3c85906542e9da3d84f500326fc63321f2774e9264736f6c63430005110032"
func init() { func init() {
......
...@@ -15,6 +15,7 @@ remappings = [ ...@@ -15,6 +15,7 @@ remappings = [
'@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts', '@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts',
'@rari-capital/solmate/=lib/solmate', '@rari-capital/solmate/=lib/solmate',
'@cwia/=lib/clones-with-immutable-args/src', '@cwia/=lib/clones-with-immutable-args/src',
'@lib-keccak/=lib/lib-keccak/contracts/lib',
'forge-std/=lib/forge-std/src', 'forge-std/=lib/forge-std/src',
'ds-test/=lib/forge-std/lib/ds-test/src', 'ds-test/=lib/forge-std/lib/ds-test/src',
'safe-contracts/=lib/safe-contracts/contracts', 'safe-contracts/=lib/safe-contracts/contracts',
......
Subproject commit 59dcbd7b0de1fd00b44f4ce41e99a7f990564d11
...@@ -1091,6 +1091,18 @@ ...@@ -1091,6 +1091,18 @@
"length": 22, "length": 22,
"filename_relative": "src/dispute/FaultDisputeGame.sol" "filename_relative": "src/dispute/FaultDisputeGame.sol"
}, },
{
"id": "037c6a008887de2859c40f66cb99806d2e25ea8d4b0658d3fdc448e77c20439b",
"impact": "Medium",
"confidence": "Medium",
"check": "uninitialized-local",
"description": "PreimageOracle.challengeFirstLPP(address,uint256,PreimageOracle.Leaf,bytes32[]).stateMatrix (src/cannon/PreimageOracle.sol#357) is a local variable never initialized\n",
"type": "variable",
"name": "stateMatrix",
"start": 16305,
"length": 40,
"filename_relative": "src/cannon/PreimageOracle.sol"
},
{ {
"id": "8c229f5475784b2e9526e30d55b066e479489bca4b07c4f062b42b5b70100794", "id": "8c229f5475784b2e9526e30d55b066e479489bca4b07c4f062b42b5b70100794",
"impact": "Medium", "impact": "Medium",
......
...@@ -19,5 +19,33 @@ ...@@ -19,5 +19,33 @@
"offset": 0, "offset": 0,
"slot": "2", "slot": "2",
"type": "mapping(bytes32 => mapping(uint256 => bool))" "type": "mapping(bytes32 => mapping(uint256 => bool))"
},
{
"bytes": "512",
"label": "zeroHashes",
"offset": 0,
"slot": "3",
"type": "bytes32[16]"
},
{
"bytes": "32",
"label": "proposalBranches",
"offset": 0,
"slot": "19",
"type": "mapping(address => mapping(uint256 => bytes32[16]))"
},
{
"bytes": "32",
"label": "proposalMetadata",
"offset": 0,
"slot": "20",
"type": "mapping(address => mapping(uint256 => LPPMetaData))"
},
{
"bytes": "32",
"label": "proposalParts",
"offset": 0,
"slot": "21",
"type": "mapping(address => mapping(uint256 => bytes32))"
} }
] ]
\ No newline at end of file
...@@ -3,3 +3,33 @@ pragma solidity 0.8.15; ...@@ -3,3 +3,33 @@ pragma solidity 0.8.15;
/// @notice Thrown when a passed part offset is out of bounds. /// @notice Thrown when a passed part offset is out of bounds.
error PartOffsetOOB(); error PartOffsetOOB();
/// @notice Thrown when a merkle proof fails to verify.
error InvalidProof();
/// @notice Thrown when the prestate preimage doesn't match the claimed preimage.
error InvalidPreimage();
/// @notice Thrown when a leaf with an invalid input size is added.
error InvalidInputSize();
/// @notice Thrown when the pre and post states passed aren't contiguous.
error StatesNotContiguous();
/// @notice Thrown when the permutation yields the expected result.
error PostStateMatches();
/// @notice Thrown when the preimage is too large to fit in the tree.
error TreeSizeOverflow();
/// @notice Thrown when the preimage proposal has already been finalized.
error AlreadyFinalized();
/// @notice Thrown when the proposal has not matured past the challenge period.
error ActiveProposal();
/// @notice Thrown when attempting to finalize a proposal that has been challenged.
error BadProposal();
/// @notice Thrown when attempting to add leaves to a preimage proposal that has not been initialized.
error NotInitialized();
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
using LPPMetadataLib for LPPMetaData global;
/// @notice Packed LPP metadata.
/// ┌─────────────┬────────────────────────────────────────────┐
/// │ Bit Offsets │ Description │
/// ├─────────────┼────────────────────────────────────────────┤
/// │ [0, 64) │ Timestamp (Finalized - All data available) │
/// │ [64, 96) │ Part Offset │
/// │ [96, 128) │ Claimed Size │
/// │ [128, 160) │ Blocks Processed (Inclusive of Padding) │
/// │ [160, 192) │ Bytes Processed (Non-inclusive of Padding) │
/// │ [192, 256) │ Countered │
/// └─────────────┴────────────────────────────────────────────┘
type LPPMetaData is bytes32;
/// @notice LPP metadata UDT extension functions.
library LPPMetadataLib {
uint256 private constant U64_MASK = 0xFFFFFFFFFFFFFFFF;
uint256 private constant U32_MASK = 0xFFFFFFFF;
function setTimestamp(LPPMetaData _self, uint64 _timestamp) internal pure returns (LPPMetaData self_) {
assembly {
self_ := or(shl(192, _timestamp), and(_self, not(shl(192, U64_MASK))))
}
}
function setPartOffset(LPPMetaData _self, uint32 _partOffset) internal pure returns (LPPMetaData self_) {
assembly {
self_ := or(shl(160, _partOffset), and(_self, not(shl(160, U32_MASK))))
}
}
function setClaimedSize(LPPMetaData _self, uint32 _claimedSize) internal pure returns (LPPMetaData self_) {
assembly {
self_ := or(shl(128, _claimedSize), and(_self, not(shl(128, U32_MASK))))
}
}
function setBlocksProcessed(LPPMetaData _self, uint32 _blocksProcessed) internal pure returns (LPPMetaData self_) {
assembly {
self_ := or(shl(96, _blocksProcessed), and(_self, not(shl(96, U32_MASK))))
}
}
function setBytesProcessed(LPPMetaData _self, uint32 _bytesProcessed) internal pure returns (LPPMetaData self_) {
assembly {
self_ := or(shl(64, _bytesProcessed), and(_self, not(shl(64, U32_MASK))))
}
}
function setCountered(LPPMetaData _self, bool _countered) internal pure returns (LPPMetaData self_) {
assembly {
self_ := or(_countered, and(_self, not(U64_MASK)))
}
}
function timestamp(LPPMetaData _self) internal pure returns (uint64 timestamp_) {
assembly {
timestamp_ := shr(192, _self)
}
}
function partOffset(LPPMetaData _self) internal pure returns (uint64 partOffset_) {
assembly {
partOffset_ := and(shr(160, _self), U32_MASK)
}
}
function claimedSize(LPPMetaData _self) internal pure returns (uint32 claimedSize_) {
assembly {
claimedSize_ := and(shr(128, _self), U32_MASK)
}
}
function blocksProcessed(LPPMetaData _self) internal pure returns (uint32 blocksProcessed_) {
assembly {
blocksProcessed_ := and(shr(96, _self), U32_MASK)
}
}
function bytesProcessed(LPPMetaData _self) internal pure returns (uint32 bytesProcessed_) {
assembly {
bytesProcessed_ := and(shr(64, _self), U32_MASK)
}
}
function countered(LPPMetaData _self) internal pure returns (bool countered_) {
assembly {
countered_ := and(_self, U64_MASK)
}
}
}
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