Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock Signature Verificaiton #2251

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully we have some checks in place that would barf for this but if we're in proper, SGX, attesting mode we definitely shouldn't be able to set that flag to true. In prod we'll lock it down with the enclave.json

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
}
Loading