Repository navigation
Opcodes v2, bulk memory opcodes activation + metering, FFI hardening #989
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
22e7ab8
Add metering for bulk memory opcodes
andrei-marinica 5c2ec11
golangci-lint fixes
andrei-marinica ea6c85c
codecov ignores hook generator
andrei-marinica 1ce8ce0
doc fix
andrei-marinica edd05cc
opcode version always resets cache
andrei-marinica 90b9c9b
SetOpcodeConfig error handling
andrei-marinica 00e3015
wasmer2 bridge layout test
andrei-marinica a25253f
Merge branch 'master' into opcodes-v2
andrei-marinica 7070055
wasmer2 additional FFI reflection tests
andrei-marinica d1d0eab
SetOpcodeConfig thread lock
andrei-marinica b98e1de
fix after review
andrei-marinica 2c24537
OpcodeVersion in constructor fix
andrei-marinica 6fcb166
opcode v2 more tests
andrei-marinica cd61f0c
doc update
andrei-marinica 15ae749
ei gen - input rename & cleanup
andrei-marinica 9916513
opcode config nil checks
andrei-marinica 77d52db
bulk memory tests verify memory contents
andrei-marinica c339ff2
opcode v2: clear stale compiled code on host creation, assert bulk me…
andrei-marinica 47b2cc7
wasmer2 - destroy executor after failed config
andrei-marinica d356503
CI - cleanup after running jobs
andrei-marinica 41b593d
gitignore
andrei-marinica File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,3 +41,6 @@ test/contracts/**/wasm/target | |
| **/Cargo.lock | ||
| vmhost/**/__debug_bin | ||
| .gocache/ | ||
|
|
||
| # Temporary LLM artifacts | ||
| docs | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ ignore: | |
| - "**test/**" | ||
| - "**testcommon/**" | ||
| - "**testgen/**" | ||
| - "vmhost/vmhooks/generate/**" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package executor | ||
|
|
||
| // OpcodeVersion specifies which set of opcodes should be used by the VM. | ||
| // | ||
| // [OpcodeVersionV1] is the legacy opcode set that does not include support | ||
| // for bulk memory operations. [OpcodeVersionV2] extends it by adding bulk | ||
| // memory instructions, such as MemoryCopy and MemoryFill, while dropping | ||
| // these categories from the whitelist, since no contract built with the | ||
| // current SDK toolchain can emit any of them: | ||
| // | ||
| // - legacy exception handling: Catch, CatchAll, Delegate, Rethrow, Throw, Try | ||
| // - reference types: RefFunc, RefIsNull, RefNull, TypedSelect | ||
| type OpcodeVersion uint32 | ||
|
|
||
| const ( | ||
| // OpcodeVersionV1 is the legacy opcode set without bulk memory support. | ||
| // | ||
| // Use this for modules or environments that were compiled or designed | ||
| // before bulk memory operations were introduced, or when compatibility | ||
| // with older tooling is required. | ||
| OpcodeVersionV1 OpcodeVersion = iota | ||
|
|
||
| // OpcodeVersionV2 is the opcode set with bulk memory support. | ||
| // | ||
| // Use this for modules that rely on bulk memory operations like | ||
| // MemoryCopy and MemoryFill, or when targeting newer runtimes that | ||
| // support these instructions. | ||
| // | ||
| // Relative to OpcodeVersionV1, OpcodeVersionV2 also drops these | ||
| // categories from the whitelist, since no contract built with today's | ||
| // tooling can produce them: | ||
| // | ||
| // - legacy exception handling: Catch, CatchAll, Delegate, Rethrow, Throw, Try | ||
| // - reference types: RefFunc, RefIsNull, RefNull, TypedSelect | ||
| // | ||
| // Note: OpcodeVersionV2 does not add support for memory.init and data.drop. | ||
| OpcodeVersionV2 | ||
| ) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package executorwrapper | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/multiversx/mx-chain-vm-go/executor" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestWrapperExecutorFactory_CreateExecutor_MissingDependencies(t *testing.T) { | ||
| t.Run("nil wrapped factory", func(t *testing.T) { | ||
| factory := SimpleWrappedExecutorFactory(nil) | ||
|
|
||
| exec, err := factory.CreateExecutor(executor.ExecutorFactoryArgs{}) | ||
| require.ErrorIs(t, err, ErrNilWrappedExecutorFactory) | ||
| require.Nil(t, exec) | ||
| }) | ||
|
|
||
| t.Run("nil logger", func(t *testing.T) { | ||
| factory := NewWrappedExecutorFactory(nil, SimpleWrappedExecutorFactory(nil)) | ||
|
|
||
| exec, err := factory.CreateExecutor(executor.ExecutorFactoryArgs{}) | ||
| require.ErrorIs(t, err, ErrNilExecutorLogger) | ||
| require.Nil(t, exec) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # bulk-memory | ||
|
|
||
| Contract used to measure the gas cost of the bulk memory opcodes, `memory.copy` and `memory.fill`. | ||
|
|
||
| Every endpoint takes the number of bytes to copy/fill as argument 0. Since the rest of the | ||
| code path is identical no matter the argument, the gas difference between two calls is exactly | ||
| `(bytes1 - bytes2) * <opcode>PerByte`, which is what the tests in | ||
| `vmhost/hosttest/bulkMemoryGas_test.go` assert. | ||
|
|
||
| Built directly from WAT, without `wasm-opt`, so that the opcodes stay exactly as written: | ||
|
|
||
| ``` | ||
| ./build.sh | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Built directly from WAT, no wasm-opt, so that the opcodes stay exactly as written. | ||
|
|
||
| set -e | ||
|
|
||
| cd "$(dirname "$0")" | ||
| mkdir -p output | ||
| wat2wasm bulk-memory.wat -o output/bulk-memory.wasm |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.