Skip to content
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

fix(protocol): need to fix a bug in LibTrieProof (or its test) #15739

Merged
merged 7 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/protocol/contracts/libs/LibTrieProof.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ 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.
*
* @param stateRoot 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.
adaki2004 marked this conversation as resolved.
Show resolved Hide resolved
* @param mkproof The proof obtained by encoding storage proof.
* @return verified The verification result.
*/
function verifyFullMerkleProof(
bytes32 stateRoot,
address addr,
bytes32 slot,
bytes32 value,
Brechtpd marked this conversation as resolved.
Show resolved Hide resolved
bytes memory mkproof
)
internal
Expand All @@ -54,7 +53,9 @@ library LibTrieProof {
RLPReader.readBytes(accountState[ACCOUNT_FIELD_INDEX_STORAGE_HASH]);

verified = SecureMerkleTrie.verifyInclusionProof(
bytes.concat(slot), bytes.concat(value), storageProof, bytes32(storageRoot)
bytes.concat(slot), hex"01", 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, merkleProof);
}

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

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

vm.startPrank(Alice);
LibTrieProof.verifyFullMerkleProof(
worldStateRoot,
contractWhichStoresValue1AtSlot,
slotStoredAtTheApp,
hex"01",
merkleProof
bool verified = LibTrieProof.verifyFullMerkleProof(
worldStateRoot, contractWhichStoresValue1AtSlot, slotStoredAtTheApp, merkleProof
);

assertEq(verified, true);
}
}
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
Loading