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

Add kv context to MEVM execution #198

Merged
merged 1 commit into from
Feb 19, 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
2 changes: 1 addition & 1 deletion core/types/suave_structs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion core/vm/contracts_suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
/* General utility precompiles */

func (b *suaveRuntime) confidentialInputs() ([]byte, error) {
return b.suaveContext.ConfidentialInputs, nil
return b.contextGet("confidentialInputs")
}

/* Confidential store precompiles */
Expand Down Expand Up @@ -270,3 +270,11 @@ func (s *suaveRuntime) simulateTransaction(session string, txnBytes []byte) (typ
}
return *result, nil
}

func (s *suaveRuntime) contextGet(key string) ([]byte, error) {
val, ok := s.suaveContext.Context[key]
if !ok {
return nil, fmt.Errorf("value not found")
}
return val, nil
}
47 changes: 45 additions & 2 deletions core/vm/contracts_suave_runtime_adapter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions core/vm/contracts_suave_runtime_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ func (m *mockRuntime) privateKeyGen() (string, error) {
return "", nil
}

func (m *mockRuntime) contextGet(key string) ([]byte, error) {
return nil, nil
}

func TestRuntimeAdapter(t *testing.T) {
adapter := &SuaveRuntimeAdapter{
impl: &mockRuntime{},
Expand Down
12 changes: 6 additions & 6 deletions core/vm/suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ type ConfidentialStore interface {

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

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

return &SuaveContext{
Backend: evm.SuaveContext.Backend,
ConfidentialInputs: evm.SuaveContext.ConfidentialInputs,
CallerStack: append(evm.SuaveContext.CallerStack, &caller),
Backend: evm.SuaveContext.Backend,
Context: evm.SuaveContext.Context,
Copy link
Member

Choose a reason for hiding this comment

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

SuaveContext.Context feels a bit verbose

CallerStack: append(evm.SuaveContext.CallerStack, &caller),
}
}

Expand Down
7 changes: 5 additions & 2 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,11 @@ 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{
ConfidentialInputs: ccr.ConfidentialInputs,
CallerStack: []*common.Address{},
Context: map[string][]byte{
"confidentialInputs": ccr.ConfidentialInputs,
"kettleAddress": ccr.KettleAddress.Bytes(),
},
CallerStack: []*common.Address{},
Backend: &vm.SuaveExecutionBackend{
EthBundleSigningKey: b.suaveEthBundleSigningKey,
EthBlockSigningKey: b.suaveEthBlockSigningKey,
Expand Down
Loading
Loading