-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protocol): implement
Bridge.isMessageFailed
(#13004)
Co-authored-by: Roger <[email protected]> Co-authored-by: jeff <[email protected]>
- Loading branch information
1 parent
609e96f
commit 45153d9
Showing
9 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,17 @@ | |
|
||
pragma solidity ^0.8.9; | ||
|
||
import "../../common/IHeaderSync.sol"; | ||
import "../../libs/LibBlockHeader.sol"; | ||
import "../../libs/LibTrieProof.sol"; | ||
import "./LibBridgeData.sol"; | ||
|
||
/** | ||
* @author dantaik <[email protected]> | ||
*/ | ||
library LibBridgeStatus { | ||
using LibBlockHeader for BlockHeader; | ||
|
||
enum MessageStatus { | ||
NEW, | ||
RETRIABLE, | ||
|
@@ -52,6 +59,39 @@ library LibBridgeStatus { | |
return keccak256(abi.encodePacked("MESSAGE_STATUS", msgHash)); | ||
} | ||
|
||
function isMessageFailed( | ||
AddressResolver resolver, | ||
bytes32 msgHash, | ||
uint256 destChainId, | ||
bytes calldata proof | ||
) internal view returns (bool) { | ||
require(destChainId != block.chainid, "B:destChainId"); | ||
require(msgHash != 0, "B:msgHash"); | ||
|
||
LibBridgeData.StatusProof memory sp = abi.decode( | ||
proof, | ||
(LibBridgeData.StatusProof) | ||
); | ||
bytes32 syncedHeaderHash = IHeaderSync(resolver.resolve("taiko", false)) | ||
.getSyncedHeader(sp.header.height); | ||
|
||
if ( | ||
syncedHeaderHash == 0 || | ||
syncedHeaderHash != sp.header.hashBlockHeader() | ||
) { | ||
return false; | ||
} | ||
|
||
return | ||
LibTrieProof.verify({ | ||
stateRoot: sp.header.stateRoot, | ||
addr: resolver.resolve(destChainId, "bridge", false), | ||
slot: getMessageStatusSlot(msgHash), | ||
value: bytes32(uint256(LibBridgeStatus.MessageStatus.FAILED)), | ||
mkproof: sp.proof | ||
}); | ||
} | ||
|
||
function _setMessageStatus(bytes32 msgHash, MessageStatus status) private { | ||
bytes32 slot = getMessageStatusSlot(msgHash); | ||
uint256 value = uint256(status); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters