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

Deliver messages directly to Polymer Dispatcher #31

Merged
merged 9 commits into from
Apr 20, 2024
Merged

Conversation

reednaa
Copy link
Member

@reednaa reednaa commented Mar 7, 2024

Connect directly with the Polymer dispatcher for simpler off-chain indexing of the packages. This allows Generalised Incentives to have full control over the package flow.

@reednaa reednaa changed the title Deliver messages directly to the polymer Dispatcher Deliver messages directly to Polymer Dispatcher Mar 8, 2024
@reednaa reednaa requested a review from alfredo-stonk March 8, 2024 12:39
Copy link

@alfredo-stonk alfredo-stonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Main feedback to how to ensure your dApp is only connected to trusted counterparties. Also minor notes for current limitations on our end.

src/apps/polymer/vIBCEscrow.sol Outdated Show resolved Hide resolved
src/apps/polymer/vIBCEscrow.sol Outdated Show resolved Hide resolved
src/apps/polymer/vIBCEscrow.sol Outdated Show resolved Hide resolved
src/apps/polymer/vIBCEscrow.sol Outdated Show resolved Hide resolved
@reednaa reednaa mentioned this pull request Mar 20, 2024
@reednaa reednaa requested a review from alfredo-stonk April 17, 2024 08:33
@reednaa
Copy link
Member Author

reednaa commented Apr 17, 2024

I have updated the implementation with the newest ABI inspired by Mars.sol.

Let me know if the implementation is good and secure.

Copy link

@alfredo-stonk alfredo-stonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Escrow implementation with regular IBC channels looks good.

src/apps/polymer/APolymerEscrow.sol Show resolved Hide resolved
Comment on lines +164 to +169
// Set a verificaiton context so we can recover the ack.
isVerifiedMessageHash[keccak256(rawMessage)] = VerifiedMessageHashContext({
chainIdentifier: packet.src.channelId,
implementationIdentifier: destinationImplementationIdentifier
});
_handleAck(packet.src.channelId, destinationImplementationIdentifier, rawMessage, feeRecipitent, gasLimit);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If _handleAck reverts, isVerifiedMessaageHash state wouldn't be mutated. So how to recover the ack? this is related to the question above too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good question. What is the execution strictness when delivered from Polymer?
Is it required for applications that the on....Packet functions never revert?
So we need to call _handleAck within a try statement?
What happens if onAcknowledgementPacket reverts from `Polymer's perspective?

Generally, _handleAck should never revert if the relayer provides enough gas for the application. It is only if the relayer cheaps out the function can revert.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Polymer side, all packet callback functions on...Packet are effectively try-catched, eg. onAcknowledgementPacket(bool success, bytes memory data) = _callIfContract(. So it's ok if IBC-dApps revert in any callback functions.

In your case, since retry is handled by recoverAck, I'd recommend you wrap _handleAck in try-catch, so to record acks even when _handleAck reverts due to lack of gas.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The try-catch implementation in the dispatcher is vulnerable to gas denial of service for large gas spenders. This is because max 63/64 of the gas is forwarded. There should be an gas check, otherwise there is a soft-max gas limit for Polymer applications.

Something like this:

unchecked {
if (!success) if(gasleft() < maxGasAck * 1 / 63) revert NotEnoughGasExecution();
}

This is not a catch-all solution since reverting by spending all gas will block from the applications side. But at least that will be the applications fault.

Looking further through your implementation, this is not an immediate using it for our testnet purposes.

Our contracts should not revert when packages are properly relayed and as a result, the try-catch in itself is not what we worry about. Furthermore, there is still a way to process the acks since acks are not written (on Polymer) until they execute without failure.

@reednaa reednaa marked this pull request as ready for review April 19, 2024 14:23
@reednaa reednaa merged commit 681fc11 into main Apr 20, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants