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

implement AstriaMintableERC20, update deposit tx to support ERC20 mints #20

Merged
merged 23 commits into from
Jun 10, 2024

Conversation

noot
Copy link
Contributor

@noot noot commented May 22, 2024

  • implement AstriaMintableERC20.sol, allows an immutable address bridge to mint or burn
  • this address should be set at genesis and the sender of DepositTxs is set to this address
  • DepositTx was updated to include to and data which are set for erc20 mints (later on burns), to is set to the erc20 address of the AstriaMintableERC20 and data is the calldata to call the mint function
  • genesis config fields for erc20s must be set to allow bridging erc20s from the sequencer. namely the erc20 contract address must be set, meaning the token must already be deployed

testing:

  • i tested this manually end-to-end using the instructions in contracts/README.md.

closes #9

@noot noot marked this pull request as ready for review May 23, 2024 22:39
//
// the fees are spent from the "bridge account" which is not actually a real account, but is instead some
// address defined by consensus, so the gas cost is not actually deducted from any account.
Gas: 16000,
Copy link

Choose a reason for hiding this comment

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

I'm not sure if this is a big enough number, the gas costs of a tx is normally gasUnits * gasPrice. I'd either make it so the DepositTxs pay no gas or set this to something crazy large to account for EIP1559 gas price swings

Copy link
Contributor Author

@noot noot Jun 1, 2024

Choose a reason for hiding this comment

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

I originally tried to just make the tx not use gas, but it got a bit janky when it came to the state transition gas accounting D:

the gas parameter here is just for the gas units, not the gas price, and I don't think gas itself can vary that much? DepositTxs don't have a gas price since they're inherent to consensus

Copy link

Choose a reason for hiding this comment

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

Lol I got that wrong, you're right it's the gas unit and not gas cost. This should be fine then

@@ -0,0 +1,14 @@
// SPDX-License-Identifier: UNLICENSED
Copy link

Choose a reason for hiding this comment

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

This file can be deleted

assetID := [32]byte{}
copy(assetID[:], deposit.AssetId[:32])

if _, ok := s.bridgeAllowedAssetIDs[assetID]; !ok {
Copy link

Choose a reason for hiding this comment

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

We don't check that the bridge account itself is tied to this asset or if the bridge's start height requirement has been met. Might be safer to make these checks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, added!

@noot noot requested a review from Lilyjjo June 6, 2024 18:26
github-merge-queue bot pushed a commit to astriaorg/astria that referenced this pull request Jun 7, 2024
## Summary
implement withdrawals of ERC20 tokens that are of type
`AstriaBridgeableERC20` (see implemented contract).

## Background
we want to be able to withdraw ERC20 tokens that are bridged to a
rollup.

## Changes
- implement `AstriaBridgeableERC20` which is a standard `ERC20` contract
with additional functionality for minting (not used by the withdrawer,
implemented/tested here
astriaorg/astria-geth#20) as well as
functionality for withdrawing
- implement `IAstriaWithdrawer` which is implemented by both
`AstriaWithdrawer` and `AstriaMintableERC20`.
- the withdrawer now interacts with a `IAstriaWithdrawer`. both native
assets and ERC20 withdrawals have the same event signatures, so no
additional code was needed for the withdrawer itself.
- to use the withdrawer with an `AstriaBridgeableERC20`, the
`ASTRIA_BRIDGE_WITHDRAWER_ETHEREUM_CONTRACT_ADDRESS` is set to some
`AstriaMintableERC20`, and
`ASTRIA_BRIDGE_WITHDRAWER_ROLLUP_ASSET_DENOMINATION` is set to the
rollup asset's denomination as represented on the sequencer. for
example, if the asset is represented on the sequencer is
`transfer/channel-1/usdc`, that is the rollup asset denomination. the
`name/symbol` of the ERC20 contract are not relevant.
- also update the build script to write the generated abigen contract
bindings to files, this is easier for debugging and unit testing.

## Testing
unit tests

## Related Issues

closes #924
Copy link
Member

Choose a reason for hiding this comment

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

can we add a .gitattributes file and mark as generated?

func (tx *DepositTx) gas() uint64 { return tx.Gas }
func (tx *DepositTx) gasFeeCap() *big.Int { return new(big.Int) }
func (tx *DepositTx) gasTipCap() *big.Int { return new(big.Int) }
func (tx *DepositTx) gasPrice() *big.Int { return new(big.Int) }
func (tx *DepositTx) value() *big.Int { return tx.Value }
func (tx *DepositTx) nonce() uint64 { return 0 }
func (tx *DepositTx) to() *common.Address { return nil }
func (tx *DepositTx) to() *common.Address { return tx.To }
Copy link
Member

Choose a reason for hiding this comment

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

how were we identifying the correct account to send funds to previously?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

using the From field, but i felt that was confusing, and now we need to set the From field to the bridge "account"

Comment on lines 109 to 114
if cfg.Erc20Asset == nil && nativeBridgeSeen {
return nil, errors.New("only one native bridge address is allowed")
}
if cfg.Erc20Asset != nil && !nativeBridgeSeen {
if cfg.Erc20Asset == nil && !nativeBridgeSeen {
nativeBridgeSeen = true
}
Copy link
Member

Choose a reason for hiding this comment

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

I know I wrote this but maybe a slightly cleaner if we combine?

if cfg.Erc20Asset == nil {
        if nativeBridgeSeen {
                return nil, errors.New("only one native bridge address is allowed")
        }
        nativeBridgeSeen = true
}

nativeBridgeSeen = true
}

if cfg.Erc20Asset != nil && bc.Config().AstriaBridgeSenderAddress == (common.Address{}) {
return nil, errors.New("astria bridge sender address must be set for bridged ERC20 assets")
Copy link
Member

Choose a reason for hiding this comment

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

Noted further down, but we should probably use string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AstriaBridgeSenderAddress is an evm address address (the fake address mints are sent from) so can leave this

@@ -346,6 +346,7 @@ type ChainConfig struct {
AstriaCelestiaInitialHeight uint64 `json:"astriaCelestiaInitialHeight"`
AstriaCelestiaHeightVariance uint64 `json:"astriaCelestiaHeightVariance,omitempty"`
AstriaBridgeAddressConfigs []AstriaBridgeAddressConfig `json:"astriaBridgeAddresses,omitempty"`
AstriaBridgeSenderAddress common.Address `json:"astriaBridgeSenderAddress,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

We should use a bech32m encoded string here, given that we marked the bytes as deprecated.

Does this have any implications on the contract?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above, this is actually supposed to be an evm address, it's not an astria address

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i updated the contracts for bech32 also btw

@noot noot requested a review from joroshiba June 9, 2024 19:34
@noot noot merged commit 3d160b2 into main Jun 10, 2024
2 checks passed
@noot noot deleted the noot/erc20-deposit branch June 10, 2024 16:04
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.

feat: support deposits to erc20 addresses
3 participants