Skip to content

Commit

Permalink
feat: update protos, config for fees, updated bridging (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
bharath-123 committed May 29, 2024
1 parent 5c61227 commit 8a2d76b
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 47 deletions.
13 changes: 11 additions & 2 deletions genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@
"astriaSequencerInitialHeight": 2,
"astriaCelestiaInitialHeight": 2,
"astriaCelestiaHeightVariance": 10,
"astriaBridgeAddresses": [],
"astriaBridgeAllowedAssetDenom": "nria"
"astriaBridgeAddresses": [
{
"bridgeAddress": "684ae50c49a434199199c9c698115391152d7b3f",
"startHeight": 1,
"assetDenom": "nria",
"assetPrecision": 9
}
],
"astriaFeeCollectors": {
"1": "0xaC21B97d35Bf75A7dAb16f35b111a50e78A72F30"
}
},
"difficulty": "10000000",
"gasLimit": "8000000",
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/ethereum/go-ethereum
go 1.21

require (
buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240314225003-19f6b40c3e7b.2
buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.32.0-20240314225003-19f6b40c3e7b.1
buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240423053323-ccf38db75f2f.2
buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.33.0-20240423053323-ccf38db75f2f.1
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0
github.com/Microsoft/go-winio v0.6.1
github.com/VictoriaMetrics/fastcache v1.12.1
Expand Down Expand Up @@ -82,7 +82,8 @@ require (
)

require (
buf.build/gen/go/astria/astria/protocolbuffers/go v1.32.0-20240314225002-310b29d1ef86.1 // indirect
buf.build/gen/go/astria/primitives/protocolbuffers/go v1.33.0-20240422195039-812e347acd6b.1 // indirect
buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.33.0-20240423053322-44396ca8658a.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/DataDog/zstd v1.4.5 // indirect
Expand Down
23 changes: 13 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
buf.build/gen/go/astria/astria/grpc/go v1.3.0-20240314225002-310b29d1ef86.2/go.mod h1:FFX7uXjELBVDDB3WOW6lO6Sn36kC9QqkHu5xU9xY4ac=
buf.build/gen/go/astria/astria/protocolbuffers/go v1.28.1-20240314225002-310b29d1ef86.4/go.mod h1:2267P73yUQPZlQyW96+03iM2xSEMVcK0DbRqSYbyLJQ=
buf.build/gen/go/astria/astria/protocolbuffers/go v1.32.0-20240314225002-310b29d1ef86.1 h1:tqubh9diC2bk6BzxO9Obs9KgxvsfTEa0hWKqG9kA45E=
buf.build/gen/go/astria/astria/protocolbuffers/go v1.32.0-20240314225002-310b29d1ef86.1/go.mod h1:Ma4TsfKTQby0r4gCkdb6D2ThBxTNu0mSVNZF1udF2ko=
buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240314225003-19f6b40c3e7b.2 h1:9vSSs8hVVcYrQMt7CTO5r1I4eUhPiXUEBrVBZ9SaCnc=
buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240314225003-19f6b40c3e7b.2/go.mod h1:wSSvcWt7/78D8RQKhBjTaTvl0j7paszROJHHnJCfZ40=
buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.28.1-20240314225003-19f6b40c3e7b.4/go.mod h1:Ow5heKoG4UcB64gsltdmZNOZQsL8khlJzysd5lLwOfI=
buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.32.0-20240314225003-19f6b40c3e7b.1 h1:7dX4IwODvMlzcC0j0wkuLPf4JBzT9EW2O2Vb6tCEHHs=
buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.32.0-20240314225003-19f6b40c3e7b.1/go.mod h1:1PoFKhLruAgpqRKBz6cY/Z5bfXXYj3pHTvtf2uBoRJs=
buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240423053323-ccf38db75f2f.2 h1:hZ3iCorHPftvC8mtOq59JgsXVrzQa7DGVWhhReLfDUU=
buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240423053323-ccf38db75f2f.2/go.mod h1:xHHYSn2PRQE8P9sUfLoH4sDV1dPZzx7knBWLpc4r1ws=
buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.28.1-20240423053323-ccf38db75f2f.4/go.mod h1:L45ZB/W7SxQDHLrKTdGT40ytkcnntNJcF/VyiAK3psE=
buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.33.0-20240423053323-ccf38db75f2f.1 h1:OB4HbEo2YRJc3L7TNSvou07id25Xg8WmuIHmx7FnnfA=
buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.33.0-20240423053323-ccf38db75f2f.1/go.mod h1:LbzJDzXgLEtOzJmPbh6SbBC0RyK1UxkfETur2p06VHU=
buf.build/gen/go/astria/primitives/grpc/go v1.3.0-20240422195039-812e347acd6b.2/go.mod h1:5NfjRl1Y2qnN62OOMBNhKDFJKsZAvrYyJJdcoS438Aw=
buf.build/gen/go/astria/primitives/protocolbuffers/go v1.28.1-20240422195039-812e347acd6b.4/go.mod h1:Db3JxaJwPkhOVCUnIS785SD7TEI4NPB4LvWpvlWr02E=
buf.build/gen/go/astria/primitives/protocolbuffers/go v1.33.0-20240422195039-812e347acd6b.1 h1:ANEC8IuONtxy0go3DZqyXonzPGQ8kxDe3EOJNoqRol8=
buf.build/gen/go/astria/primitives/protocolbuffers/go v1.33.0-20240422195039-812e347acd6b.1/go.mod h1:1VK/IapDxiDL/a+arAHdzNuaTSeC6suYHRK8AxJQrUw=
buf.build/gen/go/astria/sequencerblock-apis/grpc/go v1.3.0-20240423053322-44396ca8658a.2/go.mod h1:YdVN+ZAuYsnCS8PH/TNFApM+3Z+rc0lQ63tHKri1KTE=
buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.28.1-20240423053322-44396ca8658a.4/go.mod h1:Zn4mqAF/djuebKMIqCoYo5aQtZuuUlZ32u9AsbJPNVY=
buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.33.0-20240423053322-44396ca8658a.1 h1:ybwQ3f4wa6hjSYFD6vEw7xfkuPNTJm9IVefs7LwF8uw=
buf.build/gen/go/astria/sequencerblock-apis/protocolbuffers/go v1.33.0-20240423053322-44396ca8658a.1/go.mod h1:avEoXDW7L9QoMYCDJFVqBm5D/qyZ4BMg31Zi/SFQR6U=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
Expand Down Expand Up @@ -1559,7 +1563,6 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
Expand Down
85 changes: 63 additions & 22 deletions grpc/execution/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package execution

import (
"bytes"
primitivev1 "buf.build/gen/go/astria/primitives/protocolbuffers/go/astria/primitive/v1"
"context"
"crypto/sha256"
"errors"
Expand All @@ -14,7 +14,6 @@ import (
"sync"
"time"

primitivev1 "buf.build/gen/go/astria/astria/protocolbuffers/go/astria/primitive/v1"
astriaGrpc "buf.build/gen/go/astria/execution-apis/grpc/go/astria/execution/v1alpha2/executionv1alpha2grpc"
astriaPb "buf.build/gen/go/astria/execution-apis/protocolbuffers/go/astria/execution/v1alpha2"
"github.com/ethereum/go-ethereum/beacon/engine"
Expand All @@ -25,6 +24,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/params"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
Expand All @@ -46,8 +46,11 @@ type ExecutionServiceServerV1Alpha2 struct {
genesisInfoCalled bool
getCommitmentStateCalled bool

bridgeAddresses map[string]struct{}
bridgeAllowedAssetID [32]byte
// astria bridge addess to config for that bridge account
bridgeAddresses map[string]*params.AstriaBridgeAddressConfig
// a set of allowed asset IDs structs are left empty
bridgeAllowedAssetIDs map[[32]byte]struct{}
nextFeeRecipient common.Address // Fee recipient for the next block
}

var (
Expand Down Expand Up @@ -91,26 +94,53 @@ func NewExecutionServiceServerV1Alpha2(eth *eth.Ethereum) (*ExecutionServiceServ
return nil, errors.New("celestia height variance not set")
}

if bc.Config().AstriaBridgeAddresses == nil {
bridgeAddresses := make(map[string]*params.AstriaBridgeAddressConfig)
bridgeAllowedAssetIDs := make(map[[32]byte]struct{})
if bc.Config().AstriaBridgeAddressConfigs == nil {
log.Warn("bridge addresses not set")
}
} else {
nativeBridgeSeen := false
for _, cfg := range bc.Config().AstriaBridgeAddressConfigs {
err := cfg.Validate()
if err != nil {
return nil, fmt.Errorf("invalid bridge address config: %w", err)
}

if bc.Config().AstriaBridgeAllowedAssetDenom == "" && bc.Config().AstriaBridgeAddresses != nil {
return nil, errors.New("bridge allowed asset denom not set")
}
if cfg.Erc20Asset != nil && nativeBridgeSeen {
return nil, errors.New("only one native bridge address is allowed")
}
if cfg.Erc20Asset != nil && !nativeBridgeSeen {
nativeBridgeSeen = true
}

bridgeAddresses := make(map[string]struct{})
for _, addr := range bc.Config().AstriaBridgeAddresses {
bridgeAddresses[string(addr)] = struct{}{}
bridgeAddresses[string(cfg.BridgeAddress)] = &cfg
assetID := sha256.Sum256([]byte(cfg.AssetDenom))
bridgeAllowedAssetIDs[assetID] = struct{}{}
}
}

bridgeAllowedAssetID := sha256.Sum256([]byte(bc.Config().AstriaBridgeAllowedAssetDenom))
// To decrease compute cost, we identify the next fee recipient at the start
// and update it as we execute blocks.
nextFeeRecipient := common.Address{}
if bc.Config().AstriaFeeCollectors == nil {
log.Warn("fee asset collectors not set, assets will be burned")
} else {
maxHeightCollectorMatch := uint32(0)
nextBlock := uint32(bc.CurrentBlock().Number.Int64()) + 1
for height, collector := range bc.Config().AstriaFeeCollectors {
if height <= nextBlock && height > maxHeightCollectorMatch {
maxHeightCollectorMatch = height
nextFeeRecipient = collector
}
}
}

return &ExecutionServiceServerV1Alpha2{
eth: eth,
bc: bc,
bridgeAddresses: bridgeAddresses,
bridgeAllowedAssetID: bridgeAllowedAssetID,
eth: eth,
bc: bc,
bridgeAddresses: bridgeAddresses,
bridgeAllowedAssetIDs: bridgeAllowedAssetIDs,
nextFeeRecipient: nextFeeRecipient,
}, nil
}

Expand Down Expand Up @@ -209,21 +239,28 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
txsToProcess := types.Transactions{}
for _, tx := range req.Transactions {
if deposit := tx.GetDeposit(); deposit != nil {
bridgeAddress := string(deposit.BridgeAddress)
if _, ok := s.bridgeAddresses[bridgeAddress]; !ok {
bridgeAddress := string(deposit.BridgeAddress.GetInner())
bac, ok := s.bridgeAddresses[bridgeAddress]
if !ok {
log.Debug("ignoring deposit tx from unknown bridge", "bridgeAddress", bridgeAddress)
continue
}

if !bytes.Equal(deposit.AssetId, s.bridgeAllowedAssetID[:]) {
if len(deposit.AssetId) != 32 {
log.Debug("ignoring deposit tx with invalid asset ID", "assetID", deposit.AssetId)
}
assetID := [32]byte{}
copy(assetID[:], deposit.AssetId[:32])
if _, ok := s.bridgeAllowedAssetIDs[assetID]; !ok {
log.Debug("ignoring deposit tx with disallowed asset ID", "assetID", deposit.AssetId)
continue
}

amount := protoU128ToBigInt(deposit.Amount)
address := common.HexToAddress(deposit.DestinationChainAddress)
txdata := types.DepositTx{
From: address,
Value: protoU128ToBigInt(deposit.Amount),
Value: bac.ScaledDepositAmount(amount),
Gas: 0,
}

Expand Down Expand Up @@ -260,7 +297,7 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
Parent: prevHeadHash,
Timestamp: uint64(req.GetTimestamp().GetSeconds()),
Random: common.Hash{},
FeeRecipient: common.Address{},
FeeRecipient: s.nextFeeRecipient,
}
payload, err := s.eth.Miner().BuildPayload(payloadAttributes)
if err != nil {
Expand Down Expand Up @@ -293,6 +330,10 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *
},
}

if next, ok := s.bc.Config().AstriaFeeCollectors[res.Number+1]; ok {
s.nextFeeRecipient = next
}

log.Info("ExecuteBlock completed", "request", req, "response", res)
totalExecutedTxCount.Inc(int64(len(block.Transactions())))
executeBlockSuccessCount.Inc(1)
Expand Down
67 changes: 57 additions & 10 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,14 @@ type ChainConfig struct {
IsDevMode bool `json:"isDev,omitempty"`

// Astria Specific Configuration
AstriaOverrideGenesisExtraData bool `json:"astriaOverrideGenesisExtraData,omitempty"`
AstriaExtraDataOverride hexutil.Bytes `json:"astriaExtraDataOverride,omitempty"`
AstriaRollupName string `json:"astriaRollupName,omitempty"`
AstriaSequencerInitialHeight uint32 `json:"astriaSequencerInitialHeight"`
AstriaCelestiaInitialHeight uint32 `json:"astriaCelestiaInitialHeight"`
AstriaCelestiaHeightVariance uint32 `json:"astriaCelestiaHeightVariance,omitempty"`
AstriaBridgeAddresses []hexutil.Bytes `json:"astriaBridgeAddresses,omitempty"`
AstriaBridgeAllowedAssetDenom string `json:"astriaBridgeAllowedAssetDenom,omitempty"`
AstriaOverrideGenesisExtraData bool `json:"astriaOverrideGenesisExtraData,omitempty"`
AstriaExtraDataOverride hexutil.Bytes `json:"astriaExtraDataOverride,omitempty"`
AstriaRollupName string `json:"astriaRollupName"`
AstriaSequencerInitialHeight uint32 `json:"astriaSequencerInitialHeight"`
AstriaCelestiaInitialHeight uint32 `json:"astriaCelestiaInitialHeight"`
AstriaCelestiaHeightVariance uint32 `json:"astriaCelestiaHeightVariance,omitempty"`
AstriaBridgeAddressConfigs []AstriaBridgeAddressConfig `json:"astriaBridgeAddresses,omitempty"`
AstriaFeeCollectors map[uint32]common.Address `json:"astriaFeeCollectors"`
}

func (c *ChainConfig) AstriaExtraData() []byte {
Expand All @@ -395,8 +395,6 @@ func (c *ChainConfig) AstriaExtraData() []byte {
c.AstriaSequencerInitialHeight,
c.AstriaCelestiaInitialHeight,
c.AstriaCelestiaHeightVariance,
c.AstriaBridgeAddresses,
c.AstriaBridgeAllowedAssetDenom,
})
if uint64(len(extra)) > MaximumExtraDataSize {
log.Warn("Miner extra data exceed limit", "extra", hexutil.Bytes(extra), "limit", MaximumExtraDataSize)
Expand Down Expand Up @@ -977,3 +975,52 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules
IsVerkle: isMerge && c.IsVerkle(num, timestamp),
}
}

type AstriaBridgeAddressConfig struct {
BridgeAddress hexutil.Bytes `json:"bridgeAddress"`
StartHeight uint32 `json:"startHeight"`
AssetDenom string `json:"assetDenom"`
AssetPrecision uint16 `json:"assetPrecision"`
Erc20Asset *AstriaErc20AssetConfig `json:"erc20Asset,omitempty"`
}

type AstriaErc20AssetConfig struct {
Erc20Address common.Address `json:"erc20Address"`
ContractPrecision uint16 `json:"contractPrecision"`
}

func (abc *AstriaBridgeAddressConfig) Validate() error {
if len(abc.BridgeAddress) != 20 {
return fmt.Errorf("bridge address must be 20 bytes")
}
if abc.StartHeight == 0 {
return fmt.Errorf("start height must be greater than 0")
}
if abc.AssetDenom == "" {
return fmt.Errorf("asset denom must be set")
}
if abc.Erc20Asset == nil && abc.AssetPrecision > 18 {
return fmt.Errorf("asset precision of native asset must be less than or equal to 18")
}
if abc.Erc20Asset != nil && abc.AssetPrecision > abc.Erc20Asset.ContractPrecision {
return fmt.Errorf("asset precision must be less than or equal to contract precision")
}
// TODO: support erc20 bridged assets
if abc.Erc20Asset != nil {
return fmt.Errorf("cannot currently process erc20 bridged assets")
}

return nil
}

func (abc *AstriaBridgeAddressConfig) ScaledDepositAmount(deposit *big.Int) *big.Int {
var exponent uint16
if abc.Erc20Asset != nil {
exponent = abc.Erc20Asset.ContractPrecision - abc.AssetPrecision
} else {
exponent = 18 - abc.AssetPrecision
}
multiplier := new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(exponent)), nil)

return new(big.Int).Mul(deposit, multiplier)
}

0 comments on commit 8a2d76b

Please sign in to comment.