Skip to content

Commit

Permalink
take in bridge addresses and allowed asset ids in ValidateAndUnmarsha…
Browse files Browse the repository at this point in the history
…lSequencerTx
  • Loading branch information
bharath-123 committed May 28, 2024
1 parent ad553f4 commit 641cc3c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion grpc/execution/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *

txsToProcess := types.Transactions{}
for _, tx := range req.Transactions {
unmarshalledTx, err := s.ValidateAndUnmarshalSequencerTx(tx)
unmarshalledTx, err := ValidateAndUnmarshalSequencerTx(tx, s.bridgeAddresses, s.bridgeAllowedAssetIDs)
if err != nil {
log.Error("failed to validate sequencer tx, ignoring", "tx", tx, "err", err)
continue
Expand Down
7 changes: 4 additions & 3 deletions grpc/execution/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
)

// if sequencer tx is valid, then a unmarshalled ethereum transaction is returned. if not valid, nil is returned
func (s *ExecutionServiceServerV1Alpha2) ValidateAndUnmarshalSequencerTx(tx *sequencerblockv1alpha1.RollupData) (*types.Transaction, error) {
func ValidateAndUnmarshalSequencerTx(tx *sequencerblockv1alpha1.RollupData, bridgeAddresses map[string]*params.AstriaBridgeAddressConfig, bridgeAllowedAssetIDs map[[32]byte]struct{}) (*types.Transaction, error) {
if deposit := tx.GetDeposit(); deposit != nil {
bridgeAddress := string(deposit.BridgeAddress.GetInner())
bac, ok := s.bridgeAddresses[bridgeAddress]
bac, ok := bridgeAddresses[bridgeAddress]
if !ok {
log.Debug("ignoring deposit tx from unknown bridge", "bridgeAddress", bridgeAddress)
return nil, fmt.Errorf("unknown bridge address: %s", bridgeAddress)
Expand All @@ -25,7 +26,7 @@ func (s *ExecutionServiceServerV1Alpha2) ValidateAndUnmarshalSequencerTx(tx *seq
}
assetID := [32]byte{}
copy(assetID[:], deposit.AssetId[:32])
if _, ok := s.bridgeAllowedAssetIDs[assetID]; !ok {
if _, ok := bridgeAllowedAssetIDs[assetID]; !ok {
log.Debug("ignoring deposit tx with disallowed asset ID", "assetID", deposit.AssetId)
return nil, fmt.Errorf("disallowed asset ID: %x", deposit.AssetId)
}
Expand Down
2 changes: 1 addition & 1 deletion grpc/execution/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestSequenceTxValidation(t *testing.T) {

for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
_, err := serviceV1Alpha1.ValidateAndUnmarshalSequencerTx(test.sequencerTx)
_, err := ValidateAndUnmarshalSequencerTx(test.sequencerTx, serviceV1Alpha1.bridgeAddresses, serviceV1Alpha1.bridgeAllowedAssetIDs)
if test.wantErr != "" && err == nil {
t.Errorf("expected error, got nil")
}
Expand Down

0 comments on commit 641cc3c

Please sign in to comment.