Skip to content

Commit

Permalink
fix(protocol): need to fix a bug in LibTrieProof (or its test) (#15739)
Browse files Browse the repository at this point in the history
Co-authored-by: Keszey Dániel <keszeyd@MacBook-Pro.local>
  • Loading branch information
dantaik and Keszey Dániel committed Feb 11, 2024
1 parent e2f4bc2 commit ac1ca31
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
11 changes: 6 additions & 5 deletions packages/protocol/contracts/libs/LibTrieProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ library LibTrieProof {
uint256 private constant ACCOUNT_FIELD_INDEX_STORAGE_HASH = 2;

error LTP_INVALID_ACCOUNT_PROOF();
error LTP_INVALID_INCLUSION_PROOF();

/**
* Verifies that the value of a slot in the storage of an account is value.
Expand All @@ -27,18 +28,16 @@ library LibTrieProof {
* @param slot The slot in the contract.
* @param value The value to be verified.
* @param mkproof The proof obtained by encoding storage proof.
* @return verified The verification result.
*/
function verifyFullMerkleProof(
bytes32 stateRoot,
address addr,
bytes32 slot,
bytes32 value,
bytes memory value,
bytes memory mkproof
)
internal
pure
returns (bool verified)
{
(bytes[] memory accountProof, bytes[] memory storageProof) =
abi.decode(mkproof, (bytes[], bytes[]));
Expand All @@ -53,8 +52,10 @@ library LibTrieProof {
bytes memory storageRoot =
RLPReader.readBytes(accountState[ACCOUNT_FIELD_INDEX_STORAGE_HASH]);

verified = SecureMerkleTrie.verifyInclusionProof(
bytes.concat(slot), bytes.concat(value), storageProof, bytes32(storageRoot)
bool verified = SecureMerkleTrie.verifyInclusionProof(
bytes.concat(slot), value, storageProof, bytes32(storageRoot)
);

if (!verified) revert LTP_INVALID_INCLUSION_PROOF();
}
}
5 changes: 2 additions & 3 deletions packages/protocol/contracts/signal/SignalService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,9 @@ contract SignalService is EssentialContract, ISignalService {
address signalService = resolve(srcChainId, "signal_service", false);

bytes32 slot = getSignalSlot(srcChainId, srcApp, srcSignal);
bool verified =
LibTrieProof.verifyFullMerkleProof(stateRoot, signalService, slot, hex"01", merkleProof);

if (!verified) revert SS_INVALID_PROOF();
// verifyFullMerkleProof() will revert in case if something is not valid
LibTrieProof.verifyFullMerkleProof(stateRoot, signalService, slot, hex"01", merkleProof);
}

/// @notice Checks if multi-hop is enabled.
Expand Down
5 changes: 2 additions & 3 deletions packages/protocol/test/libs/LibTrieProof.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity 0.8.24;
import "../TaikoTest.sol";
import "../../contracts/libs/LibTrieProof.sol";

contract TestVerifyFullMerkleProof is TaikoTest {
function test_verifyFullMerkleProof() public {
contract TestLibTrieProof is TaikoTest {
function test_verifyFullMerkleProof() public pure {
// Not needed for now, but leave it as is.
//uint64 chainId = 11_155_111; // Created the proofs on a deployed Sepolia
// contract, this is why this chainId.
Expand Down Expand Up @@ -51,7 +51,6 @@ contract TestVerifyFullMerkleProof is TaikoTest {
hex"e3a1209749684f52b5c0717a7ca78127fb56043d637d81763c04e9d30ba4d4746d56e901";
bytes memory merkleProof = abi.encode(accountProof, storageProof);

vm.startPrank(Alice);
LibTrieProof.verifyFullMerkleProof(
worldStateRoot,
contractWhichStoresValue1AtSlot,
Expand Down
12 changes: 7 additions & 5 deletions packages/protocol/test/team/airdrop/ERC20Airdrop.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ contract TestERC20Airdrop is TaikoTest {
claimEnd = uint64(block.timestamp + 10_000);
merkleProof = new bytes32[](3);

token = TaikoToken( deployProxy({
name: "taiko_token",
impl: address(new TaikoToken()),
data: abi.encodeCall(TaikoToken.init, ("Taiko Token", "TKO", owner)) }));

token = TaikoToken(
deployProxy({
name: "taiko_token",
impl: address(new TaikoToken()),
data: abi.encodeCall(TaikoToken.init, ("Taiko Token", "TKO", owner))
})
);

airdrop = ERC20Airdrop(
deployProxy({
Expand Down

0 comments on commit ac1ca31

Please sign in to comment.