-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,106 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity >=0.8.0; | ||
|
||
/*@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@ HYPERLANE @@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@*/ | ||
|
||
// ============ Internal Imports ============ | ||
import {TokenRouter} from "./libs/TokenRouter.sol"; | ||
import {HypNativeCollateral} from "./HypNativeCollateral.sol"; | ||
import {StandardHookMetadata} from "../hooks/libs/StandardHookMetadata.sol"; | ||
import {Address} from "@openzeppelin/contracts/utils/Address.sol"; | ||
|
||
/** | ||
* @title HypNative | ||
* @title Hyperlane Native Token Router that extends ERC20 with remote transfer functionality. | ||
* @author Abacus Works | ||
* @notice This contract facilitates the transfer of value between chains using value transfer hooks | ||
* @dev Supply on each chain is not constant but the aggregate supply across all chains is. | ||
*/ | ||
contract HypNative is HypNativeCollateral { | ||
constructor(address _mailbox) HypNativeCollateral(_mailbox) {} | ||
contract HypNative is TokenRouter { | ||
/** | ||
* @dev Emitted when native tokens are donated to the contract. | ||
* @param sender The address of the sender. | ||
* @param amount The amount of native tokens donated. | ||
*/ | ||
event Donation(address indexed sender, uint256 amount); | ||
|
||
// ============ External Functions ============ | ||
constructor(address _mailbox) TokenRouter(_mailbox) {} | ||
|
||
/// @inheritdoc TokenRouter | ||
/** | ||
* @notice Initializes the Hyperlane router | ||
* @param _hook The post-dispatch hook contract. | ||
* @param _interchainSecurityModule The interchain security module contract. | ||
* @param _owner The this contract. | ||
*/ | ||
function initialize( | ||
address _hook, | ||
address _interchainSecurityModule, | ||
address _owner | ||
) public initializer { | ||
_MailboxClient_initialize(_hook, _interchainSecurityModule, _owner); | ||
} | ||
|
||
/** | ||
* @inheritdoc TokenRouter | ||
* @dev uses (`msg.value` - `_amount`) as hook payment and `msg.sender` as refund address. | ||
*/ | ||
function transferRemote( | ||
uint32 _destination, | ||
bytes32 _recipient, | ||
uint256 _amount | ||
) external payable virtual override returns (bytes32 messageId) { | ||
bytes calldata emptyBytes; | ||
assembly { | ||
emptyBytes.length := 0 | ||
emptyBytes.offset := 0 | ||
} | ||
return | ||
transferRemote( | ||
_destination, | ||
_recipient, | ||
_amount, | ||
emptyBytes, | ||
address(hook) | ||
); | ||
require(msg.value >= _amount, "Native: amount exceeds msg.value"); | ||
uint256 _hookPayment = msg.value - _amount; | ||
return _transferRemote(_destination, _recipient, _amount, _hookPayment); | ||
} | ||
|
||
/** | ||
* @inheritdoc TokenRouter | ||
* @dev use _hook with caution, make sure that this hook can handle msg.value transfer using the metadata.msgValue() | ||
* @dev uses (`msg.value` - `_amount`) as hook payment. | ||
*/ | ||
function transferRemote( | ||
uint32 _destination, | ||
bytes32 _recipient, | ||
uint256 _amount, | ||
bytes calldata _hookMetadata, | ||
address _hook | ||
) public payable virtual override returns (bytes32 messageId) { | ||
uint256 quote = _GasRouter_quoteDispatch( | ||
_destination, | ||
_hookMetadata, | ||
_hook | ||
); | ||
|
||
bytes memory hookMetadata = StandardHookMetadata.overrideMsgValue( | ||
_hookMetadata, | ||
_amount | ||
); | ||
|
||
) external payable virtual override returns (bytes32 messageId) { | ||
require(msg.value >= _amount, "Native: amount exceeds msg.value"); | ||
uint256 _hookPayment = msg.value - _amount; | ||
return | ||
_transferRemote( | ||
_destination, | ||
_recipient, | ||
_amount, | ||
_amount + quote, | ||
hookMetadata, | ||
_hookPayment, | ||
_hookMetadata, | ||
_hook | ||
); | ||
} | ||
|
||
function balanceOf( | ||
address _account | ||
) external view override returns (uint256) { | ||
return _account.balance; | ||
} | ||
|
||
/** | ||
* @inheritdoc TokenRouter | ||
* @dev No-op because native amount is transferred in `msg.value` | ||
* @dev Compiler will not include this in the bytecode. | ||
*/ | ||
function _transferFromSender( | ||
uint256 | ||
) internal pure override returns (bytes memory) { | ||
return bytes(""); // no metadata | ||
} | ||
|
||
/** | ||
* @dev Sends `_amount` of native token to `_recipient` balance. | ||
* @inheritdoc TokenRouter | ||
*/ | ||
function _transferTo( | ||
address _recipient, | ||
uint256 _amount, | ||
bytes calldata // no metadata | ||
) internal virtual override { | ||
Address.sendValue(payable(_recipient), _amount); | ||
} | ||
|
||
receive() external payable { | ||
emit Donation(msg.sender, msg.value); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,84 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity >=0.8.0; | ||
Check notice Code scanning / Olympix Integrated Security Using an unbounded pragma for Solidity version may be unsafe if future versions introduce breaking changes. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/unbounded-pragma Low
Using an unbounded pragma for Solidity version may be unsafe if future versions introduce breaking changes. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/unbounded-pragma
|
||
|
||
/*@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@ HYPERLANE @@@@@@@ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@@ | ||
@@@@@@@@@ @@@@@@@@*/ | ||
|
||
// ============ Internal Imports ============ | ||
import {TokenRouter} from "./libs/TokenRouter.sol"; | ||
import {TokenMessage} from "./libs/TokenMessage.sol"; | ||
import {Address} from "@openzeppelin/contracts/utils/Address.sol"; | ||
import {HypNative} from "./HypNative.sol"; | ||
import {StandardHookMetadata} from "../hooks/libs/StandardHookMetadata.sol"; | ||
|
||
/** | ||
* @title Hyperlane Native Token Router that extends ERC20 with remote transfer functionality. | ||
* @title HypNativeCollateral | ||
* @author Abacus Works | ||
* @dev Supply on each chain is not constant but the aggregate supply across all chains is. | ||
* @notice This contract facilitates the transfer of value between chains using value transfer hooks | ||
*/ | ||
contract HypNativeCollateral is TokenRouter { | ||
/** | ||
* @dev Emitted when native tokens are donated to the contract. | ||
* @param sender The address of the sender. | ||
* @param amount The amount of native tokens donated. | ||
*/ | ||
event Donation(address indexed sender, uint256 amount); | ||
contract HypNativeCollateral is HypNative { | ||
Check failure Code scanning / Olympix Integrated Security Contracts that can receive ether but cannot send it may lock value permanently. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/locked-ether Critical
Contracts that can receive ether but cannot send it may lock value permanently. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/locked-ether
|
||
constructor(address _mailbox) HypNative(_mailbox) {} | ||
Check notice Code scanning / Olympix Integrated Security Test functions fail to thoroughly test all aspects of contract constructors, potentially missing critical initialization issues. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/incomplete-constructor-tests Low
Test functions fail to thoroughly test all aspects of contract constructors, potentially missing critical initialization issues. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/incomplete-constructor-tests
Check notice Code scanning / Olympix Integrated Security Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor Low
Parameters passed to a constructor that are not validated for correct values may lead to contract creation in an undesired state. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/no-parameter-validation-in-constructor
|
||
|
||
constructor(address _mailbox) TokenRouter(_mailbox) {} | ||
// ============ External Functions ============ | ||
|
||
/** | ||
* @notice Initializes the Hyperlane router | ||
* @param _hook The post-dispatch hook contract. | ||
* @param _interchainSecurityModule The interchain security module contract. | ||
* @param _owner The this contract. | ||
*/ | ||
function initialize( | ||
address _hook, | ||
address _interchainSecurityModule, | ||
address _owner | ||
) public initializer { | ||
_MailboxClient_initialize(_hook, _interchainSecurityModule, _owner); | ||
} | ||
|
||
/** | ||
* @inheritdoc TokenRouter | ||
* @dev uses (`msg.value` - `_amount`) as hook payment and `msg.sender` as refund address. | ||
*/ | ||
/// @inheritdoc TokenRouter | ||
function transferRemote( | ||
uint32 _destination, | ||
bytes32 _recipient, | ||
uint256 _amount | ||
) external payable virtual override returns (bytes32 messageId) { | ||
require(msg.value >= _amount, "Native: amount exceeds msg.value"); | ||
uint256 _hookPayment = msg.value - _amount; | ||
return _transferRemote(_destination, _recipient, _amount, _hookPayment); | ||
bytes calldata emptyBytes; | ||
assembly { | ||
emptyBytes.length := 0 | ||
emptyBytes.offset := 0 | ||
} | ||
return | ||
transferRemote( | ||
_destination, | ||
_recipient, | ||
_amount, | ||
emptyBytes, | ||
address(hook) | ||
); | ||
} | ||
|
||
/** | ||
* @inheritdoc TokenRouter | ||
* @dev uses (`msg.value` - `_amount`) as hook payment. | ||
* @dev use _hook with caution, make sure that this hook can handle msg.value transfer using the metadata.msgValue() | ||
*/ | ||
function transferRemote( | ||
uint32 _destination, | ||
bytes32 _recipient, | ||
uint256 _amount, | ||
bytes calldata _hookMetadata, | ||
address _hook | ||
) external payable virtual override returns (bytes32 messageId) { | ||
require(msg.value >= _amount, "Native: amount exceeds msg.value"); | ||
uint256 _hookPayment = msg.value - _amount; | ||
) public payable virtual override returns (bytes32 messageId) { | ||
uint256 quote = _GasRouter_quoteDispatch( | ||
_destination, | ||
_hookMetadata, | ||
_hook | ||
); | ||
|
||
bytes memory hookMetadata = StandardHookMetadata.overrideMsgValue( | ||
_hookMetadata, | ||
_amount | ||
); | ||
|
||
return | ||
_transferRemote( | ||
_destination, | ||
_recipient, | ||
_amount, | ||
_hookPayment, | ||
_hookMetadata, | ||
_amount + quote, | ||
hookMetadata, | ||
_hook | ||
); | ||
} | ||
|
||
function balanceOf( | ||
address _account | ||
) external view override returns (uint256) { | ||
return _account.balance; | ||
} | ||
|
||
/** | ||
* @inheritdoc TokenRouter | ||
* @dev No-op because native amount is transferred in `msg.value` | ||
* @dev Compiler will not include this in the bytecode. | ||
*/ | ||
function _transferFromSender( | ||
uint256 | ||
) internal pure override returns (bytes memory) { | ||
return bytes(""); // no metadata | ||
} | ||
|
||
/** | ||
* @dev Sends `_amount` of native token to `_recipient` balance. | ||
* @inheritdoc TokenRouter | ||
*/ | ||
function _transferTo( | ||
address _recipient, | ||
uint256 _amount, | ||
bytes calldata // no metadata | ||
) internal virtual override { | ||
Address.sendValue(payable(_recipient), _amount); | ||
} | ||
|
||
receive() external payable { | ||
emit Donation(msg.sender, msg.value); | ||
} | ||
} |