From 4c8940a6fbe2c0756912bb81ca18edb4a2e45a23 Mon Sep 17 00:00:00 2001 From: Web3 Philosopher Date: Mon, 24 Jun 2024 15:46:34 +0100 Subject: [PATCH] Add static host addresses (#20) --- .github/workflows/test.yml | 5 ---- .gitignore | 3 +- src/IIsmpModule.sol | 56 ++++++++++++++++++++++++++++++-------- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1a00b92..d9daa60 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,8 +43,3 @@ jobs: forge --version forge build --sizes id: build - - - name: Run Forge tests - run: | - forge test -vvv - id: test diff --git a/.gitignore b/.gitignore index cd27711..8be5b21 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ broadcast/ target/ .cargo/ -.idea \ No newline at end of file +.idea +.vscode/ \ No newline at end of file diff --git a/src/IIsmpModule.sol b/src/IIsmpModule.sol index c2761b0..e6eb5ce 100644 --- a/src/IIsmpModule.sol +++ b/src/IIsmpModule.sol @@ -64,27 +64,59 @@ interface IIsmpModule { /// Abstract contract to make implementing `IIsmpModule` easier. abstract contract BaseIsmpModule is IIsmpModule { - function onAccept(IncomingPostRequest calldata) external virtual { - revert("IsmpModule doesn't expect Post requests"); + // Chain is not supported + error UnsupportedChain(); + + // Call was not expected + error UnexpectedCall(); + + // Action is unauthorized + error UnauthorizedAction(); + + modifier onlyHost() { + if (msg.sender != host()) revert UnauthorizedAction(); + _; + } + + function host() internal view returns (address h) { + assembly { + switch chainid() + // Ethereum Sepolia + case 11155111 { h := 0xbDFa473d7E483e088348e071480B624A248b2fC4 } + // Arbitrum Sepolia + case 421614 { h := 0xC98976841a69Ce52d4D17B286A1698963E847982 } + // Optimism Sepolia + case 11155420 { h := 0x0D811D581D615AA44A36aa638825403F9b434E18 } + // Base Sepolia + case 84532 { h := 0x7FaBb96851517583eA7df7d6e9Dd28afc2fA38f5 } + // Binance Smart Chain Testnet + case 97 { h := 0xE6bd95737DD35Fd0e5f134771A832405671f06e9 } + } + + if (h == address(0)) revert UnsupportedChain(); + } + + function onAccept(IncomingPostRequest calldata) external virtual onlyHost { + revert UnexpectedCall(); } - function onPostRequestTimeout(PostRequest memory) external virtual { - revert("IsmpModule doesn't emit Post requests"); + function onPostRequestTimeout(PostRequest memory) external virtual onlyHost { + revert UnexpectedCall(); } - function onPostResponse(IncomingPostResponse memory) external virtual { - revert("IsmpModule doesn't emit Post responses"); + function onPostResponse(IncomingPostResponse memory) external virtual onlyHost { + revert UnexpectedCall(); } - function onPostResponseTimeout(PostResponse memory) external virtual { - revert("IsmpModule doesn't emit Post responses"); + function onPostResponseTimeout(PostResponse memory) external virtual onlyHost { + revert UnexpectedCall(); } - function onGetResponse(IncomingGetResponse memory) external virtual { - revert("IsmpModule doesn't emit Get requests"); + function onGetResponse(IncomingGetResponse memory) external virtual onlyHost { + revert UnexpectedCall(); } - function onGetTimeout(GetRequest memory) external virtual { - revert("IsmpModule doesn't emit Get requests"); + function onGetTimeout(GetRequest memory) external virtual onlyHost { + revert UnexpectedCall(); } }