Skip to content

Commit

Permalink
Added the limit of the maximum number of hashes that can be requested…
Browse files Browse the repository at this point in the history
… in a ListOffChainData call (#91)
  • Loading branch information
begmaroman authored Jun 20, 2024
1 parent 4c27e9a commit 0f850ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion services/datacom/datacom.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ func (d *Endpoints) SignSequence(signedSequence types.SignedSequence) (interface
if err != nil {
return "0x0", rpc.NewRPCError(rpc.DefaultErrorCode, "failed to verify sender")
}

if sender != d.sequencerTracker.GetAddr() {
return "0x0", rpc.NewRPCError(rpc.DefaultErrorCode, "unauthorized")
}

// Store off-chain data by hash (hash(L2Data): L2Data)
_, err = d.txMan.NewDbTxScope(d.db, func(ctx context.Context, dbTx db.Tx) (interface{}, rpc.Error) {
err := d.db.StoreOffChainData(ctx, signedSequence.Sequence.OffChainData(), dbTx)
Expand All @@ -55,11 +57,12 @@ func (d *Endpoints) SignSequence(signedSequence types.SignedSequence) (interface
if err != nil {
return "0x0", rpc.NewRPCError(rpc.DefaultErrorCode, err.Error())
}

// Sign
signedSequenceByMe, err := signedSequence.Sequence.Sign(d.privateKey)
if err != nil {
return "0x0", rpc.NewRPCError(rpc.DefaultErrorCode, fmt.Errorf("failed to sign. Error: %w", err).Error())
}
// Return signature

return signedSequenceByMe.Signature, nil
}
14 changes: 12 additions & 2 deletions services/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ import (
"github.com/ethereum/go-ethereum/common"
)

// APISYNC is the namespace of the sync service
const APISYNC = "sync"
const (
// APISYNC is the namespace of the sync service
APISYNC = "sync"

// maxListHashes is the maximum number of hashes that can be requested in a ListOffChainData call
maxListHashes = 100
)

// Endpoints contains implementations for the "zkevm" RPC endpoints
type Endpoints struct {
Expand Down Expand Up @@ -41,6 +46,11 @@ func (z *Endpoints) GetOffChainData(hash types.ArgHash) (interface{}, rpc.Error)

// ListOffChainData returns the list of images of the given hashes
func (z *Endpoints) ListOffChainData(hashes []types.ArgHash) (interface{}, rpc.Error) {
if len(hashes) > maxListHashes {
log.Errorf("too many hashes requested in ListOffChainData: %d", len(hashes))
return "0x0", rpc.NewRPCError(rpc.InvalidRequestErrorCode, "too many hashes requested")
}

keys := make([]common.Hash, len(hashes))
for i, hash := range hashes {
keys[i] = hash.Hash()
Expand Down

0 comments on commit 0f850ac

Please sign in to comment.