-
Notifications
You must be signed in to change notification settings - Fork 29
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
Native Token Bridge #40
Conversation
2b80900
to
f7ee05a
Compare
contracts/src/CrossChainApplications/NativeTokenBridge/NativeTokenReceiver.sol
Fixed
Show fixed
Hide fixed
contracts/src/CrossChainApplications/NativeTokenBridge/NativeTokenReceiver.sol
Fixed
Show fixed
Hide fixed
contracts/src/CrossChainApplications/NativeTokenBridge/NativeTokenMinter.sol
Fixed
Show fixed
Hide fixed
contracts/src/CrossChainApplications/NativeTokenBridge/NativeTokenMinter.sol
Fixed
Show fixed
Hide fixed
contracts/src/CrossChainApplications/NativeTokenBridge/NativeTokenMinter.sol
Fixed
Show fixed
Hide fixed
contracts/src/CrossChainApplications/NativeTokenBridge/NativeTokenMinter.sol
Outdated
Show resolved
Hide resolved
Some initial thoughts:
|
contracts/src/CrossChainApplications/NativeTokenBridge/NativeTokenDestination.sol
Outdated
Show resolved
Hide resolved
contracts/src/CrossChainApplications/NativeTokenBridge/NativeTokenDestination.sol
Show resolved
Hide resolved
contracts/src/CrossChainApplications/NativeTokenBridge/NativeTokenDestination.sol
Outdated
Show resolved
Hide resolved
contracts/src/CrossChainApplications/NativeTokenBridge/NativeTokenSource.sol
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly LGTM, left some nits and I didn't see reportTotalBurnedTxFees
defined in the interface for INativeTokenDestination
. Other than that, can you create new issues regarding comments that will be deferred.
. "github.com/onsi/gomega" | ||
) | ||
|
||
func NativeTokenBridge(network interfaces.LocalNetwork) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, can we use interfaces.Network
here instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was interfaces.Network
, but Cam suggested interfaces.LocalNetwork
. I think that's the right decision because these tests won't be able to be run on a testnet, since they require their own subnet that has admin address set for the Native Minter precompile. So while we could spin up a subnet on Fuji to test these contracts, the flow would have to be different from what is here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good no strong pref here. After this gets deployed and a fuji subnet has it set up, would we be able to use that subnet as a testnet if wanted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could test the functionality, yeah, but we would need to not use the same setup code. So we could split them out at that point of setup
and then test
.
Native Token Bridge
🚨 Report Summary
For more details view the full report in OpenZeppelin Code Inspector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handful of final nits but otherwise LGTM
contracts/src/CrossChainApplications/NativeTokenBridge/NativeTokenDestination.sol
Outdated
Show resolved
Hide resolved
contracts/src/CrossChainApplications/NativeTokenBridge/ERC20TokenSource.sol
Show resolved
Hide resolved
contracts/src/CrossChainApplications/NativeTokenBridge/NativeTokenSource.sol
Outdated
Show resolved
Hide resolved
contracts/src/CrossChainApplications/NativeTokenBridge/NativeTokenDestination.sol
Outdated
Show resolved
Hide resolved
|
||
// Transfer to recipient | ||
emit UnlockTokens(recipient, amount); | ||
payable(recipient).transfer(amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OZ Defender report suggests using recipient.call{value: amount, gas: XXX}("")
here. I think this is probably a worthwhile change because it's possible for the fallback
method of a contract to be called to execute code. We have the proper nonReentrant
guard in place already to prevent against any reentrancy, so I think we can use the full gasleft()
amount in the call.
This could also apply to the two other places we use .transfer()
in the new contracts, and I'd say is worth updating these to be consistent, but given that they only are transferring to the burn address it shouldn't be possible for that to call code either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelkaplan13 What do you think of using https://github.com/OpenZeppelin/openzeppelin-contracts/blob/6ba452dea4258afe77726293435f10baf2bed265/contracts/utils/Address.sol#L41?
Just using recipient.call{value: amount, gas: XXX}("")
actually bloats to
(bool success, ) = BURNED_TX_FEES_ADDRESS.call{value: amount, gas: gasleft()}(""); require(success, "NativeTokensource: failed to burn tokens");
Because we have to check the return status of call
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know that existed, but looks like exactly what we'd want 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure, but I think .call()
passes along the remaining gas if not explicitly set also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed that here.
You can also leave the gas amount, then it will forward all gas and let the called contract execute its logic and return the remainder. Safer is to provide an upper limit, just in case.
Great find with that OZ library, lets definitely use it 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelkaplan13 can you clarify your consideration of fallback
functions in terms of comparing tranfser
and call
? IIUC, both transfer and low level call handle fallback functions the same, and both are guarded through reentrancy guards, so the difference is the gas passed down
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that transfer
always uses at most 2300 gas, which creates a hard limit on the amount of gas available to any fallback
function. That becomes problematic if the gas cost of operations change in network upgrades because fallback functions that may have used <=2300 gas prior may need >2300 afterwards. Using call
lets them use as much gas is provided in the transaction, so they could still work even if they use more gas after future upgrades.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's right. There's a helpful comment above the sendValue
implementation I also linked above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay yup thats my understanding as well, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢 🚀
I think it looks ready to roll! Excited to get it merged and start the follow up issues soon also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks for pushing through comments and making new issues! 🚀
Wow |
Why this should be merged
This adds a pair of contracts that can move a native token from an existing EVM chain into a new EVM chain as the new chain's native token. For instance, you could create a subnet that uses AVAX from the C-chain as its native token used to pay for transaction fees in that subnet.
See #22
How this works
See
contracts/src/CrossChainApplications/NativeTokenBridge/README.md
How this was tested
e2e tests added
How is this documented
See
contracts/src/CrossChainApplications/NativeTokenBridge/README.md