From a25ffda8cf036db8fcac40b629b08c58a34218a4 Mon Sep 17 00:00:00 2001 From: elizabeth Date: Tue, 2 Apr 2024 17:03:57 -0400 Subject: [PATCH] add bridge address and asset IDs to genesis and check during execution --- genesis.json | 4 +++- grpc/execution/server.go | 44 ++++++++++++++++++++++++++++++++++------ params/config.go | 16 +++++++++------ 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/genesis.json b/genesis.json index 37ad379c6296..4cde15934a39 100644 --- a/genesis.json +++ b/genesis.json @@ -19,7 +19,9 @@ "astriaOverrideGenesisExtraData": true, "astriaSequencerInitialHeight": 2, "astriaCelestiaInitialHeight": 2, - "astriaCelestiaHeightVariance": 10 + "astriaCelestiaHeightVariance": 10, + "astriaBridgeAddresses": [], + "astriaBridgeAllowedAssetDenom": "nria" }, "difficulty": "10000000", "gasLimit": "8000000", diff --git a/grpc/execution/server.go b/grpc/execution/server.go index d9aef68a9b5c..23608b08120b 100644 --- a/grpc/execution/server.go +++ b/grpc/execution/server.go @@ -5,6 +5,7 @@ package execution import ( + "bytes" "context" "crypto/sha256" "errors" @@ -39,11 +40,14 @@ type ExecutionServiceServerV1Alpha2 struct { eth *eth.Ethereum bc *core.BlockChain - commitementUpdateLock sync.Mutex // Lock for the forkChoiceUpdated method - blockExecutionLock sync.Mutex // Lock for the NewPayload method + commitmentUpdateLock sync.Mutex // Lock for the forkChoiceUpdated method + blockExecutionLock sync.Mutex // Lock for the NewPayload method genesisInfoCalled bool getCommitmentStateCalled bool + + bridgeAddresses map[string]struct{} + bridgeAllowedAssetID [32]byte } var ( @@ -87,13 +91,30 @@ func NewExecutionServiceServerV1Alpha2(eth *eth.Ethereum) (*ExecutionServiceServ return nil, errors.New("celestia height variance not set") } + if bc.Config().AstriaBridgeAddresses == nil { + log.Warn("bridge addresses not set") + } + + if bc.Config().AstriaBridgeAllowedAssetDenom == "" && bc.Config().AstriaBridgeAddresses != nil { + return nil, errors.New("bridge allowed asset denom not set") + } + + bridgeAddresses := make(map[string]struct{}) + for _, addr := range bc.Config().AstriaBridgeAddresses { + bridgeAddresses[string(addr)] = struct{}{} + } + + bridgeAllowedAssetID := sha256.Sum256([]byte(bc.Config().AstriaBridgeAllowedAssetDenom)) + if merger := eth.Merger(); !merger.PoSFinalized() { merger.FinalizePoS() } return &ExecutionServiceServerV1Alpha2{ - eth: eth, - bc: bc, + eth: eth, + bc: bc, + bridgeAddresses: bridgeAddresses, + bridgeAllowedAssetID: bridgeAllowedAssetID, }, nil } @@ -192,6 +213,17 @@ 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 { + log.Debug("ignoring deposit tx from unknown bridge", "bridgeAddress", bridgeAddress) + continue + } + + if !bytes.Equal(deposit.AssetId, s.bridgeAllowedAssetID[:]) { + log.Debug("ignoring deposit tx with disallowed asset ID", "assetID", deposit.AssetId) + continue + } + address := common.HexToAddress(deposit.DestinationChainAddress) txdata := types.DepositTx{ From: address, @@ -295,8 +327,8 @@ func (s *ExecutionServiceServerV1Alpha2) UpdateCommitmentState(ctx context.Conte commitmentUpdateStart := time.Now() defer commitmentStateUpdateTimer.UpdateSince(commitmentUpdateStart) - s.commitementUpdateLock.Lock() - defer s.commitementUpdateLock.Unlock() + s.commitmentUpdateLock.Lock() + defer s.commitmentUpdateLock.Unlock() if !s.syncMethodsCalled() { return nil, status.Error(codes.PermissionDenied, "Cannot update commitment state until GetGenesisInfo && GetCommitmentState methods are called") diff --git a/params/config.go b/params/config.go index 342d87f8be14..0c4bb52d4f33 100644 --- a/params/config.go +++ b/params/config.go @@ -337,12 +337,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"` + 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"` } func (c *ChainConfig) AstriaExtraData() []byte { @@ -356,6 +358,8 @@ 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)