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

Return data abuse results in non-deliverable messages #8

Open
reednaa opened this issue Oct 13, 2023 · 0 comments
Open

Return data abuse results in non-deliverable messages #8

reednaa opened this issue Oct 13, 2023 · 0 comments

Comments

@reednaa
Copy link
Member

reednaa commented Oct 13, 2023

Currently, when delivering a message to a destination application, the delivery is placed through a try-catch statement. It looks roughly like this:

try ICrossChainReceiver(toApplication).receiveMessage{gas: maxGas}(sourceIdentifier, messageIdentifier, fromApplication, message[CTX0_MESSAGE_START: ])
returns (bytes memory ack) {
    acknowledgement = ack;
} catch (bytes memory /* err */) {
    acknowledgement = abi.encodePacked(
        MESSAGE_REVERTED,
        message[CTX0_MESSAGE_START: ]
    );
}

Ideally, this would ensure that if anything goes wrong, out of gas, the exception raised, incorrectly configured contract, return bombs, you name it, it would be caught and execution can continue. This would greatly simplify relayer design and relaying assumptions.

However, that is not the case. Solidity has an open issue on the topic: ethereum/solidity#13869 and it also contains a list of cases where Solidity doesn't catch an error.

One solution would be to change the implementation to:

(bool success, bytes memory returndata) = toApplication.call{gas: maxGas}(abi.encodeWithSignature(....));
if (success) {
    (acknowledgement) = abi.decode(returndata, (bytes));
} else {
    acknowledgement = abi.encodePacked(
        MESSAGE_REVERTED,
        message[CTX0_MESSAGE_START: ]
    );
}

But abi.decode can fail if the application doesn't return the expected format which is "[location, length, bytes]". In theory, it is possible to check that the returndata is longer than 64 bytes + length but this adds complexity and gas cost. It also won't protect against return bombs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant