Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix audit issue #152

Merged
merged 10 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ORMP
Submodule ORMP updated from 9cfc28 to 6a066a
15 changes: 6 additions & 9 deletions src/lines/ORMPLine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.17;

import "./base/BaseMessageLine.sol";
import "./base/LineLookup.sol";
import "ORMP/src/interfaces/IEndpoint.sol";
import "ORMP/src/interfaces/IORMP.sol";
import "ORMP/src/user/Application.sol";
import "@openzeppelin/contracts/access/Ownable2Step.sol";

Expand All @@ -16,11 +16,6 @@ contract ORMPLine is BaseMessageLine, Application, LineLookup, Ownable2Step {
_setURI(uri);
}

function clearFailedMessage(Message calldata message) external {
require(msg.sender == message.to, "!auth");
_clearFailedMessage(message);
}

function setAppConfig(address oracle, address relayer) external onlyOwner {
_setAppConfig(oracle, relayer);
}
Expand All @@ -45,11 +40,12 @@ contract ORMPLine is BaseMessageLine, Application, LineLookup, Ownable2Step {
internal
override
{
(uint256 gasLimit, address refund, bytes memory ormpParams) = abi.decode(params, (uint256, address, bytes));
bytes memory encoded = abi.encodeWithSelector(ORMPLine.recv.selector, fromDapp, toDapp, message);
IEndpoint(TRUSTED_ORMP).send{value: msg.value}(toChainId, _toLine(toChainId), encoded, params);
IORMP(TRUSTED_ORMP).send{value: msg.value}(toChainId, _toLine(toChainId), gasLimit, encoded, refund, ormpParams);
}

function recv(address fromDapp, address toDapp, bytes calldata message) external {
function recv(address fromDapp, address toDapp, bytes calldata message) external onlyORMP {
uint256 fromChainId = _fromChainId();
require(_xmsgSender() == _fromLine(fromChainId), "!auth");
hujw77 marked this conversation as resolved.
Show resolved Hide resolved
_recv(fromChainId, fromDapp, toDapp, message);
Expand All @@ -61,7 +57,8 @@ contract ORMPLine is BaseMessageLine, Application, LineLookup, Ownable2Step {
override
returns (uint256)
{
(uint256 gasLimit,, bytes memory ormpParams) = abi.decode(params, (uint256, address, bytes));
bytes memory encoded = abi.encodeWithSelector(ORMPLine.recv.selector, msg.sender, toDapp, message);
return IEndpoint(TRUSTED_ORMP).fee(toChainId, toDapp, encoded, params);
return IORMP(TRUSTED_ORMP).fee(toChainId, address(this), gasLimit, encoded, ormpParams);
}
}
9 changes: 3 additions & 6 deletions src/lines/base/BaseMessageLine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ abstract contract BaseMessageLine is IMessageLine, LineMetadata {
internal
virtual;

function send(uint256 toChainId, address toDapp, bytes calldata message, bytes calldata params)
public
payable
virtual
{
function send(uint256 toChainId, address toDapp, bytes calldata message, bytes calldata params) public payable {
_send(msg.sender, toChainId, toDapp, message, params);
}

function _recv(uint256 fromChainId, address fromDapp, address toDapp, bytes memory message)
internal
returns (bytes memory)
{
(bool success, bytes memory returndata) = toDapp.call(abi.encodePacked(message, fromChainId, fromDapp));
(bool success, bytes memory returndata) =
toDapp.call{value: msg.value}(abi.encodePacked(message, fromChainId, fromDapp));
if (success) {
return returndata;
} else {
Expand Down