Skip to content

Commit

Permalink
chore: revert "feat(gnovm): implement overflow checking at VM level (#…
Browse files Browse the repository at this point in the history
…3250)"

This reverts commit 68aff64.

This PR was merged before discussions were complete. It was finally
rejected because it does not comply with Go specification, which
stipulates that overflow on signed integers do not trigger runtime
panic. See https://go.dev/ref/spec#Integer_overflow
  • Loading branch information
mvertes committed Jan 14, 2025
1 parent cc5cb36 commit de5a919
Show file tree
Hide file tree
Showing 21 changed files with 1,057 additions and 563 deletions.
22 changes: 8 additions & 14 deletions examples/gno.land/p/demo/grc/grc20/token.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package grc20

import (
"math/overflow"
"std"
"strconv"

Expand Down Expand Up @@ -169,24 +170,17 @@ func (led *PrivateLedger) Approve(owner, spender std.Address, amount uint64) err
}

// Mint increases the total supply of the token and adds the specified amount to the specified address.
func (led *PrivateLedger) Mint(address std.Address, amount uint64) (err error) {
func (led *PrivateLedger) Mint(address std.Address, amount uint64) error {
if !address.IsValid() {
return ErrInvalidAddress
}

defer func() {
if r := recover(); r != nil {
if r != "addition overflow" {
panic(r)
}
err = ErrOverflow
}
}()

// Convert amount and totalSupply to signed integers to enable
// overflow checking (not occuring on unsigned) when computing the sum.
// The maximum value for totalSupply is therefore 1<<63.
sum := int64(led.totalSupply) + int64(amount)
// XXX: math/overflow is not supporting uint64.
// This checks prevents overflow but makes the totalSupply limited to a uint63.
sum, ok := overflow.Add64(int64(led.totalSupply), int64(amount))
if !ok {
return ErrOverflow
}

led.totalSupply = uint64(sum)
currentBalance := led.balanceOf(address)
Expand Down
70 changes: 0 additions & 70 deletions gnovm/pkg/gnolang/op_bench_test.go

This file was deleted.

Loading

0 comments on commit de5a919

Please sign in to comment.