Skip to content

Commit

Permalink
Refactor the crypto services (#2170)
Browse files Browse the repository at this point in the history
* refactor the crypto services and generate true random entropy for da encryption

* lint

* generate random rpc key

* address pr comments
  • Loading branch information
tudor-malene authored Dec 2, 2024
1 parent e9f734d commit f3ebdce
Show file tree
Hide file tree
Showing 42 changed files with 1,497 additions and 1,629 deletions.
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

0 comments on commit f3ebdce

Please sign in to comment.