Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ jobs:
test:
strategy:
matrix:
go-version: [1.20.7]
go-version: [1.23.6]
os: [ubuntu-latest, macos-13]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Test (Linux)
if: runner.os == 'Linux'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
name: Build
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: 1.20.7
go-version: 1.23.6
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Get dependencies
run: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ jobs:
name: golangci linter
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: 1.20.7
- uses: actions/checkout@v3
go-version: 1.23.6
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.53.2
version: v1.64.5

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
module github.com/multiversx/mx-chain-vm-go

go 1.20
go 1.23

require (
github.com/awalterschulze/gographviz v2.0.3+incompatible
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/gogo/protobuf v1.3.2
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-core-go v1.2.22
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f
github.com/multiversx/mx-chain-logger-go v1.0.15
github.com/multiversx/mx-chain-scenario-go v1.5.1-0.20250218130524-4d5a15e117af
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241021074004-c2bdb78da54a
github.com/multiversx/mx-components-big-int v1.0.0
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250218161123-121084ae9840
github.com/multiversx/mx-chain-crypto-go v1.2.13-0.20250218161752-9482d9a22234
github.com/multiversx/mx-chain-logger-go v1.0.16-0.20250218161408-6a0c19d0da48
github.com/multiversx/mx-chain-scenario-go v1.5.1-0.20250218162624-877d8b9870a4
github.com/multiversx/mx-chain-storage-go v1.0.20-0.20250218162234-85e60acebb43
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20250218162215-88938774627c
github.com/multiversx/mx-components-big-int v1.0.1-0.20250218162530-b4e4d7442408
github.com/pelletier/go-toml v1.9.3
github.com/stretchr/testify v1.8.1
github.com/urfave/cli/v2 v2.27.1
Expand Down
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiversx/mx-chain-core-go v1.2.22 h1:yDYrvoQOBbsDerEp7L3+de5AfMy3pTF333gWPpd+FNk=
github.com/multiversx/mx-chain-core-go v1.2.22/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f h1:jydjrmVFvSllBOTppveOAkLITpOYKk0kma5z0bfDImI=
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f/go.mod h1:9aSp//uBSvqFdzh4gvYISraoruhr1FCTXgPQalQ687k=
github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc=
github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ=
github.com/multiversx/mx-chain-scenario-go v1.5.1-0.20250218130524-4d5a15e117af h1:6ORdoM22EjKrzPXU14ddCpqmP++v9Pz3vGo+lNPv1ac=
github.com/multiversx/mx-chain-scenario-go v1.5.1-0.20250218130524-4d5a15e117af/go.mod h1:sLKkfFGXK8EtnjBKmPcTZ0pbVGPsnUVFKOc2kWhGdFU=
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf h1:L9K7Xzq5SZz6k55R7HrafiRcU+c8/PqozJxys65G4bI=
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf/go.mod h1:ptvW/8r6bam55mVpeVZbyvvvydYM0DQwcPOH0W4Xyx8=
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241021074004-c2bdb78da54a h1:+D5GR9SkHTkKU6fIMZLdSQHeIzbDzOT6fSJfKBG80+g=
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241021074004-c2bdb78da54a/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY=
github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqdhV1m/aJhaP1EMaiS8=
github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM=
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250218161123-121084ae9840 h1:rwIljKJpbNLWNBj/oMdcbCKU910JytOXJoBqDYnfres=
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250218161123-121084ae9840/go.mod h1:IO+vspNan+gT0WOHnJ95uvWygiziHZvfXpff6KnxV7g=
github.com/multiversx/mx-chain-crypto-go v1.2.13-0.20250218161752-9482d9a22234 h1:NNI7kYxzsq+4mTPSUJo0cK1+iPxjUX+gRJDaBRwEQ7M=
github.com/multiversx/mx-chain-crypto-go v1.2.13-0.20250218161752-9482d9a22234/go.mod h1:QZAw2bZcOxGQRgYACTrmP8pfTa3NyxENIL+00G6nM5E=
github.com/multiversx/mx-chain-logger-go v1.0.16-0.20250218161408-6a0c19d0da48 h1:Of8RfTBNqJMvfWrDEpAkCAmNjYciM/Hul+yECQMBSHY=
github.com/multiversx/mx-chain-logger-go v1.0.16-0.20250218161408-6a0c19d0da48/go.mod h1:PZMaAr6nhEWgOV04JKBwFNrws0gvHzHW0WaeqnBlGlc=
github.com/multiversx/mx-chain-scenario-go v1.5.1-0.20250218162624-877d8b9870a4 h1:Q/iRXtZ6HhPQ6mV5/KWzg9WeamM90JV/WNQj8uP93ls=
github.com/multiversx/mx-chain-scenario-go v1.5.1-0.20250218162624-877d8b9870a4/go.mod h1:9WV9g7ZOf+7ytXri7KRGInNbJSExUpcZ1BUKbWkJKps=
github.com/multiversx/mx-chain-storage-go v1.0.20-0.20250218162234-85e60acebb43 h1:gmd10vRDOK3QJ7njD/iafV/uaNXl/6QEZf+s+CH9k4c=
github.com/multiversx/mx-chain-storage-go v1.0.20-0.20250218162234-85e60acebb43/go.mod h1:tTVMcXx0UWdMymMv3N8b1D1P1XSQwfyGK6xwMlRoONo=
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20250218162215-88938774627c h1:4L3SY1so6MwfmfO7+MGOhGtDxhVW5PtW6JG48sZmHNE=
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20250218162215-88938774627c/go.mod h1:NGcFCdOnbpEdk042ixTgD6xavRFQ7ap0z3kBhTXKlDQ=
github.com/multiversx/mx-components-big-int v1.0.1-0.20250218162530-b4e4d7442408 h1:FbpVQJg14ry25DiBBZIvBoKiSrTHWkUSlYMOOW/iQJQ=
github.com/multiversx/mx-components-big-int v1.0.1-0.20250218162530-b4e4d7442408/go.mod h1:kcWw7hDe6cSz1wcBAqj/6sFH6ouSPsNeH9P7XlpZRcw=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"expect": {
"out": [],
"status": "10",
"message": "str:this big Float operation is not permitted while doing float.Add"
"message": "str:big float decode error"
}
},
{
Expand Down Expand Up @@ -72,7 +72,7 @@
"expect": {
"out": [],
"status": "10",
"message": "str:this big Float operation is not permitted while doing float.Sub"
"message": "str:big float decode error"
}
}
]
Expand Down
6 changes: 6 additions & 0 deletions testcommon/instanceSmartContractCallerTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ func (template *InstanceCallTestTemplate) WithWasmerSIGSEGVPassthrough(passthrou
return template
}

// WithEnableEpochsHandler provides the enable epochs handler to be used by the mock contract call test
func (template *InstanceCallTestTemplate) WithEnableEpochsHandler(handler vmhost.EnableEpochsHandler) *InstanceCallTestTemplate {
template.hostBuilder.WithEnableEpochsHandler(handler)
return template
}

// GetVMHost returns the inner VMHost
func (template *InstanceCallTestTemplate) GetVMHost() vmhost.VMHost {
return template.host
Expand Down
6 changes: 6 additions & 0 deletions testcommon/instanceSmartContractCreatorTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ func (template *InstanceCreatorTestTemplate) WithWasmerSIGSEGVPassthrough(passth
return template
}

// WithEnableEpochsHandler sets the enableEpochsHandler
func (template *InstanceCreatorTestTemplate) WithEnableEpochsHandler(enableEpochsHandler vmcommon.EnableEpochsHandler) *InstanceCreatorTestTemplate {
template.hostBuilder.WithEnableEpochsHandler(enableEpochsHandler)
return template
}

// WithAddress provides the address for a TestCreateTemplateConfig
func (template *InstanceCreatorTestTemplate) WithAddress(address []byte) *InstanceCreatorTestTemplate {
template.address = address
Expand Down
6 changes: 6 additions & 0 deletions testcommon/testHostBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ func (thb *TestHostBuilder) WithGasSchedule(gasSchedule config.GasScheduleMap) *
return thb
}

// WithEnableEpochsHandler sets an enable epochs handler for the VM to work with.
func (thb *TestHostBuilder) WithEnableEpochsHandler(handler vmcommon.EnableEpochsHandler) *TestHostBuilder {
thb.vmHostParameters.EnableEpochsHandler = handler
return thb
}

// Build initializes the VM host with all configured options.
func (thb *TestHostBuilder) Build() vmhost.VMHost {
thb.initializeHost()
Expand Down
5 changes: 3 additions & 2 deletions vmhost/contexts/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bytes"
"errors"
"fmt"
builtinMath "math"
"math/big"

"github.com/multiversx/mx-chain-core-go/core/check"
logger "github.com/multiversx/mx-chain-logger-go"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
"github.com/multiversx/mx-chain-vm-go/executor"
"github.com/multiversx/mx-chain-vm-go/vmhost"
builtinMath "math"
"math/big"
)

var logRuntime = logger.GetOrCreate("vm/runtime")
Expand Down
4 changes: 4 additions & 0 deletions vmhost/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ const (

// FixBackTransferOPCODE defines the flag that activates the fix for get back transfer opcode
FixBackTransferOPCODE core.EnableEpochFlag = "FixBackTransferOPCODEFlag"

// ValidationOnGobDecodeFlag defines the flag that allows the GobDecode validation added on go1.21
ValidationOnGobDecodeFlag core.EnableEpochFlag = "ValidationOnGobDecodeFlag"
// all new flags must be added to allFlags slice from hostCore/host
)
1 change: 1 addition & 0 deletions vmhost/hostCore/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var allFlags = []core.EnableEpochFlag{
vmhost.CryptoOpcodesV2Flag,
vmhost.MultiESDTNFTTransferAndExecuteByUserFlag,
vmhost.UseGasBoundedShouldFailExecutionFlag,
vmhost.ValidationOnGobDecodeFlag,
}

// vmHost implements HostContext interface.
Expand Down
37 changes: 32 additions & 5 deletions vmhost/vmhooks/manBufOps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vmhooks
import (
"bytes"
"math/big"
"strings"

"github.com/multiversx/mx-chain-vm-go/executor"
"github.com/multiversx/mx-chain-vm-go/math"
Expand Down Expand Up @@ -668,13 +669,19 @@ func (context *VMHooksImpl) MBufferToBigFloat(mBufferHandle, bigFloatHandle int3
bigFloat := new(big.Float)
err = bigFloat.GobDecode(managedBuffer)
if err != nil {
if enableEpochsHandler.IsFlagEnabled(vmhost.MaskInternalDependenciesErrorsFlag) {
err = vmhost.ErrBigFloatDecode
}
if !enableEpochsHandler.IsFlagEnabled(vmhost.ValidationOnGobDecodeFlag) &&
isGobDecodeValidationError(err) {

context.FailExecution(err)
return 1
} else {
if enableEpochsHandler.IsFlagEnabled(vmhost.MaskInternalDependenciesErrorsFlag) {
err = vmhost.ErrBigFloatDecode
}

context.FailExecution(err)
return 1
}
}

if bigFloat.IsInf() {
context.FailExecution(vmhost.ErrInfinityFloatOperation)
return 1
Expand All @@ -684,6 +691,26 @@ func (context *VMHooksImpl) MBufferToBigFloat(mBufferHandle, bigFloatHandle int3
return 0
}

func isGobDecodeValidationError(err error) bool {
if err == nil {
return false
}

validationErrors := []string{
"nonzero finite number with empty mantissa",
"msb not set in last word",
"zero precision finite number",
}

for _, validationError := range validationErrors {
if strings.Contains(err.Error(), validationError) {
return true
}
}

return false
}

// MBufferFromBigFloat VMHooks implementation.
// @autogenerate(VMHooks)
func (context *VMHooksImpl) MBufferFromBigFloat(mBufferHandle, bigFloatHandle int32) int32 {
Expand Down
5 changes: 5 additions & 0 deletions vmhost/vmhooks/vmHooksImpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func (context *VMHooksImpl) FailExecution(err error) {
FailExecution(context.host, err)
}

// GetEnableEpochsHandler returns the enable epochs handler
func (context *VMHooksImpl) GetEnableEpochsHandler() vmhost.EnableEpochsHandler {
return context.host.EnableEpochsHandler()
}

// FailExecution fails the execution with the provided error
func FailExecution(host vmhost.VMHost, err error) {
if err == nil {
Expand Down
Loading
Loading