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

u256 #118

Merged
merged 23 commits into from
Mar 8, 2024
Merged

u256 #118

merged 23 commits into from
Mar 8, 2024

Conversation

mconcat
Copy link
Contributor

@mconcat mconcat commented Dec 11, 2023

No description provided.

@r3v4s
Copy link
Member

r3v4s commented Dec 11, 2023

Data: &errors.errorString{s:"interface conversion: gnolang.Value is gnolang.RefValue, not *gnolang.ArrayValue"}
Msg Traces:
    0  /opt/build/gno.land/pkg/sdk/vm/keeper.go:473 - VM query eval panic: interface conversion: gnolang.Value is gnolang.RefValue, not *gnolang.ArrayValue
Machine:
    CheckTypes: false
	Op: [OpHalt OpExec OpBody OpDefine OpBody OpPopBlock OpIfCond OpEval OpDefine OpBody OpPopBlock OpBody OpReturn OpBody OpRangeIter OpPopBlock OpBody OpPopResults OpPrecall OpBody OpAssign OpPrecall]
	Values: (len: 13)
          #12 (ref(7056109f882894760efac556035fcc4093b62f76:20) gno.land/p/u256_v2.Int)
          #11 (7922816251 uint64)
          #10 (Mul64 func(x uint64,y uint64)(hi uint64,lo uint64))
          #9 (0 int)
          #8 (array[(0 uint64),(0 uint64),(0 uint64),(0 uint64)] gno.land/p/u256_v2.Int)
          #7 (<*gno.land/p/u256_v2.Int>.Mul(z *gno.land/p/u256_v2.Int,x *gno.land/p/u256_v2.Int,y *gno.land/p/u256_v2.Int)( *gno.land/p/u256_v2.Int) func(x *gno.land/p/u256_v2.Int,y *gno.land/p/u256_v2.Int)( *gno.land/p/u256_v2.Int))
          #6 (&0xc0066adfb8.(*gno.land/p/u256_v2.Int) *gno.land/p/u256_v2.Int)
          #5 (<*gno.land/p/u256_v2.Int>.Add(z *gno.land/p/u256_v2.Int,x *gno.land/p/u256_v2.Int,y *gno.land/p/u256_v2.Int)( *gno.land/p/u256_v2.Int) func(x *gno.land/p/u256_v2.Int,y *gno.land/p/u256_v2.Int)( *gno.land/p/u256_v2.Int))
          #4 (array[(nil *gno.land/p/u256_v2.Int),(&0xc008190810.(*gno.land/p/u256_v2.Int) *gno.land/p/u256_v2.Int),(&0xc0081912f0.(*gno.land/p/u256_v2.Int) *gno.land/p/u256_v2.Int),(&0xc0081917a0.(*gno.land/p/u256_v2.Int) *gno.land/p/u256_v2.Int),(&0xc008191c80.(*gno.land/p/u256_v2.Int) *gno.land/p/u256_v2.Int)] [5]*gno.land/p/u256_v2.Int)
          #3 (<*gno.land/p/u256_v2.Int>.fromDecimal(z *gno.land/p/u256_v2.Int,bs string)( .uverse.error) func(bs string)( .uverse.error))
          #2 (<*gno.land/p/u256_v2.Int>.SetFromDecimal(z *gno.land/p/u256_v2.Int,s string)(err .uverse.error) func(s string)(err .uverse.error))
          #1 (FromDecimal func(decimal string)( *gno.land/p/u256_v2.Int, .uverse.error))
          #0 (Hello func()())
	Exprs:
          #2 Mul64<VPBlock(3,43)>(*(x<VPBlock(1,1)>)[(const (0 int))], *(y<VPBlock(1,2)>)[(const (0 int))])
          #1 z<VPBlock(3,0)>.Add(z<VPBlock(3,0)>, base<VPBlock(1,0)>.Mul(base<VPBlock(1,0)>, mult<VPBlock(2,1)>))
          #0 (const-type bool)(err<VPBlock(1,0)> != (const (undefined)))
	Stmts:
          #9 bodyStmt[0/0/2]=carry<VPBlock(1,5)>, res1<VPBlock(1,6)> = umulHop<VPBlock(3,61)>(carry<VPBlock(1,5)>, *(x<VPBlock(1,1)>)[(const (1 int))], *(y<VPBlock(1,2)>)[(const (0 int))])*
          #8 bodyStmt[0/0/2]=(end)
          #7 bodyStmt[5/1/3]=if (const-type bool)(remaining<VPBlock(3,5)> > (const (19 int))) { bs<VPBlock(3,1)> = bs<VPBlock(3,1)>[(const (0 int)):remaining<VPBlock(3,5)> - (const (19 int))] }
          #6 bodyStmt[0/0/4]=return (const (undefined))*
          #5 bodyStmt[0/0/1]=(end)
          #4 bodyStmt[0/0/3]=if (const-type bool)((const (len func(x interface{})( int)))(s<VPBlock(2,1)>) == (const (len func(x interface{})( int)))((const ("115792089237316195423570985008687907853269984665640564039457584007913129639935" string)))) { if (const-type bool)(s<VPBlock(3,1)> > (const ("115792089237316195423570985008687907853269984665640564039457584007913129639935" string))) { return ErrBig256Range<VPBlock(5,107)> }; return z<VPBlock(2,0)>.fromDecimal(s<VPBlock(2,1)>) }
          #3 err<VPBlock(1,0)> := &(z<VPBlock(2,3)>).SetFromDecimal(decimal<VPBlock(2,0)>)
          #2 bodyStmt[0/0/2]=return &(z<VPBlock(1,3)>), (const (undefined))*
          #1 bodyStmt[0/0/7]=(const (println func(xs ...interface{})()))((const ("4444" string)))*
          #0 return
	Blocks:
          @(1) Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc008bec3c0,Source:func (z *(Int<VPBlock(2,0)>)) Mu...,Parent:0xc006abfa40)
            z: (&0xc0079a2cf0.(*gno.land/p/u256_v2.Int) *gno.land/p/u256_v2.Int)
            x: (&0xc0079a2cf0.(*gno.land/p/u256_v2.Int) *gno.land/p/u256_v2.Int)
            y: (&0xc008190810.(*gno.land/p/u256_v2.Int) *gno.land/p/u256_v2.Int)
            .res_0: (nil *gno.land/p/u256_v2.Int)
            res: (array[(0 uint64),(0 uint64),(0 uint64),(0 uint64)] gno.land/p/u256_v2.Int)
            carry: (0 uint64)
            res1: (0 uint64)
            res2: (0 uint64)
            res3: (0 uint64)
 (s vals) @(1) Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc009723c20,Source:func (z *(Int<VPBlock(2,0)>)) Mu...,Parent:0xc0046ec2e0)
            z: (nil *gno.land/p/u256_v2.Int)
            x: (nil *gno.land/p/u256_v2.Int)
            y: (nil *gno.land/p/u256_v2.Int)
            .res_0: (nil *gno.land/p/u256_v2.Int)
            res: (undefined)
            carry: (undefined)
            res1: (undefined)
            res2: (undefined)
            res3: (undefined)
 (s typs) @(1) [*gno.land/p/u256_v2.Int *gno.land/p/u256_v2.Int *gno.land/p/u256_v2.Int *gno.land/p/u256_v2.Int gno.land/p/u256_v2.Int uint64 uint64 uint64 uint64]
          @(2) Block(ID:7056109f882894760efac556035fcc4093b62f76:6,Addr:0xc006abfa40,Source:ref(gno.land/p/u256_v2/u256.gno:...,Parent:0xc006abef00)
            (RefNode names not shown)
 (s vals) @(2) Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc0046ec2e0,Source:file{ package u256; import error...,Parent:0xc0046ec5a0)
            errors: (package(errors errors) package{})
            strconv: (package(strconv strconv) package{})
 (s typs) @(2) [package{} package{}]
          @(3) gno.land/p/u256_v2
	Blocks (other):
          #8 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc002adfc20,Source:if (const-type bool)(i<VPBlock(2...,Parent:0xc007fc7e00)
 (static) #8 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc009c05020,Source:if (const-type bool)(i<VPBlock(2...,Parent:0xc009b3c620)
          #7 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc007fc7e00,Source:for i<VPBlock(1,0)>, mult<VPBloc...,Parent:0xc007fc74a0)
            i: (1 int)
            mult: (&0xc008190810.(*gno.land/p/u256_v2.Int) *gno.land/p/u256_v2.Int)
 (static) #7 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc009b3c620,Source:for i<VPBlock(1,0)>, mult<VPBloc...,Parent:0xc009b3f020)
            i: (0 int)
            mult: (nil *gno.land/p/u256_v2.Int)
          #6 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc007fc74a0,Source:func (z *(Int<VPBlock(2,0)>)) fr...,Parent:0xc006abfa40)
            z: (&0xc0066adfb8.(*gno.land/p/u256_v2.Int) *gno.land/p/u256_v2.Int)
            bs: ("7922816251" string)
            .res_0: (undefined)
            num: (7922816251 uint64)
            err: (undefined)
            remaining: (10 int)
 (static) #6 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc009b3f020,Source:func (z *(Int<VPBlock(2,0)>)) fr...,Parent:0xc0046ec2e0)
            z: (nil *gno.land/p/u256_v2.Int)
            bs: ( string)
            .res_0: (undefined)
            num: (undefined)
            err: (undefined)
            remaining: (0 int)
          #5 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc007fc6f00,Source:if (const-type bool)((const (len...,Parent:0xc007fc65a0)
 (static) #5 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc009b79820,Source:if (const-type bool)((const (len...,Parent:0xc009b3e820)
          #4 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc007fc65a0,Source:func (z *(Int<VPBlock(2,0)>)) Se...,Parent:0xc006abfa40)
            z: (&0xc0066adfb8.(*gno.land/p/u256_v2.Int) *gno.land/p/u256_v2.Int)
            s: ("79228162514264337593543950336" string)
            err: (undefined)
 (static) #4 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc009b3e820,Source:func (z *(Int<VPBlock(2,0)>)) Se...,Parent:0xc0046ec2e0)
            z: (nil *gno.land/p/u256_v2.Int)
            s: ( string)
            err: (undefined)
          #3 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc007fc63c0,Source:if err<VPBlock(1,0)> := &(z<VPBl...,Parent:0xc007fc61e0)
            err: (undefined)
 (static) #3 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc009ae1820,Source:if err<VPBlock(1,0)> := &(z<VPBl...,Parent:0xc009b3e420)
            err: (undefined)
          #2 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc007fc61e0,Source:func FromDecimal(decimal (const-...,Parent:0xc006abfa40)
            decimal: ("79228162514264337593543950336" string)
            .res_0: (nil *gno.land/p/u256_v2.Int)
            .res_1: (undefined)
            z: (array[(4264337593543950336 uint64),(0 uint64),(0 uint64),(0 uint64)] gno.land/p/u256_v2.Int)
 (static) #2 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc009b3e420,Source:func FromDecimal(decimal (const-...,Parent:0xc0046ec2e0)
            decimal: ( string)
            .res_0: (nil *gno.land/p/u256_v2.Int)
            .res_1: (undefined)
            z: (undefined)
          #1 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc006abfe00,Source:func Hello() { q96<VPBlock(1,0)>...,Parent:0xc006abf680)
            q96: ("79228162514264337593543950336" string)
            bigStr: ("833325865908927437441174649481942846" string)
            zeroStr: ("0" string)
            b96: (undefined)
            err: (undefined)
            bigNum: (undefined)
            zero: (undefined)
 (static) #1 Block(ID:0000000000000000000000000000000000000000:0,Addr:0xc0092da020,Source:func Hello() { q96<VPBlock(1,0)>...,Parent:0xc00503fba0)
            q96: ( string)
            bigStr: ( string)
            zeroStr: ( string)
            b96: (nil *gno.land/p/u256_v2.Int)
            err: (undefined)
            bigNum: (nil *gno.land/p/u256_v2.Int)
            zero: (nil *gno.land/p/u256_v2.Int)
	Frames:
          #5 [FRAME FUNC:Mul RECV:(&0xc0079a2cf0.(*gno.land/p/u256_v2.Int) *gno.land/p/u256_v2.Int) (2 args) 19/7/2/9/9 LASTPKG:gno.land/p/u256_v2 LASTRLM:Realm(nil)]
          #4 [FRAME LABEL:  14/4/1/7/7]
          #3 [FRAME FUNC:fromDecimal RECV:(&0xc0066adfb8.(*gno.land/p/u256_v2.Int) *gno.land/p/u256_v2.Int) (1 args) 13/3/1/6/6 LASTPKG:gno.land/p/u256_v2 LASTRLM:Realm(nil)]
          #2 [FRAME FUNC:SetFromDecimal RECV:(&0xc0066adfb8.(*gno.land/p/u256_v2.Int) *gno.land/p/u256_v2.Int) (1 args) 9/2/1/4/4 LASTPKG:gno.land/p/u256_v2 LASTRLM:Realm(nil)]
          #1 [FRAME FUNC:FromDecimal RECV:(undefined) (1 args) 4/1/0/2/2 LASTPKG:gno.land/p/u256_v2 LASTRLM:Realm(nil)]
          #0 [FRAME FUNC:Hello RECV:(undefined) (0 args) 1/0/0/0/1 LASTPKG:gno.land/p/u256_v2 LASTRLM:Realm(nil)]
	Realm:
	  
	Exceptions:
	  []
	  

Stack Trace:
    0  /opt/build/tm2/pkg/errors/errors.go:20
    1  /opt/build/gno.land/pkg/sdk/vm/keeper.go:473
    2  /usr/local/go/src/runtime/panic.go:914
    3  /usr/local/go/src/runtime/iface.go:263
    4  /usr/local/go/src/runtime/iface.go:273
    5  /opt/build/gnovm/pkg/gnolang/values.go:1906
    6  /opt/build/gnovm/pkg/gnolang/op_expressions.go:33
    7  /opt/build/gnovm/pkg/gnolang/machine.go:1179
    8  /opt/build/gnovm/pkg/gnolang/machine.go:636
    9  /opt/build/gno.land/pkg/sdk/vm/keeper.go:479
   10  /opt/build/gno.land/pkg/sdk/vm/handler.go:194
   11  /opt/build/gno.land/pkg/sdk/vm/handler.go:125
   12  /opt/build/tm2/pkg/sdk/baseapp.go:496
   13  /opt/build/tm2/pkg/sdk/baseapp.go:393
   14  /opt/build/tm2/pkg/bft/abci/client/local_client.go:180
   15  /opt/build/tm2/pkg/bft/proxy/app_conn.go:143
   16  /opt/build/tm2/pkg/bft/rpc/core/abci.go:59
   17  /usr/local/go/src/reflect/value.go:596
   18  /usr/local/go/src/reflect/value.go:380
   19  /opt/build/tm2/pkg/bft/rpc/lib/server/handlers.go:281
   20  /usr/local/go/src/net/http/server.go:2136
   21  /usr/local/go/src/net/http/server.go:2514
   22  /go/pkg/mod/github.com/rs/cors@v1.10.1/cors.go:281
   23  /usr/local/go/src/net/http/server.go:2136
   24  /opt/build/tm2/pkg/bft/rpc/lib/server/http_server.go:216
   25  /opt/build/tm2/pkg/bft/rpc/lib/server/http_server.go:189
   26  /usr/local/go/src/net/http/server.go:2136
   27  /usr/local/go/src/net/http/server.go:2938
   28  /usr/local/go/src/net/http/server.go:2009
   29  /usr/local/go/src/runtime/asm_amd64.s:1650
--= /Error =--

pool/bit_math.gno Outdated Show resolved Hide resolved
pool/bit_math.gno Outdated Show resolved Hide resolved
u256/u256.gno Show resolved Hide resolved
u256/u256.gno Show resolved Hide resolved
@mconcat mconcat marked this pull request as ready for review February 21, 2024 12:12
@dongwon8247 dongwon8247 marked this pull request as draft February 26, 2024 06:58
@kristovatlas
Copy link

Mind adding some commentary on the motivation for this PR?

@dongwon8247
Copy link
Member

dongwon8247 commented Feb 28, 2024

@kristovatlas Thank you for asking. Our initial aim was to utilize bigint for arbitrary precision, which is essential for DeFi applications. So initially, we worked on adding feat: native bigint using math/big.Int #764 to Gno and also to our own testnet to continue development. But after discussing for quite some time with the core team, the conclusion was that it's a bit early to adapt bigint as a new native key type so we need to try alternatives.

That's why we're switching bigint to uint256 (as a /p) for now so that we can deploy our contracts onto official Gno testnets (Portal Loop, testnetX) to follow up with the latest changes of master.

FYI - For complex calculations, we will need uint512, so we need to figure out a way like how Uniswap does this with uint256 * uint256 (link).

@kristovatlas
Copy link

Great, thank you.

@r3v4s
Copy link
Member

r3v4s commented Mar 7, 2024

@mconcat FYI, u256 + i256 ready in this pr

@r3v4s r3v4s marked this pull request as ready for review March 8, 2024 07:23
@r3v4s r3v4s requested review from notJoon and r3v4s March 8, 2024 07:23
@r3v4s r3v4s merged commit d35429d into main Mar 8, 2024
@r3v4s r3v4s deleted the mconcat/uint256 branch March 8, 2024 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants