From d8ae47643c41ab9e74c42b5688dcf88965a15d09 Mon Sep 17 00:00:00 2001 From: 0age <37939117+0age@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:06:03 -0800 Subject: [PATCH] integrate Hyperlane with Tribunal --- lib/tribunal | 2 +- src/HyperlaneTribunal.sol | 94 ++++++++++++++++++--------------------- 2 files changed, 44 insertions(+), 52 deletions(-) diff --git a/lib/tribunal b/lib/tribunal index a8be328..0b6317c 160000 --- a/lib/tribunal +++ b/lib/tribunal @@ -1 +1 @@ -Subproject commit a8be32896064521ac6edc77cc9b0c8ba9fa08033 +Subproject commit 0b6317c423a9ad68ef671fa157da6229fc86b84d diff --git a/src/HyperlaneTribunal.sol b/src/HyperlaneTribunal.sol index 10e49fe..a8fa62e 100644 --- a/src/HyperlaneTribunal.sol +++ b/src/HyperlaneTribunal.sol @@ -1,37 +1,25 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.27; -import {TheCompact} from "the-compact/src/TheCompact.sol"; +import {ITheCompactClaims} from "the-compact/src/interfaces/ITheCompactClaims.sol"; import {ClaimWithWitness} from "the-compact/src/types/Claims.sol"; import {Compact} from "the-compact/src/types/EIP712Types.sol"; import {Tribunal} from "tribunal/Tribunal.sol"; -import {Address} from "@openzeppelin/contracts/utils/Address.sol"; -import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol"; import {Router} from "hyperlane/contracts/client/Router.sol"; -struct Intent { - uint256 fee; - uint32 chainId; - address token; - address recipient; - uint256 amount; -} - -string constant TYPESTRING = "Intent(uint256 fee,uint32 chainId,address token,address recipient,uint256 amount)"; -bytes32 constant TYPEHASH = keccak256(bytes(TYPESTRING)); - string constant WITNESS_TYPESTRING = - "Intent intent)Intent(uint256 fee,uint32 chainId,address token,address recipient,uint256 amount)"; + "Mandate mandate)Mandate(uint256 chainId,address tribunal,address recipient,uint256 expires,address token,uint256 minimumAmount,uint256 baselinePriorityFee,uint256 scalingFactor,bytes32 salt)"; library Message { - function encode( - Tribunal.Compact calldata compact, - bytes32 mandateHash, - uint256 claimedAmount, - address claimant - ) internal pure returns (bytes memory) { - require(compact.allocatorSignature.length == 64 && compact.sponsorSignature.length == 64, "invalid signature length"); + function encode(Tribunal.Compact calldata compact, bytes32 mandateHash, uint256 claimedAmount, address claimant) + internal + pure + returns (bytes memory) + { + require( + compact.allocatorSignature.length == 64 && compact.sponsorSignature.length == 64, "invalid signature length" + ); return abi.encodePacked( compact.arbiter, @@ -50,10 +38,13 @@ library Message { function decode(bytes calldata message) internal - pure + view returns ( - // TODO: calldata - Compact memory compact, + address sponsor, + uint256 nonce, + uint256 expires, + uint256 id, + uint256 allocatedAmount, bytes calldata allocatorSignature, bytes calldata sponsorSignature, bytes32 witness, @@ -61,15 +52,15 @@ library Message { address claimant ) { - assert(message.length == 380); - compact = Compact({ - arbiter: address(bytes20(message[0:20])), - sponsor: address(bytes20(message[20:40])), - nonce: uint256(bytes32(message[40:72])), - expires: uint256(bytes32(message[72:104])), - id: uint256(bytes32(message[104:136])), - amount: uint256(bytes32(message[136:168])) - }); + require(message.length == 380, "invalid message length"); + address arbiter = address(bytes20(message[0:20])); + require(arbiter == address(this), "invalid arbiter"); + + sponsor = address(bytes20(message[20:40])); + nonce = uint256(bytes32(message[40:72])); + expires = uint256(bytes32(message[72:104])); + id = uint256(bytes32(message[104:136])); + allocatedAmount = uint256(bytes32(message[136:168])); allocatorSignature = message[168:232]; sponsorSignature = message[232:296]; witness = bytes32(message[296:328]); @@ -81,10 +72,10 @@ library Message { contract HyperlaneTribunal is Router, Tribunal { using Message for bytes; - TheCompact public immutable theCompact; + ITheCompactClaims public immutable theCompact; constructor(address _mailbox, address _theCompact) Router(_mailbox) { - theCompact = TheCompact(_theCompact); + theCompact = ITheCompactClaims(_theCompact); } /** @@ -95,13 +86,13 @@ contract HyperlaneTribunal is Router, Tribunal { * @param claimAmount The amount to claim */ function _processDirective( - Tribunal.Compact memory compact, + Tribunal.Compact calldata compact, bytes32 mandateHash, Directive memory directive, uint256 claimAmount ) internal virtual override { _Router_dispatch( - compact.chainId, + uint32(compact.chainId), directive.dispensation, Message.encode(compact, mandateHash, claimAmount, directive.claimant), "", @@ -119,16 +110,13 @@ contract HyperlaneTribunal is Router, Tribunal { * @return dispensation The quoted dispensation amount */ function _quoteDirective( - Tribunal.Compact memory compact, + Tribunal.Compact calldata compact, bytes32 mandateHash, address claimant, uint256 claimAmount ) internal view virtual override returns (uint256 dispensation) { return _Router_quoteDispatch( - compact.chainId, - Message.encode(compact, mandateHash, claimAmount, claimant), - "", - address(hook) + uint32(compact.chainId), Message.encode(compact, mandateHash, claimAmount, claimant), "", address(hook) ); } @@ -140,9 +128,13 @@ contract HyperlaneTribunal is Router, Tribunal { bytes calldata message ) internal override { ( - Compact memory compact, - bytes memory allocatorSignature, - bytes memory sponsorSignature, + address sponsor, + uint256 nonce, + uint256 expires, + uint256 id, + uint256 allocatedAmount, + bytes calldata allocatorSignature, + bytes calldata sponsorSignature, bytes32 witness, uint256 claimedAmount, address claimant @@ -153,11 +145,11 @@ contract HyperlaneTribunal is Router, Tribunal { witness: witness, allocatorSignature: allocatorSignature, sponsorSignature: sponsorSignature, - sponsor: compact.sponsor, - nonce: compact.nonce, - expires: compact.expires, - id: compact.id, - allocatedAmount: compact.amount, + sponsor: sponsor, + nonce: nonce, + expires: expires, + id: id, + allocatedAmount: allocatedAmount, amount: claimedAmount, claimant: claimant });