-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(protocol)!: cache cross-chain data in the signal service as signals #15736
Changes from all commits
a3c14b4
08038bd
163abdb
9af711b
80cdc1f
9c4dfd3
e9cdfb6
fe4eda7
216b565
8c54e20
4380fbe
6c9da20
7806d77
7517d7d
19b16a6
7640159
f85cc11
c462319
1668e49
40ddb74
731df4f
4d33026
a600f92
c4326cf
244de26
f4ec267
37b9480
62b6f3d
c4ca6cb
5dc4d49
550ba67
b34cf02
c0de501
08610b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,54 +8,60 @@ pragma solidity ^0.8.24; | |||||
|
||||||
import { RLPReader } from "../thirdparty/optimism/rlp/RLPReader.sol"; | ||||||
import { SecureMerkleTrie } from "../thirdparty/optimism/trie/SecureMerkleTrie.sol"; | ||||||
|
||||||
import "forge-std/console2.sol"; | ||||||
/** | ||||||
* @title LibTrieProof | ||||||
*/ | ||||||
|
||||||
library LibTrieProof { | ||||||
// The consensus format representing account is RLP encoded in the | ||||||
// following order: nonce, balance, storageHash, codeHash. | ||||||
uint256 private constant ACCOUNT_FIELD_INDEX_STORAGE_HASH = 2; | ||||||
|
||||||
error LTP_INVALID_ACCOUNT_PROOF(); | ||||||
error LTP_INVALID_INCLUSION_PROOF(); | ||||||
error LTP_INVALID_STORAGE_PROOF(); | ||||||
|
||||||
/** | ||||||
* Verifies that the value of a slot in the storage of an account is value. | ||||||
* | ||||||
* @param stateRoot The merkle root of state tree. | ||||||
* @param rootHash The merkle root of state tree. | ||||||
* @param addr The address of contract. | ||||||
* @param slot The slot in the contract. | ||||||
* @param value The value to be verified. | ||||||
* @param mkproof The proof obtained by encoding storage proof. | ||||||
* @param accountProof The account proof. | ||||||
* @param storageProof The storage proof. | ||||||
* @return storageRoot The storage root. | ||||||
*/ | ||||||
function verifyFullMerkleProof( | ||||||
bytes32 stateRoot, | ||||||
function verifyMerkleProof( | ||||||
bytes32 rootHash, | ||||||
address addr, | ||||||
bytes32 slot, | ||||||
bytes memory value, | ||||||
bytes memory mkproof | ||||||
bytes[] memory accountProof, | ||||||
bytes[] memory storageProof | ||||||
) | ||||||
internal | ||||||
pure | ||||||
returns (bytes32 storageRoot) | ||||||
{ | ||||||
(bytes[] memory accountProof, bytes[] memory storageProof) = | ||||||
abi.decode(mkproof, (bytes[], bytes[])); | ||||||
|
||||||
bytes memory rlpAccount = | ||||||
SecureMerkleTrie.get(abi.encodePacked(addr), accountProof, stateRoot); | ||||||
if (accountProof.length == 0) { | ||||||
storageRoot = rootHash; | ||||||
} else { | ||||||
bytes memory rlpAccount = | ||||||
SecureMerkleTrie.get(abi.encodePacked(addr), accountProof, rootHash); | ||||||
|
||||||
if (rlpAccount.length == 0) revert LTP_INVALID_ACCOUNT_PROOF(); | ||||||
if (rlpAccount.length == 0) revert LTP_INVALID_ACCOUNT_PROOF(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
With For the storage value the maximum length is 33 so we can also add a check on that in the input. |
||||||
|
||||||
RLPReader.RLPItem[] memory accountState = RLPReader.readList(rlpAccount); | ||||||
RLPReader.RLPItem[] memory accountState = RLPReader.readList(rlpAccount); | ||||||
|
||||||
bytes memory storageRoot = | ||||||
RLPReader.readBytes(accountState[ACCOUNT_FIELD_INDEX_STORAGE_HASH]); | ||||||
storageRoot = | ||||||
bytes32(RLPReader.readBytes(accountState[ACCOUNT_FIELD_INDEX_STORAGE_HASH])); | ||||||
} | ||||||
|
||||||
bool verified = SecureMerkleTrie.verifyInclusionProof( | ||||||
bytes.concat(slot), value, storageProof, bytes32(storageRoot) | ||||||
); | ||||||
|
||||||
if (!verified) revert LTP_INVALID_INCLUSION_PROOF(); | ||||||
if (!verified) revert LTP_INVALID_STORAGE_PROOF(); | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does now make it impossible for smart contracts on L2 to just fetch this data from a smart contract or fetch specific L1 state roots. The block number and block hash info is now lost and unavailable, only now possible to verify that some L1 state root existed, not which and also not the corresponding block hash.
The applications that can make use of this info is low (thinking of things like axiom for historical data or some other alternative bridging solution), so probably not a big deal, still it felt good to have it there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also realized the differences. I think it's fine as most apps shall not assuming these data are available otherwise, the app will not be deployable on other chains.
But I do think it may be benefit to add the latest cached data and its block number to TaikoL1/L2 contract, and the cost is very small (writing to the same slot).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed hard to predict how useful it will be.
But it all depends on what other L2s also make available, because the function to call to get the data will be different, but the dapp could depend on the data to be there easily by just pointing to the right contract for each chain. I haven't look too closely to what is available on optimism, but there at least the full block header of the last known L1 block is made available in a contract: https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/L1Block.sol. That means that dapps that depend on this information can run on Optimism but would not be able to run on Taiko.