Skip to content

Commit

Permalink
Mock Signature Verificaiton (#2251)
Browse files Browse the repository at this point in the history
* add mock sig verification for in memory test
  • Loading branch information
badgersrus authored Jan 17, 2025
1 parent f3a950c commit 976559e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions go/enclave/components/rollup_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type rollupConsumerImpl struct {
logger gethlog.Logger

storage storage.Storage
sigValidator *SignatureValidator
sigValidator SequencerSignatureVerifier
}

func NewRollupConsumer(
Expand All @@ -36,7 +36,7 @@ func NewRollupConsumer(
rollupCompression *RollupCompression,
storage storage.Storage,
logger gethlog.Logger,
verifier *SignatureValidator,
verifier SequencerSignatureVerifier,
) RollupConsumer {
return &rollupConsumerImpl{
MgmtContractLib: mgmtContractLib,
Expand Down
11 changes: 5 additions & 6 deletions go/enclave/components/sigverifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import (
gethcommon "github.com/ethereum/go-ethereum/common"
)

// SequencerSignatureVerifier interface for signature validation
type SequencerSignatureVerifier interface {
CheckSequencerSignature(hash gethcommon.Hash, sig []byte) error
}

type SignatureValidator struct {
attestedKey *ecdsa.PublicKey
storage storage.Storage
}

func NewSignatureValidator(storage storage.Storage) (*SignatureValidator, error) {
// todo (#718) - sequencer identities should be retrieved from the L1 management contract
return &SignatureValidator{
storage: storage,
attestedKey: nil,
Expand All @@ -36,11 +40,6 @@ func (sigChecker *SignatureValidator) CheckSequencerSignature(hash gethcommon.Ha
return fmt.Errorf("could not fetch sequencer IDs: %w", err)
}

// todo no-op for in-mem test, we can add a mock version of this
if len(sequencerIDs) == 0 {
return nil
}

// loop through sequencer keys and exit early if one of them matches
for _, seqID := range sequencerIDs {
attestedEnclave, err := sigChecker.storage.GetEnclavePubKey(context.Background(), seqID)
Expand Down
12 changes: 10 additions & 2 deletions go/enclave/enclave_admin_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"sync"
"time"

"github.com/ten-protocol/go-ten/integration/ethereummock"

"github.com/ethereum/go-ethereum/params"
"github.com/ten-protocol/go-ten/go/ethadapter/mgmtcontractlib"

Expand Down Expand Up @@ -68,11 +70,10 @@ func NewEnclaveAdminAPI(config *enclaveconfig.EnclaveConfig, storage storage.Sto
}
}
sharedSecretProcessor := components.NewSharedSecretProcessor(mgmtContractLib, attestationProvider, enclaveKeyService.EnclaveID(), storage, sharedSecretService, logger)
sigVerifier, err := components.NewSignatureValidator(storage)
sigVerifier, err := getSignatureValidator(config.UseInMemoryDB, storage)
if err != nil {
logger.Crit("Could not initialise the signature validator", log.ErrKey, err)
}

dataCompressionService := compression.NewBrotliDataCompressionService()

rollupCompression := components.NewRollupCompression(registry, batchExecutor, daEncryptionService, dataCompressionService, storage, gethEncodingService, chainConfig, config, logger)
Expand Down Expand Up @@ -600,3 +601,10 @@ func exportCrossChainData(ctx context.Context, storage storage.Storage, fromSeqN
} // todo: check fromSeqNo
return bundle, nil
}

func getSignatureValidator(useInMemDB bool, storage storage.Storage) (components.SequencerSignatureVerifier, error) {
if useInMemDB {
return ethereummock.NewMockSignatureValidator(), nil
}
return components.NewSignatureValidator(storage)
}
4 changes: 2 additions & 2 deletions go/enclave/nodetype/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type validator struct {
chainConfig *params.ChainConfig

storage storage.Storage
sigValidator *components.SignatureValidator
sigValidator components.SequencerSignatureVerifier
mempool *components.TxPool

logger gethlog.Logger
Expand All @@ -39,7 +39,7 @@ func NewValidator(
registry components.BatchRegistry,
chainConfig *params.ChainConfig,
storage storage.Storage,
sigValidator *components.SignatureValidator,
sigValidator components.SequencerSignatureVerifier,
mempool *components.TxPool,
logger gethlog.Logger,
) Validator {
Expand Down
16 changes: 16 additions & 0 deletions integration/ethereummock/mock_sigverifier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ethereummock

import (
gethcommon "github.com/ethereum/go-ethereum/common"
)

type MockSignatureValidator struct{}

func NewMockSignatureValidator() *MockSignatureValidator {
return &MockSignatureValidator{}
}

// CheckSequencerSignature - NO-OP
func (sigChecker *MockSignatureValidator) CheckSequencerSignature(_ gethcommon.Hash, _ []byte) error {
return nil
}

0 comments on commit 976559e

Please sign in to comment.