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

update go to 1.22 #853

Open
wants to merge 10 commits into
base: rc/v1.7.next1
Choose a base branch
from
Open
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.22.4]
os: [ubuntu-latest, macos-latest]
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.21-0.20240508071047-fefea5737840
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240715100647-8ce0ec25ff1d
github.com/multiversx/mx-components-big-int v1.0.0
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240719103659-046d9829efc9
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240719104037-eb4789931fd8
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240719103913-f78291da6ec4
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240719110047-f00e99be0195
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240719104131-439b7008529f
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240719110000-e9227ef24076
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.21-0.20240508071047-fefea5737840 h1:2mCrTUmbbA+Xv4UifZY9xptrGjcJBcJ2wavSb4FwejU=
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k=
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df/go.mod h1:gtJYB4rR21KBSqJlazn+2z6f9gFSqQP3KvAgL7Qgxw4=
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 h1:g9t410dqjcb7UUptbVd/H6Ua12sEzWU4v7VplyNvRZ0=
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57/go.mod h1:cY6CIXpndW5g5PTPn4WzPwka/UBEf+mgw+PSY5pHGAU=
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 h1:hFEcbGBtXu8UyB9BMhmAIH2R8BtV/NOq/rsxespLCN8=
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00/go.mod h1:pnIIfWopbDMQ1EW5Ddc6KDMqv8Qtx+hxbH9rorHpCyo=
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f h1:yd/G8iPBGOEAwbaS8zndJpO6bQk7Tk72ZhmlqRasThI=
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f/go.mod h1:E6nfj9EQzGxWDGM3Dn6eZWRC3qFy1G8IqOsYsBOcgWw=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240715100647-8ce0ec25ff1d h1:GqwJaWDgWFuHx4AsUBMwpHWzY4afyTbWBk0nwYG6lsY=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240715100647-8ce0ec25ff1d/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo=
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.21-0.20240719103659-046d9829efc9 h1:ZTWHoQ01tChjuT8OLKVsw5sWvrm9Sd38l0Ad/ab0NJY=
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240719103659-046d9829efc9/go.mod h1:80c219T0k3sqeF44m/VQ6NcOlqMA2oH99lR1nNHhD34=
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240719104037-eb4789931fd8 h1:GIYtMeCC/LCG7i+jZJ6zR7uXyb6YSSlQqfppNs1A3L8=
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240719104037-eb4789931fd8/go.mod h1:hf7R/JrrifUmP4PU8e3fPj6atUwGGsuIoYcWOwSdZLU=
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240719103913-f78291da6ec4 h1:pYrnT0KQZloC2/mcagWZeMAVVVnNunzWDkR2qKqldDM=
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240719103913-f78291da6ec4/go.mod h1:LbhgSvQs5AsoAnerq4S9b8+5bHOJKhqejP5wv8H0D+Q=
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240719110047-f00e99be0195 h1:3GSA3Ze41Kuuzww1Z2bo2kS5Tj4BF28s1Sce+YxXQyI=
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240719110047-f00e99be0195/go.mod h1:GMLXCI5A6xdt5B8Rz3ELwQ/TJ1Tg5XyXHMrSOKY6i28=
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240719104131-439b7008529f h1:62H7nBUAg4yyJ5V+gAhT3cJE5vS8xgydHDUWLpVFJik=
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240719104131-439b7008529f/go.mod h1:GOwIJ00PINe0DizixjCXnYl6Ec1sm3q9Vh/u3qmtlMI=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240719110000-e9227ef24076 h1:Ato2Xx2xiL3mOfbnU1zvvOQpeHNFqaFX7RRlr0DU51s=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240719110000-e9227ef24076/go.mod h1:930Ymc6nTiloEW6hI0Kd5gpIZvyM7Qh97+DFDwQW4Sw=
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
18 changes: 12 additions & 6 deletions integrationTests/json/scenariosTestCommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/check"
logger "github.com/multiversx/mx-chain-logger-go"
scenexec "github.com/multiversx/mx-chain-scenario-go/scenario/executor"
Expand All @@ -18,6 +19,7 @@ import (
executorwrapper "github.com/multiversx/mx-chain-vm-go/executor/wrapper"
vmscenario "github.com/multiversx/mx-chain-vm-go/scenario"
"github.com/multiversx/mx-chain-vm-go/testcommon/testexecutor"
"github.com/multiversx/mx-chain-vm-go/vmhost"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -50,12 +52,16 @@ type ScenariosTestBuilder struct {
// ScenariosTest will create a new ScenariosTestBuilder instance
func ScenariosTest(t *testing.T) *ScenariosTestBuilder {
return &ScenariosTestBuilder{
t: t,
folder: "",
singleFile: "",
executorLogger: nil,
executorFactory: nil,
enableEpochsHandler: worldmock.EnableEpochsHandlerStubAllFlags(),
t: t,
folder: "",
singleFile: "",
executorLogger: nil,
executorFactory: nil,
enableEpochsHandler: &worldmock.EnableEpochsHandlerStub{
IsFlagEnabledCalled: func(flag core.EnableEpochFlag) bool {
return flag != vmhost.ValidationOnGobDecodeFlag // relevant for big float tests. TODO: remove this when completely migrate to go1.22
},
},
}
}

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/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
3 changes: 3 additions & 0 deletions vmhost/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ import "github.com/multiversx/mx-chain-core-go/core"
const (
// CryptoOpcodesV2Flag defines the flag that activates the new crypto APIs for RC1.7
CryptoOpcodesV2Flag core.EnableEpochFlag = "CryptoOpcodesV2Flag"
// 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 @@ -40,6 +40,7 @@ const internalVMErrors = "internalVMErrors"
// allFlags must have all flags used by mx-chain-vm-go in the current version
var allFlags = []core.EnableEpochFlag{
vmhost.CryptoOpcodesV2Flag,
vmhost.ValidationOnGobDecodeFlag,
}

// vmHost implements HostContext interface.
Expand Down
31 changes: 31 additions & 0 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 @@ -461,6 +462,16 @@ func (context *VMHooksImpl) MBufferToBigFloat(mBufferHandle, bigFloatHandle int3

bigFloat := new(big.Float)
err = bigFloat.GobDecode(managedBuffer)
// TODO: remove 466-L473 when completely migrate to go1.22
enableEpochsHandler := context.GetEnableEpochsHandler()
hasSpecificError := isGobDecodeValidationError(err)
isFlagEnabled := enableEpochsHandler.IsFlagEnabled(vmhost.ValidationOnGobDecodeFlag)
hasSpecificErrorBeforeFlag := hasSpecificError && !isFlagEnabled
if hasSpecificErrorBeforeFlag {
value.Set(bigFloat)
return 0
}

if context.WithFault(err, runtime.ManagedBufferAPIErrorShouldFailExecution()) {
return 1
}
Expand All @@ -473,6 +484,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 @@ -92,6 +92,11 @@ func (context *VMHooksImpl) GetStorageContext() vmhost.StorageContext {
return context.host.Storage()
}

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

// WithFault handles an error, taking into account whether it should completely
// fail the execution of a contract or not.
func (context *VMHooksImpl) WithFault(err error, failExecution bool) bool {
Expand Down
Loading
Loading