From a0afadb1e98d02419544956d3af6961d0a29291b Mon Sep 17 00:00:00 2001 From: deelawn Date: Mon, 4 Dec 2023 15:11:54 +0000 Subject: [PATCH] fix: upgrade apd lib to version without bug (#1399) Addresses #1152 After debugging for a bit it became apparent the sign was being dropped during the operation in the `apd` module. Upgrading to the latest version fixes this.
Contributors' checklist... - [x] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
--- contribs/gnokeykc/go.mod | 2 +- contribs/gnokeykc/go.sum | 4 ++-- gnovm/pkg/gnolang/op_binary.go | 2 +- gnovm/pkg/gnolang/op_eval.go | 5 ++--- gnovm/pkg/gnolang/op_inc_dec.go | 2 +- gnovm/pkg/gnolang/op_unary.go | 2 +- gnovm/pkg/gnolang/values.go | 2 +- gnovm/pkg/gnolang/values_conversions.go | 4 ++-- gnovm/pkg/gnolang/values_conversions_test.go | 2 +- gnovm/tests/files/math4.gno | 19 +++++++++++++++++++ go.mod | 3 +-- go.sum | 5 ++--- misc/loop/go.mod | 2 +- misc/loop/go.sum | 4 ++-- 14 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 gnovm/tests/files/math4.gno diff --git a/contribs/gnokeykc/go.mod b/contribs/gnokeykc/go.mod index 4f832dc3359..22f07943f39 100644 --- a/contribs/gnokeykc/go.mod +++ b/contribs/gnokeykc/go.mod @@ -15,7 +15,7 @@ require ( github.com/btcsuite/btcd/btcutil v1.1.3 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.1.1 // indirect - github.com/cockroachdb/apd v1.1.0 // indirect + github.com/cockroachdb/apd/v3 v3.2.1 // indirect github.com/danieljoos/wincred v1.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect diff --git a/contribs/gnokeykc/go.sum b/contribs/gnokeykc/go.sum index 21b2d9a6f9b..cc1f4dfed88 100644 --- a/contribs/gnokeykc/go.sum +++ b/contribs/gnokeykc/go.sum @@ -35,8 +35,8 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= -github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= +github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg= +github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= diff --git a/gnovm/pkg/gnolang/op_binary.go b/gnovm/pkg/gnolang/op_binary.go index ddab8302d2d..9162a710d7d 100644 --- a/gnovm/pkg/gnolang/op_binary.go +++ b/gnovm/pkg/gnolang/op_binary.go @@ -4,7 +4,7 @@ import ( "fmt" "math/big" - "github.com/cockroachdb/apd" + "github.com/cockroachdb/apd/v3" ) // ---------------------------------------- diff --git a/gnovm/pkg/gnolang/op_eval.go b/gnovm/pkg/gnolang/op_eval.go index 83dd3737b6b..5367c0403bc 100644 --- a/gnovm/pkg/gnolang/op_eval.go +++ b/gnovm/pkg/gnolang/op_eval.go @@ -9,7 +9,7 @@ import ( "strconv" "strings" - "github.com/cockroachdb/apd" + "github.com/cockroachdb/apd/v3" ) func (m *Machine) doOpEval() { @@ -160,8 +160,7 @@ func (m *Machine) doOpEval() { panic(fmt.Sprintf("error computing exponent: %v", err)) } // Step 3 make Decimal from mantissa and exp. - var dValue *big.Int - dValue = new(big.Int) + dValue := new(apd.BigInt) _, ok := dValue.SetString(hexString, 16) if !ok { panic(fmt.Sprintf("can't convert %s to decimal", value)) diff --git a/gnovm/pkg/gnolang/op_inc_dec.go b/gnovm/pkg/gnolang/op_inc_dec.go index 70886497d5e..84c39716eec 100644 --- a/gnovm/pkg/gnolang/op_inc_dec.go +++ b/gnovm/pkg/gnolang/op_inc_dec.go @@ -4,7 +4,7 @@ import ( "fmt" "math/big" - "github.com/cockroachdb/apd" + "github.com/cockroachdb/apd/v3" ) func (m *Machine) doOpInc() { diff --git a/gnovm/pkg/gnolang/op_unary.go b/gnovm/pkg/gnolang/op_unary.go index 331bea63ff9..9c330c7f8f1 100644 --- a/gnovm/pkg/gnolang/op_unary.go +++ b/gnovm/pkg/gnolang/op_unary.go @@ -4,7 +4,7 @@ import ( "fmt" "math/big" - "github.com/cockroachdb/apd" + "github.com/cockroachdb/apd/v3" ) func (m *Machine) doOpUpos() { diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 3bdd3332e08..2b3221f8921 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -10,7 +10,7 @@ import ( "strings" "unsafe" - "github.com/cockroachdb/apd" + "github.com/cockroachdb/apd/v3" "github.com/gnolang/gno/tm2/pkg/crypto" ) diff --git a/gnovm/pkg/gnolang/values_conversions.go b/gnovm/pkg/gnolang/values_conversions.go index cc7c0de9f09..e2000defdde 100644 --- a/gnovm/pkg/gnolang/values_conversions.go +++ b/gnovm/pkg/gnolang/values_conversions.go @@ -7,7 +7,7 @@ import ( "reflect" "strconv" - "github.com/cockroachdb/apd" + "github.com/cockroachdb/apd/v3" ) // t cannot be nil or untyped or DataByteType. @@ -1113,7 +1113,7 @@ func ConvertUntypedBigintTo(dst *TypedValue, bv BigintValue, t Type) { return // done case BigdecKind: dst.T = t - dst.V = BigdecValue{V: apd.NewWithBigInt(bi, 0)} + dst.V = BigdecValue{V: apd.NewWithBigInt(new(apd.BigInt).SetMathBigInt(bi), 0)} return // done default: panic(fmt.Sprintf( diff --git a/gnovm/pkg/gnolang/values_conversions_test.go b/gnovm/pkg/gnolang/values_conversions_test.go index e92496c1ac2..5436347733f 100644 --- a/gnovm/pkg/gnolang/values_conversions_test.go +++ b/gnovm/pkg/gnolang/values_conversions_test.go @@ -4,7 +4,7 @@ import ( "math" "testing" - "github.com/cockroachdb/apd" + "github.com/cockroachdb/apd/v3" "github.com/stretchr/testify/require" ) diff --git a/gnovm/tests/files/math4.gno b/gnovm/tests/files/math4.gno new file mode 100644 index 00000000000..83bfb44f7b0 --- /dev/null +++ b/gnovm/tests/files/math4.gno @@ -0,0 +1,19 @@ +package main + +func main() { + println(-3.0 * 1.0 / 2.0) // -1.5 + println(-3.0 * 1.0 / 2) // -1.5 + println(-3.0 * 1 / 2.0) // -1.5 + + println(-3 * 1.0 / 2.0) // 1.5 + println(-3 * 1.0 / 2) // 1.5 + println(-3 * 1 / 2.0) // 1.5 +} + +// Output: +// -1.5 +// -1.5 +// -1.5 +// -1.5 +// -1.5 +// -1.5 diff --git a/go.mod b/go.mod index f4317389c49..599396eee99 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/btcsuite/btcd/btcutil v1.1.3 - github.com/cockroachdb/apd v1.1.0 + github.com/cockroachdb/apd/v3 v3.2.1 github.com/davecgh/go-spew v1.1.1 github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 github.com/dgraph-io/badger/v3 v3.2103.4 @@ -60,7 +60,6 @@ require ( github.com/gorilla/sessions v1.2.1 // indirect github.com/klauspost/compress v1.12.3 // indirect github.com/kr/text v0.2.0 // indirect - github.com/lib/pq v1.10.7 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/nxadm/tail v1.4.11 // indirect github.com/pkg/errors v0.9.1 // indirect diff --git a/go.sum b/go.sum index 8569f1e443b..4a4dbed28d6 100644 --- a/go.sum +++ b/go.sum @@ -33,8 +33,8 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= -github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= +github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg= +github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -144,7 +144,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= -github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= github.com/linxGnu/grocksdb v1.8.5 h1:Okfk5B1h0ikCYdDM7Tc5yJUS8LTwAmMBq5IPWTmOLPs= diff --git a/misc/loop/go.mod b/misc/loop/go.mod index 10d2acd62bd..35baa515932 100644 --- a/misc/loop/go.mod +++ b/misc/loop/go.mod @@ -12,7 +12,7 @@ require ( github.com/btcsuite/btcd/btcutil v1.1.3 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.1.1 // indirect - github.com/cockroachdb/apd v1.1.0 // indirect + github.com/cockroachdb/apd/v3 v3.2.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/dgraph-io/badger/v3 v3.2103.4 // indirect diff --git a/misc/loop/go.sum b/misc/loop/go.sum index 846ee1340ed..d16d9f63ce9 100644 --- a/misc/loop/go.sum +++ b/misc/loop/go.sum @@ -33,8 +33,8 @@ github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghf github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= -github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= +github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg= +github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=