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

feat(gnovm/tm2): add ZeroAddress constant #2401

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions gno.land/cmd/gnoland/testdata/event_multi_msg.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ stdout ' "BaseAccount": {'
stdout ' "address": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",'
stdout ' "coins": "[0-9]*ugnot",' # dynamic
stdout ' "public_key": null,'
stdout ' "account_number": "0",'
stdout ' "account_number": "1",'
stdout ' "sequence": "0"'
stdout ' }'
stdout '}'
! stderr '.+' # empty


## sign
gnokey sign -tx-path $WORK/multi/multi_msg.tx -chainid=tendermint_test -account-number 0 -account-sequence 0 test1
gnokey sign -tx-path $WORK/multi/multi_msg.tx -chainid=tendermint_test -account-number 1 -account-sequence 0 test1
stdout 'Tx successfully signed and saved to '

## broadcast
Expand Down
4 changes: 2 additions & 2 deletions gno.land/cmd/gnoland/testdata/gnoweb_airgapped.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ stdout ' "BaseAccount": {'
stdout ' "address": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",'
stdout ' "coins": "[0-9]*ugnot",' # dynamic
stdout ' "public_key": null,'
stdout ' "account_number": "0",'
stdout ' "account_number": "1",'
stdout ' "sequence": "0"'
stdout ' }'
stdout '}'
Expand All @@ -26,7 +26,7 @@ gnokey maketx call -pkgpath "gno.land/r/demo/echo" -func "Render" -gas-fee 10000
cp stdout call.tx

# Sign
gnokey sign -tx-path $WORK/call.tx -chainid "tendermint_test" -account-number 0 -account-sequence 0 test1
gnokey sign -tx-path $WORK/call.tx -chainid "tendermint_test" -account-number 1 -account-sequence 0 test1
cmpenv stdout sign.stdout.golden

gnokey broadcast $WORK/call.tx
Expand Down
4 changes: 4 additions & 0 deletions gno.land/pkg/gnoland/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ func (cfg InitChainerConfig) loadAppState(ctx sdk.Context, appState any) ([]abci
return nil, fmt.Errorf("invalid AppState of type %T", appState)
}

// Init ZeroAccount
zeroAcc := cfg.acctKpr.NewAccountWithAddress(ctx, vm.ZeroAddress())
cfg.acctKpr.SetAccount(ctx, zeroAcc)

// Parse and set genesis state balances
for _, bal := range state.Balances {
acc := cfg.acctKpr.NewAccountWithAddress(ctx, bal.Address)
Expand Down
2 changes: 1 addition & 1 deletion gno.land/pkg/integration/testdata/adduserfrom.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ stdout ' "BaseAccount": {'
stdout ' "address": "g1mtmrdmqfu0aryqfl4aw65n35haw2wdjkh5p4cp",'
stdout ' "coins": "10000000ugnot",'
stdout ' "public_key": null,'
stdout ' "account_number": "58",'
stdout ' "account_number": "59",'
stdout ' "sequence": "0"'
stdout ' }'
stdout '}'
Expand Down
2 changes: 1 addition & 1 deletion gno.land/pkg/integration/testdata/gnokey.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ stdout ' "BaseAccount": {'
stdout ' "address": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",'
stdout ' "coins": "[0-9]*ugnot",' # dynamic
stdout ' "public_key": null,'
stdout ' "account_number": "0",'
stdout ' "account_number": "1",'
stdout ' "sequence": "0"'
stdout ' }'
stdout '}'
Expand Down
6 changes: 6 additions & 0 deletions gno.land/pkg/sdk/vm/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@ func (bnk *SDKBanker) RemoveCoin(b32addr crypto.Bech32Address, denom string, amo
if err != nil {
panic(err)
}
// TODO: once TotalCoin is implemented, we need to deduct the TotalCoins beside send coin to ZeroAddress (?)
zeroAddr := ZeroAddress()
_, err = bnk.vmk.bank.AddCoins(bnk.ctx, zeroAddr, std.Coins{std.Coin{denom, amount}})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why adding the removed coins to the zero address?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moul
This is because of the burn process definition: Should send coins from burner to zero address, beside removing that amount of coins from Total Supply.
Adding to ZeroAddress making everyone can see how many coins is burned, and how many coins zero address currently holds. Deducting coins from total supply is the target of burning theory.

if err != nil {
panic(err)
}
}
15 changes: 15 additions & 0 deletions gno.land/pkg/sdk/vm/zero_address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package vm

import "github.com/gnolang/gno/tm2/pkg/crypto"

const (
zAddressBech32 = string("g1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqluuxe")
)

func ZeroAddress() crypto.Address {
ZAddress, err := crypto.AddressFromBech32(zAddressBech32)
if err != nil {
panic(err)
}
return ZAddress
}
12 changes: 12 additions & 0 deletions gno.land/pkg/sdk/vm/zero_address_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package vm

import (
"testing"

"github.com/stretchr/testify/assert"
)

func Test_ZAccount(t *testing.T) {
zA := ZeroAddress()
assert.Exactly(t, zA.String(), "g1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqluuxe")
}
4 changes: 4 additions & 0 deletions gnovm/stdlibs/std/native.gno
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package std

const (
ZeroAddress Address = "g1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqluuxe" // XXX: specific to gno.land
)

// AssertOriginCall panics if [IsOriginCall] returns false.
func AssertOriginCall() // injected

Expand Down
4 changes: 2 additions & 2 deletions gnovm/tests/files/std5_stdlibs.gno
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ func main() {

// Stacktrace:
// panic: frame not found
// callerAt<VPBlock(3,44)>(n<VPBlock(1,0)>)
// callerAt<VPBlock(3,45)>(n<VPBlock(1,0)>)
// gonative:std.callerAt
// std<VPBlock(2,0)>.GetCallerAt(2)
// std/native.gno:44
// std/native.gno:48
// main<VPBlock(1,0)>()
// main/files/std5_stdlibs.gno:10

Expand Down
4 changes: 2 additions & 2 deletions gnovm/tests/files/std8_stdlibs.gno
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func main() {

// Stacktrace:
// panic: frame not found
// callerAt<VPBlock(3,44)>(n<VPBlock(1,0)>)
// callerAt<VPBlock(3,45)>(n<VPBlock(1,0)>)
// gonative:std.callerAt
// std<VPBlock(2,0)>.GetCallerAt(4)
// std/native.gno:44
// std/native.gno:48
// fn<VPBlock(1,0)>()
// main/files/std8_stdlibs.gno:16
// testutils<VPBlock(2,1)>.WrapCall(inner<VPBlock(3,0)>)
Expand Down
2 changes: 1 addition & 1 deletion gnovm/tests/files/zrealm_natbind0_stdlibs.gno
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func main() {
// "Location": {
// "Column": "1",
// "File": "native.gno",
// "Line": "13",
// "Line": "17",
// "PkgPath": "std"
// }
// },
Expand Down
Loading