Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Required gas, events, reentrancy, go linter #66

Merged
merged 14 commits into from
Apr 5, 2024
Merged

Conversation

minghinmatthewlam
Copy link

Why this should be merged

Fixes #23 #55 #36

How this works

  • Adds nonReentrant for external sends
  • Adds WithdrawTokens event
  • Adds SendTokensInput to SendTokens event
  • Updated required gas limits based on forge test --gas-report and testing with e2e tests
  • Adds go linter

How this was tested

  • Getting gas estimation from forge
  • Testing locally with lowered gas limits in the e2e tests
  • CI

How is this documented

geoff-vball
geoff-vball previously approved these changes Apr 2, 2024
// Need to figure out appropriate values.
uint256 public constant SEND_TOKENS_REQUIRED_GAS = 300_000;
/// @notice Required gas limit for sending tokens to another chain.
uint256 public constant SEND_TOKENS_REQUIRED_GAS = 80_000;
Copy link
Collaborator

@michaelkaplan13 michaelkaplan13 Apr 2, 2024

Choose a reason for hiding this comment

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

Given that token source contracts are intended to be compatible with any destination contracts that implement the required interface, I think we should have the gas limit for messages sent from source -> destination be provided as a parameter for each call to send. A destination contracts can have arbitrarily complex logic, so we shouldn't try to fit one gas limit to all of them.

It could make sense to have some minimum or default that we don't allow the passed value to be less than, but I think we'll need to allow for callers to specify higher values if needed.

Copy link
Author

Choose a reason for hiding this comment

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

added requiredGasLimit to SendTokensInput since destination token bridges also need to pass in case for multihop.

Copy link
Author

Choose a reason for hiding this comment

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

The required gas limit for message from destination token bridge -> source is still a constant in TeleporterTokenDestination though

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the same logic applies to messages to the source, since the source can be composed with an arbitrary ERC20, which can also execute arbitrary logic.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good point, maybe we should have the value set in the constructor of TeleporterTokenDestination? Its value should be more or less constant for a given source contract, but it could change from one source to another as Cam called out.

Copy link
Collaborator

@michaelkaplan13 michaelkaplan13 left a comment

Choose a reason for hiding this comment

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

Looks like the E2E tests need some updating to account for the changes to remove allowedRelayerAddresses. Other than that and Cam's comment about account for different gas amounts used by different source contracts, the changes LGTM.

Copy link
Contributor

@geoff-vball geoff-vball left a comment

Choose a reason for hiding this comment

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

Just commenting to get notified when R4R

geoff-vball
geoff-vball previously approved these changes Apr 4, 2024
@@ -34,8 +34,8 @@ abstract contract TeleporterTokenDestination is
/// @notice The ERC20 token this contract uses to pay for Teleporter fees.
address public immutable feeTokenAddress;

/// @notice Required gas limit for sending tokens to another chain.
uint256 public constant SEND_TOKENS_REQUIRED_GAS = 220_000;
/// @notice Required gas limit for sending tokens back to the source blockchain.
Copy link
Collaborator

Choose a reason for hiding this comment

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

A few asks for this comment:

  • Can you update this comment to describe the multihop case? Right now, it reads more like a point to point transfer.
  • Can you clarify that this figure accounts for the fixed gas relaying the transfer to a third chain? Also can you mention what blockchain this gas is spent on?

Copy link
Author

Choose a reason for hiding this comment

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

updated comment to clarify

contracts/src/TeleporterTokenDestination.sol Show resolved Hide resolved
contracts/src/TeleporterTokenDestination.sol Show resolved Hide resolved
* @param secondaryFee amount of tokens to pay for Teleporter fee if a multihop is needed.
* @param allowedRelayerAddresses addresses of relayers allowed to send the message
* @param secondaryFee amount of tokens to pay for Teleporter fee if a multihop is needed
* @param requiredGasLimit gas limit requirement for sending to a destination token bridge
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain that this is required because a source/destination bridge contracts are able to call arbitrary code?

Copy link
Author

Choose a reason for hiding this comment

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

updated comment

cam-schultz
cam-schultz previously approved these changes Apr 5, 2024
Copy link
Collaborator

@cam-schultz cam-schultz left a comment

Choose a reason for hiding this comment

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

LGTM

geoff-vball
geoff-vball previously approved these changes Apr 5, 2024
michaelkaplan13
michaelkaplan13 previously approved these changes Apr 5, 2024
@minghinmatthewlam minghinmatthewlam merged commit a211330 into main Apr 5, 2024
12 of 13 checks passed
@minghinmatthewlam minghinmatthewlam deleted the required-gas branch April 5, 2024 21:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Determine RequiredGasLimit for TeleporterTokenSource/Destination
4 participants