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

load evmc shared libs in factory #951

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ ct-coverage-evmzero:
test: test-go test-cpp test-rust

test-go: tosca-go
@go test ./... -count 1 --coverprofile=cover.out
@go test ./... -count 1 --coverprofile=cover.out --timeout 30m

test-cpp: tosca-cpp
@cd cpp/build ; \
Expand Down
28 changes: 15 additions & 13 deletions go/interpreter/evmone/evmone.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package evmone
import "C"

import (
"fmt"

"github.com/Fantom-foundation/Tosca/go/interpreter/evmc"
"github.com/Fantom-foundation/Tosca/go/tosca"
)
Expand All @@ -27,28 +25,32 @@ func init() {
// of the evmone project is added to the rpath of the resulting library.
// This way, the libevmone.so file can be found during runtime, even if
// the LD_LIBRARY_PATH is not set accordingly.
evmone, err := evmc.LoadEvmcInterpreter("libevmone.so")
if err != nil {
panic(fmt.Errorf("failed to load evmone library: %s", err))
}
// This instance remains in its basic configuration and is registered
// as the default "evmone" VM and as the "evmone-basic" tosca.
tosca.MustRegisterInterpreterFactory("evmone", func(any) (tosca.Interpreter, error) {
evmone, err := evmc.LoadEvmcInterpreter("libevmone.so")
if err != nil {
return nil, err
}
return &evmoneInstance{evmone}, nil
})
tosca.MustRegisterInterpreterFactory("evmone-basic", func(any) (tosca.Interpreter, error) {
evmone, err := evmc.LoadEvmcInterpreter("libevmone.so")
if err != nil {
return nil, err
}
return &evmoneInstance{evmone}, nil
})

// A second instance is configured to use the advanced execution mode.
evmone, err = evmc.LoadEvmcInterpreter("libevmone.so")
if err != nil {
panic(fmt.Errorf("failed to load evmone library: %s", err))
}
if err := evmone.SetOption("advanced", "on"); err != nil {
panic(fmt.Errorf("failed to configure evmone advanced mode: %v", err))
}
tosca.MustRegisterInterpreterFactory("evmone-advanced", func(any) (tosca.Interpreter, error) {
evmone, err := evmc.LoadEvmcInterpreter("libevmone.so")
if err != nil {
return nil, err
}
if err := evmone.SetOption("advanced", "on"); err != nil {
return nil, err
}
return &evmoneInstance{evmone}, nil
})
}
Expand Down
24 changes: 11 additions & 13 deletions go/interpreter/evmrs/evmrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package evmrs
import "C"

import (
"fmt"

"github.com/Fantom-foundation/Tosca/go/interpreter/evmc"
"github.com/Fantom-foundation/Tosca/go/tosca"
)
Expand All @@ -28,25 +26,25 @@ func init() {
// This way, the libevmrs.so file can be found during runtime, even if
// the LD_LIBRARY_PATH is not set accordingly.
{
evm, err := evmc.LoadEvmcInterpreter("libevmrs.so")
if err != nil {
panic(fmt.Errorf("failed to load evmrs library: %s", err))
}
// This instance remains in its basic configuration.
tosca.MustRegisterInterpreterFactory("evmrs", func(any) (tosca.Interpreter, error) {
evm, err := evmc.LoadEvmcInterpreter("libevmrs.so")
if err != nil {
return nil, err
}
return &evmrsInstance{evm}, nil
})
}

{
evm, err := evmc.LoadEvmcInterpreter("libevmrs.so")
if err != nil {
panic(fmt.Errorf("failed to load evmrs library: %s", err))
}
if err = evm.SetOption("logging", "true"); err != nil {
panic(fmt.Errorf("failed to configure EVM instance: %s", err))
}
tosca.MustRegisterInterpreterFactory("evmrs-logging", func(any) (tosca.Interpreter, error) {
evm, err := evmc.LoadEvmcInterpreter("libevmrs.so")
if err != nil {
return nil, err
}
if err = evm.SetOption("logging", "true"); err != nil {
return nil, err
}
return &evmrsInstance{evm}, nil
})
}
Expand Down
80 changes: 39 additions & 41 deletions go/interpreter/evmzero/evmzero.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ void evmzero_reset_profiler(void* vm);
import "C"

import (
"fmt"

"github.com/Fantom-foundation/Tosca/go/interpreter/evmc"
"github.com/Fantom-foundation/Tosca/go/tosca"
)
Expand All @@ -31,82 +29,82 @@ func init() {
// This way, the libevmzero.so file can be found during runtime, even if
// the LD_LIBRARY_PATH is not set accordingly.
{
evm, err := evmc.LoadEvmcInterpreter("libevmzero.so")
if err != nil {
panic(fmt.Errorf("failed to load evmzero library: %s", err))
}
// This instance remains in its basic configuration.
tosca.MustRegisterInterpreterFactory("evmzero", func(any) (tosca.Interpreter, error) {
evm, err := evmc.LoadEvmcInterpreter("libevmzero.so")
if err != nil {
return nil, err
}
return &evmzeroInstance{evm}, nil
})
}

// We create a second instance in which we enable logging.
{
evm, err := evmc.LoadEvmcInterpreter("libevmzero.so")
if err != nil {
panic(fmt.Errorf("failed to load evmzero library: %s", err))
}
if err = evm.SetOption("logging", "true"); err != nil {
panic(fmt.Errorf("failed to configure EVM instance: %s", err))
}
tosca.MustRegisterInterpreterFactory("evmzero-logging", func(any) (tosca.Interpreter, error) {
evm, err := evmc.LoadEvmcInterpreter("libevmzero.so")
if err != nil {
return nil, err
}
if err = evm.SetOption("logging", "true"); err != nil {
return nil, err
}
return &evmzeroInstance{evm}, nil
})
}

// A third instance without analysis cache.
{
evm, err := evmc.LoadEvmcInterpreter("libevmzero.so")
if err != nil {
panic(fmt.Errorf("failed to load evmzero library: %s", err))
}
if err = evm.SetOption("analysis_cache", "false"); err != nil {
panic(fmt.Errorf("failed to configure EVM instance: %s", err))
}
tosca.MustRegisterInterpreterFactory("evmzero-no-analysis-cache", func(any) (tosca.Interpreter, error) {
evm, err := evmc.LoadEvmcInterpreter("libevmzero.so")
if err != nil {
return nil, err
}
if err = evm.SetOption("analysis_cache", "false"); err != nil {
return nil, err
}
return &evmzeroInstance{evm}, nil
})
}

// Another instance without SHA3 cache.
{
evm, err := evmc.LoadEvmcInterpreter("libevmzero.so")
if err != nil {
panic(fmt.Errorf("failed to load evmzero library: %s", err))
}
if err = evm.SetOption("sha3_cache", "false"); err != nil {
panic(fmt.Errorf("failed to configure EVM instance: %s", err))
}
tosca.MustRegisterInterpreterFactory("evmzero-no-sha3-cache", func(any) (tosca.Interpreter, error) {
evm, err := evmc.LoadEvmcInterpreter("libevmzero.so")
if err != nil {
return nil, err
}
if err = evm.SetOption("sha3_cache", "false"); err != nil {
return nil, err
}
return &evmzeroInstance{evm}, nil
})
}

// Another instance in which we enable profiling.
{
evm, err := evmc.LoadEvmcInterpreter("libevmzero.so")
if err != nil {
panic(fmt.Errorf("failed to load evmzero library: %s", err))
}
if err = evm.SetOption("profiling", "true"); err != nil {
panic(fmt.Errorf("failed to configure EVM instance: %s", err))
}
tosca.MustRegisterInterpreterFactory("evmzero-profiling", func(any) (tosca.Interpreter, error) {
evm, err := evmc.LoadEvmcInterpreter("libevmzero.so")
if err != nil {
return nil, err
}
if err = evm.SetOption("profiling", "true"); err != nil {
return nil, err
}
return &evmzeroInstanceWithProfiler{&evmzeroInstance{evm}}, nil
})
}

// Another instance in which we enable profiling external.
{
evm, err := evmc.LoadEvmcInterpreter("libevmzero.so")
if err != nil {
panic(fmt.Errorf("failed to load evmzero library: %s", err))
}
if err = evm.SetOption("profiling_external", "true"); err != nil {
panic(fmt.Errorf("failed to configure EVM instance: %s", err))
}
tosca.MustRegisterInterpreterFactory("evmzero-profiling-external", func(any) (tosca.Interpreter, error) {
evm, err := evmc.LoadEvmcInterpreter("libevmzero.so")
if err != nil {
return nil, err
}
if err = evm.SetOption("profiling_external", "true"); err != nil {
return nil, err
}
return &evmzeroInstanceWithProfiler{&evmzeroInstance{evm}}, nil
})
}
Expand Down
Loading