Skip to content

Commit

Permalink
Remove ccr object from core/vm (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt authored Jan 22, 2024
1 parent 669b321 commit b386478
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 26 deletions.
4 changes: 0 additions & 4 deletions core/vm/contracts_suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ func (b *suaveRuntime) confidentialRetrieve(dataId types.DataId, key string) ([]
/* Data Record precompiles */

func (b *suaveRuntime) newDataRecord(decryptionCondition uint64, allowedPeekers []common.Address, allowedStores []common.Address, RecordType string) (types.DataRecord, error) {
if b.suaveContext.ConfidentialComputeRequestTx == nil {
panic("newRecord: source transaction not present")
}

record, err := b.suaveContext.Backend.ConfidentialStore.InitRecord(types.DataRecord{
Salt: suave.RandomDataRecordId(),
DecryptionCondition: decryptionCondition,
Expand Down
1 change: 0 additions & 1 deletion core/vm/contracts_suave_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func newTestBackend(t *testing.T) *suaveRuntime {
ConfidentialStore: confEngine.NewTransactionalStore(reqTx),
ConfidentialEthBackend: &mockSuaveBackend{},
},
ConfidentialComputeRequestTx: reqTx,
},
}
return b
Expand Down
15 changes: 7 additions & 8 deletions core/vm/suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ type ConfidentialStore interface {
Retrieve(record types.DataId, caller common.Address, key string) ([]byte, error)
FetchRecordByID(suave.DataId) (suave.DataRecord, error)
FetchRecordsByProtocolAndBlock(blockNumber uint64, namespace string) []suave.DataRecord
Finalize() error
}

type SuaveContext struct {
// TODO: MEVM access to Backend should be restricted to only the necessary functions!
Backend *SuaveExecutionBackend
ConfidentialComputeRequestTx *types.Transaction
ConfidentialInputs []byte
CallerStack []*common.Address
Backend *SuaveExecutionBackend
ConfidentialInputs []byte
CallerStack []*common.Address
}

type SuaveExecutionBackend struct {
Expand All @@ -46,10 +46,9 @@ func NewRuntimeSuaveContext(evm *EVM, caller common.Address) *SuaveContext {
}

return &SuaveContext{
Backend: evm.SuaveContext.Backend,
ConfidentialComputeRequestTx: evm.SuaveContext.ConfidentialComputeRequestTx,
ConfidentialInputs: evm.SuaveContext.ConfidentialInputs,
CallerStack: append(evm.SuaveContext.CallerStack, &caller),
Backend: evm.SuaveContext.Backend,
ConfidentialInputs: evm.SuaveContext.ConfidentialInputs,
CallerStack: append(evm.SuaveContext.CallerStack, &caller),
}
}

Expand Down
16 changes: 3 additions & 13 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,7 @@ func (b *EthAPIBackend) GetMEVM(ctx context.Context, msg *core.Message, state *s
context = core.NewEVMBlockContext(header, b.eth.BlockChain(), nil)
}

suaveCtxCopy := *suaveCtx
storeTransaction := b.suaveEngine.NewTransactionalStore(suaveCtx.ConfidentialComputeRequestTx)
suaveCtxCopy.Backend = &vm.SuaveExecutionBackend{
EthBundleSigningKey: suaveCtx.Backend.EthBundleSigningKey,
EthBlockSigningKey: suaveCtx.Backend.EthBlockSigningKey,
ExternalWhitelist: suaveCtx.Backend.ExternalWhitelist,
ConfidentialStore: storeTransaction,
ConfidentialEthBackend: b.suaveEthBackend,
}
return vm.NewConfidentialEVM(suaveCtxCopy, context, txContext, state, b.eth.blockchain.Config(), *vmConfig), storeTransaction.Finalize, state.Error
return vm.NewConfidentialEVM(*suaveCtx, context, txContext, state, b.eth.blockchain.Config(), *vmConfig), suaveCtx.Backend.ConfidentialStore.Finalize, state.Error
}

func (b *EthAPIBackend) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription {
Expand Down Expand Up @@ -445,9 +436,8 @@ func (b *EthAPIBackend) StartMining() error {
func (b *EthAPIBackend) SuaveContext(requestTx *types.Transaction, ccr *types.ConfidentialComputeRequest) vm.SuaveContext {
storeTransaction := b.suaveEngine.NewTransactionalStore(requestTx)
return vm.SuaveContext{
ConfidentialComputeRequestTx: requestTx,
ConfidentialInputs: ccr.ConfidentialInputs,
CallerStack: []*common.Address{},
ConfidentialInputs: ccr.ConfidentialInputs,
CallerStack: []*common.Address{},
Backend: &vm.SuaveExecutionBackend{
EthBundleSigningKey: b.suaveEthBundleSigningKey,
EthBlockSigningKey: b.suaveEthBlockSigningKey,
Expand Down
4 changes: 4 additions & 0 deletions suave/cstore/transactional_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func (s *TransactionalStore) Retrieve(dataId suave.DataId, caller common.Address

// InitRecord prepares a data record for storage.
func (s *TransactionalStore) InitRecord(rawRecord types.DataRecord) (types.DataRecord, error) {
if s.sourceTx == nil {
return types.DataRecord{}, errors.New("confidential store transaction: no source transaction")
}

record, err := s.engine.InitRecord(rawRecord, s.sourceTx)
if err != nil {
return types.DataRecord{}, err
Expand Down

0 comments on commit b386478

Please sign in to comment.