Skip to content

Commit

Permalink
Refactor L1 user deposit processing in x/rollup module
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkushinDaniil committed Sep 12, 2024
1 parent c3af49f commit 7f1a529
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions x/rollup/keeper/deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,23 @@ func (k *Keeper) processL1UserDepositTxs(ctx sdk.Context, txs [][]byte) (sdk.Eve
return nil, types.WrapError(types.ErrInvalidL1Txs, "L1 tx must be a user deposit tx, type %d", tx.Type())
}
ctx.Logger().Debug("User deposit tx", "index", i, "tx", string(lo.Must(tx.MarshalJSON())))
to := tx.To()
// if the receipient is nil, it means the tx is creating a contract which we don't support, so return an error.
// see https://github.com/ethereum-optimism/op-geth/blob/v1.101301.0-rc.2/core/state_processor.go#L154
if to == nil {
if tx.To() == nil {
ctx.Logger().Error("Contract creation txs are not supported", "index", i)
return nil, types.WrapError(types.ErrInvalidL1Txs, "Contract creation txs are not supported, index:%d", i)
}
cosmAddr := utils.EvmToCosmosAddress(*to)
mintAmount := sdkmath.NewIntFromBigInt(tx.Value())

// Get the sender's address from the transaction
// We use NewLondonSigner because deposit transactions follow EIP-2718 and EIP-2930
to, err := ethtypes.NewLondonSigner(tx.ChainId()).Sender(&tx)
if err != nil {
ctx.Logger().Error("Failed to get sender address", "evmAddress", to, "err", err)
return nil, types.WrapError(types.ErrInvalidL1Txs, "failed to get sender address: %v", err)
}
cosmAddr := utils.EvmToCosmosAddress(to)
mintAmount := sdkmath.NewIntFromBigInt(tx.Mint())

mintEvent, err := k.mintETH(ctx, cosmAddr, mintAmount)
if err != nil {
ctx.Logger().Error("Failed to mint ETH", "evmAddress", to, "cosmosAddress", cosmAddr, "err", err)
Expand Down

0 comments on commit 7f1a529

Please sign in to comment.