-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into alexander/on-recv
- Loading branch information
Showing
25 changed files
with
2,205 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: test | ||
|
||
on: workflow_dispatch | ||
on: [push, fork] | ||
|
||
env: | ||
FOUNDRY_PROFILE: ci | ||
|
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.13; | ||
|
||
import { IncentivizedMessageEscrow } from "../../IncentivizedMessageEscrow.sol"; | ||
|
||
import { SmallStructs } from "./external/callworm/SmallStructs.sol"; | ||
import { WormholeVerifier } from "./external/callworm/WormholeVerifier.sol"; | ||
import { IWormhole } from "./interfaces/IWormhole.sol"; | ||
|
||
// This is a mock contract which should only be used for testing. | ||
contract IncentivizedWormholeEscrow is IncentivizedMessageEscrow, WormholeVerifier { | ||
error BadChainIdentifier(); | ||
|
||
event WormholeMessage( | ||
bytes32 destinationIdentifier, | ||
bytes recipitent | ||
); | ||
|
||
IWormhole public immutable WORMHOLE; | ||
|
||
constructor(address wormhole_) WormholeVerifier(wormhole_) { | ||
WORMHOLE = IWormhole(wormhole_); | ||
} | ||
|
||
function estimateAdditionalCost() external view returns(address asset, uint256 amount) { | ||
asset = address(0); | ||
amount = WORMHOLE.messageFee(); | ||
} | ||
|
||
function _getMessageIdentifier( | ||
bytes32 destinationIdentifier, | ||
bytes calldata message | ||
) internal override view returns(bytes32) { | ||
return keccak256( | ||
abi.encodePacked( | ||
bytes32(block.number), | ||
chainId(), | ||
destinationIdentifier, | ||
message | ||
) | ||
); | ||
} | ||
|
||
function _verifyMessage(bytes calldata _metadata, bytes calldata _message) internal view override returns(bytes32 sourceIdentifier, bytes memory implementationIdentifier, bytes calldata message_) { | ||
|
||
( | ||
SmallStructs.SmallVM memory vm, | ||
bytes calldata payload, | ||
bool valid, | ||
string memory reason | ||
) = parseAndVerifyVM(_message); | ||
|
||
require(valid, reason); | ||
|
||
// Load the identifier for the calling contract. | ||
implementationIdentifier = abi.encodePacked(vm.emitterAddress); | ||
|
||
// Local "supposedly" this chain identifier. | ||
bytes32 thisChainIdentifier = bytes32(payload[0:32]); | ||
|
||
// Check that the message is intended for this chain. | ||
if (thisChainIdentifier != bytes32(uint256(chainId()))) revert BadChainIdentifier(); | ||
|
||
// Local the identifier for the source chain. | ||
sourceIdentifier = bytes32(bytes2(vm.emitterChainId)); | ||
|
||
// Get the application message. | ||
message_ = payload[32:]; | ||
} | ||
|
||
function _sendMessage(bytes32 destinationChainIdentifier, bytes memory destinationImplementation, bytes memory message) internal override returns(uint128 costOfSendMessageInNativeToken) { | ||
// Get the cost of sending wormhole messages. | ||
costOfSendMessageInNativeToken = uint128(WORMHOLE.messageFee()); | ||
|
||
// Emit context for relayers so they know where to send the message | ||
emit WormholeMessage(destinationChainIdentifier, destinationImplementation); | ||
|
||
// Handoff the message to wormhole. | ||
WORMHOLE.publishMessage{value: costOfSendMessageInNativeToken}( | ||
0, | ||
abi.encodePacked( | ||
destinationChainIdentifier, | ||
message | ||
), | ||
0 // Finality = complete. | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// contracts/Getters.sol | ||
// SPDX-License-Identifier: Apache 2 | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "../wormhole/Getters.sol"; | ||
|
||
contract GettersGetter { | ||
Getters immutable public WORMHOLE_STATE; | ||
|
||
constructor(address wormholeState) { | ||
WORMHOLE_STATE = Getters(wormholeState); | ||
} | ||
|
||
function getGuardianSet(uint32 index) public view returns (Structs.GuardianSet memory) { | ||
return WORMHOLE_STATE.getGuardianSet(index); | ||
} | ||
|
||
function getCurrentGuardianSetIndex() public view returns (uint32) { | ||
return WORMHOLE_STATE.getCurrentGuardianSetIndex(); | ||
} | ||
|
||
function getGuardianSetExpiry() public view returns (uint32) { | ||
return WORMHOLE_STATE.getGuardianSetExpiry(); | ||
} | ||
|
||
function governanceActionIsConsumed(bytes32 hash) public view returns (bool) { | ||
return WORMHOLE_STATE.governanceActionIsConsumed(hash); | ||
} | ||
|
||
function isInitialized(address impl) public view returns (bool) { | ||
return WORMHOLE_STATE.isInitialized(impl); | ||
} | ||
|
||
function chainId() public view returns (uint16) { | ||
return WORMHOLE_STATE.chainId(); | ||
} | ||
|
||
function evmChainId() public view returns (uint256) { | ||
return WORMHOLE_STATE.evmChainId(); | ||
} | ||
|
||
function isFork() public view returns (bool) { | ||
return WORMHOLE_STATE.isFork(); | ||
} | ||
|
||
function governanceChainId() public view returns (uint16){ | ||
return WORMHOLE_STATE.governanceChainId(); | ||
} | ||
|
||
function governanceContract() public view returns (bytes32){ | ||
return WORMHOLE_STATE.governanceContract(); | ||
} | ||
|
||
function messageFee() public view returns (uint256) { | ||
return WORMHOLE_STATE.messageFee(); | ||
} | ||
|
||
function nextSequence(address emitter) public view returns (uint64) { | ||
return WORMHOLE_STATE.nextSequence(emitter); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
This is an alternative implementation of the wormhole message verification with the purpose of significantly reducing gas cost but also simplify integration by always keeping the message in calldata. |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: Apache 2 | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
interface SmallStructs { | ||
|
||
struct SmallVM { | ||
// uint8 version; | ||
// uint32 timestamp; | ||
// uint32 nonce; | ||
uint16 emitterChainId; | ||
bytes32 emitterAddress; | ||
// uint64 sequence; | ||
// uint8 consistencyLevel; | ||
|
||
uint32 guardianSetIndex; | ||
} | ||
} |
Oops, something went wrong.