diff --git a/config/config.go b/config/config.go index 8e2961c0..752bdef7 100644 --- a/config/config.go +++ b/config/config.go @@ -11,6 +11,7 @@ import ( "github.com/0xPolygonHermez/zkevm-node/jsonrpc" "github.com/0xPolygonHermez/zkevm-node/log" "github.com/ethereum/go-ethereum/accounts/keystore" + "github.com/ethereum/go-ethereum/common" "github.com/mitchellh/mapstructure" "github.com/spf13/viper" "github.com/urfave/cli/v2" @@ -28,6 +29,8 @@ type Config struct { Log log.Config RPC jsonrpc.Config L1 L1Config + + SignSequenceAddress common.Address `mapstructure:"SignSequenceAddress"` } // L1Config is a struct that defines L1 contract and service settings diff --git a/config/default.go b/config/default.go index eeb433f0..59f2d995 100644 --- a/config/default.go +++ b/config/default.go @@ -10,6 +10,7 @@ import ( // DefaultValues is the default configuration const DefaultValues = ` PrivateKey = {Path = "/pk/test-member.keystore", Password = "testonly"} +SignSequenceAddress = "" [L1] WsURL = "ws://127.0.0.1:8546" diff --git a/services/datacom/datacom.go b/services/datacom/datacom.go index 3fc69f7b..dcefafc7 100644 --- a/services/datacom/datacom.go +++ b/services/datacom/datacom.go @@ -8,6 +8,8 @@ import ( "github.com/0xPolygon/cdk-data-availability/synchronizer" "github.com/0xPolygonHermez/zkevm-node/jsonrpc" "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types" + "github.com/0xPolygonHermez/zkevm-node/log" + "github.com/ethereum/go-ethereum/common" "github.com/jackc/pgx/v4" ) @@ -20,6 +22,8 @@ type DataComEndpoints struct { txMan jsonrpc.DBTxManager privateKey *ecdsa.PrivateKey sequencerTracker *synchronizer.SequencerTracker + + signSequenceAddress common.Address } // NewDataComEndpoints returns DataComEndpoints @@ -39,12 +43,14 @@ func NewDataComEndpoints( func (d *DataComEndpoints) SignSequence(signedSequence sequence.SignedSequence) (interface{}, types.Error) { // Verify that the request comes from the sequencer sender, err := signedSequence.Signer() - if err != nil { + if err != nil || sender.Cmp(common.Address{}) == 0 { return "0x0", types.NewRPCError(types.DefaultErrorCode, "failed to verify sender") } - if sender != d.sequencerTracker.GetAddr() { + if sender != d.sequencerTracker.GetAddr() && sender != d.signSequenceAddress { return "0x0", types.NewRPCError(types.DefaultErrorCode, "unauthorized") } + log.Infof("SignSequence, signedSequence sender: %v, sequencerTracker:%v, signSequenceAddress:%s", sender.String(), d.sequencerTracker.GetAddr().String(), d.signSequenceAddress.String()) + // Store off-chain data by hash (hash(L2Data): L2Data) _, err = d.txMan.NewDbTxScope(d.db, func(ctx context.Context, dbTx pgx.Tx) (interface{}, types.Error) { err := d.db.StoreOffChainData(ctx, signedSequence.Sequence.OffChainData(), dbTx) diff --git a/test/config/test.da.toml b/test/config/test.da.toml index e1dd138e..be086ac2 100644 --- a/test/config/test.da.toml +++ b/test/config/test.da.toml @@ -1,4 +1,5 @@ PrivateKey = {Path = "/pk/test-member.keystore", Password = "testonly"} +SignSequenceAddress = "" [L1] WsURL = "ws://x1-mock-l1-network:8546"