Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 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.22.4]
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.22.4
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.22.4
- 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.59.1

# 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.22

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.4.5-0.20250211131210-ca58313a13f8
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.20250218090407-be6ac75b0078
github.com/multiversx/mx-chain-crypto-go v1.2.13-0.20250218094154-30a04d14140c
github.com/multiversx/mx-chain-logger-go v1.0.16-0.20250218093657-40fd50dfe8b4
github.com/multiversx/mx-chain-scenario-go v1.4.5-0.20250218100718-cd4655f8d966
github.com/multiversx/mx-chain-storage-go v1.0.20-0.20250218095523-d428172b455e
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20250218095642-cb5b68f47b49
github.com/multiversx/mx-components-big-int v1.0.1-0.20240617091634-bd0f0556c4e2
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.4.5-0.20250211131210-ca58313a13f8 h1:70mdcqvonAsPdN00tU1r92+dGsgsPH8oA8r1PGIwTxI=
github.com/multiversx/mx-chain-scenario-go v1.4.5-0.20250211131210-ca58313a13f8/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.20250218090407-be6ac75b0078 h1:Sn8Pz5VNCPRsfnFlOCHxSTYdSt8uTKHa1R6y5GS0Xj0=
github.com/multiversx/mx-chain-core-go v1.2.25-0.20250218090407-be6ac75b0078/go.mod h1:80c219T0k3sqeF44m/VQ6NcOlqMA2oH99lR1nNHhD34=
github.com/multiversx/mx-chain-crypto-go v1.2.13-0.20250218094154-30a04d14140c h1:P6gmBHejOodCGLCGwBifMW3H/LmH0I0rFpxwyFFe1xo=
github.com/multiversx/mx-chain-crypto-go v1.2.13-0.20250218094154-30a04d14140c/go.mod h1:hZnF/2fLbauTWT+Z7GK/kja0nHJ39rTw4bjZnrtBoCE=
github.com/multiversx/mx-chain-logger-go v1.0.16-0.20250218093657-40fd50dfe8b4 h1:8ri/niCyxZqzXKp9HogpMQkIY2OjUIKnCCkE8KPH/u4=
github.com/multiversx/mx-chain-logger-go v1.0.16-0.20250218093657-40fd50dfe8b4/go.mod h1:dy8RskrUt6XbPxJjrbvqttYyukKS5LoKYjMkAzGT7GQ=
github.com/multiversx/mx-chain-scenario-go v1.4.5-0.20250218100718-cd4655f8d966 h1:wVfko10BdYDrOQR6SJ1fr9jwN4GeoUvy8D8H+V/2Aic=
github.com/multiversx/mx-chain-scenario-go v1.4.5-0.20250218100718-cd4655f8d966/go.mod h1:gFKLVY9N8HUaRjQfD5nnjzcI3qR+TVthNH2/fnnsUkw=
github.com/multiversx/mx-chain-storage-go v1.0.20-0.20250218095523-d428172b455e h1:1BnFUN/hOpLV7FHtcJaNUnRUh95Sx+BArvRjLjpH/mw=
github.com/multiversx/mx-chain-storage-go v1.0.20-0.20250218095523-d428172b455e/go.mod h1:irkoNWALpWqoT8Laj9hZ7wHDjfIQoiGU/SrXKokc5dg=
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20250218095642-cb5b68f47b49 h1:B+5rPSfOcP/OwG1HUaLoPrObCUUHewTZc2Nbc1zDMbk=
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20250218095642-cb5b68f47b49/go.mod h1:wnTEI9ObQAwZdzT7SK8PZXQqmB7rRbHIMIFhVirHrfo=
github.com/multiversx/mx-components-big-int v1.0.1-0.20240617091634-bd0f0556c4e2 h1:rjU5k2i9y3gpkz7S4bYk2CE9vUDflU7yDu12vHDPZPY=
github.com/multiversx/mx-components-big-int v1.0.1-0.20240617091634-bd0f0556c4e2/go.mod h1:6OgyB2H8Tk3hiLFr5FpURvetxjEI2bgw6yrwd7iMVJA=
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