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

Refactor the crypto services #2170

Merged
merged 4 commits into from
Dec 2, 2024
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
3 changes: 3 additions & 0 deletions go/common/enclave.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type EnclaveInit interface {

// EnclaveID - returns the enclave's ID
EnclaveID(context.Context) (EnclaveID, SystemError)

// RPCEncryptionKey - returns the key used
RPCEncryptionKey(context.Context) ([]byte, SystemError)
}

// EnclaveAdmin provides administrative functions for managing an enclave.
Expand Down
12 changes: 5 additions & 7 deletions go/common/gethencoding/geth_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ type gethEncodingServiceImpl struct {
storage storage.Storage
logger gethlog.Logger
cachingService *storage.CacheService
entropyService *crypto.EvmEntropyService
}

func NewGethEncodingService(storage storage.Storage, cachingService *storage.CacheService, logger gethlog.Logger) EncodingService {
func NewGethEncodingService(storage storage.Storage, cachingService *storage.CacheService, entropyService *crypto.EvmEntropyService, logger gethlog.Logger) EncodingService {
return &gethEncodingServiceImpl{
storage: storage,
logger: logger,
entropyService: entropyService,
cachingService: cachingService,
}
}
Expand Down Expand Up @@ -265,16 +267,12 @@ func (enc *gethEncodingServiceImpl) CreateEthHeaderForBatch(ctx context.Context,
// wrap in a caching layer
return enc.cachingService.ReadConvertedHeader(ctx, h.Hash(), func(a any) (*types.Header, error) {
// deterministically calculate the private randomness that will be exposed to the EVM
secret, err := enc.storage.FetchSecret(ctx)
if err != nil {
enc.logger.Crit("Could not fetch shared secret. Exiting.", log.ErrKey, err)
}
perBatchRandomness := crypto.CalculateRootBatchEntropy(secret[:], h.Number)
perBatchRandomness := enc.entropyService.BatchEntropy(h.Number)

// calculate the converted hash of the parent, for a correct converted chain
// default to the genesis
convertedParentHash := common.GethGenesisParentHash

var err error
if h.SequencerOrderNo.Uint64() > common.L2GenesisSeqNo {
convertedParentHash, err = enc.storage.FetchConvertedHash(ctx, h.ParentHash)
if err != nil {
Expand Down
Loading
Loading