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

Conversation

thinhnx-var
Copy link
Contributor

@thinhnx-var thinhnx-var commented Jun 20, 2024

Contributors' checklist...
  • 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
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

After discussion in #2316, this PR does:

  • add std.ZeroAddress() with address g100000000000000000000000000000000dnmcnx in tm2.
  • Logic: add coins to zeroAddress when user burn coin with SDKBanker.RemoveCoin()
  • add a ZeroAccount with account_number = 0 when initializing the chain
  • add std.ZeroAddress() in gnovm/std in oder to help realm can burn coins to this address.

There are 2 main usecase of this adding that I think about:

  • With native, user can burn coin by sending it to ZeroAddress
❯ gnokey maketx send -gas-fee="1000ugnot" -gas-wanted="50000" -send="1000ugnot" -to g100000000000000000000000000000000dnmcnx -broadcast testKey
  • With token like grc20, user can burn coin by calling transfer to ZeroAddress:
❯ gnokey maketx call -pkgpath "gno.land/r/thinhnx/foo20" -func "Transfer" -args "g100000000000000000000000000000000dnmcnx" -args "5000000000" -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast testKey

Status:

In this approach, I think we should deduct the total supply coin / token in chain, but it is neither implemented in native coin, nor grc20 standard. This may be relate to this @leohhhn 's PR #2314.

Demo:

Native coin
Pasted Graphic

grc20 token - I changed admin address to mine when testing
Pasted Graphic 1

This is my first implementation about zero address in gno ecosystem. I really want to know if there is any idea to make this better!

@github-actions github-actions bot added 📦 🤖 gnovm Issues or PRs gnovm related 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Jun 20, 2024
@thinhnx-var
Copy link
Contributor Author

@leohhhn
Sorry for long time doing, this is my approach of zero address. I need your opinion :))

Copy link

codecov bot commented Jun 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.43%. Comparing base (dd2d374) to head (a5df32c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2401      +/-   ##
==========================================
- Coverage   60.44%   60.43%   -0.01%     
==========================================
  Files         563      563              
  Lines       75159    75159              
==========================================
- Hits        45431    45424       -7     
- Misses      26341    26345       +4     
- Partials     3387     3390       +3     
Flag Coverage Δ
contribs/gnodev 60.65% <ø> (-0.82%) ⬇️
contribs/gnofaucet 15.31% <ø> (+0.85%) ⬆️
misc/genstd 80.54% <ø> (ø)
misc/logos 20.23% <ø> (+0.35%) ⬆️
tm2 62.06% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@thinhnx-var thinhnx-var force-pushed the dev-thinhnx/feat_gno_std_zeroAddress branch from ebe8540 to 5911266 Compare June 20, 2024 14:56
@thinhnx-var
Copy link
Contributor Author

Additional, I am not sure that init a ZeroAccount with account_number=0 when init chain makes sense. I made this for readability and clearly view point from user.

tm2/pkg/std/zero_address.go Outdated Show resolved Hide resolved
gnovm/stdlibs/std/native.gno Outdated Show resolved Hide resolved
@@ -91,4 +91,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 := std.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.

gno.land/pkg/gnoland/app.go Outdated Show resolved Hide resolved
Copy link
Member

@moul moul left a comment

Choose a reason for hiding this comment

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

what about having this constant defined in a p/ package instead? this way we don't need to manage multichain bech32 support.

@thinhnx-var
Copy link
Contributor Author

thinhnx-var commented Jun 21, 2024

what about having this constant defined in a p/ package instead? this way we don't need to manage multichain bech32 support.

Is it good to have a /p just contains a constant and no logical fn.
Beside it, if we have this package, it is defined separately from gno.land's zero address, which still same value.

@leohhhn leohhhn linked an issue Jun 21, 2024 that may be closed by this pull request
@moul
Copy link
Member

moul commented Jul 1, 2024

Just noticed that the Stringer value of an empty bft.Address{} is creator=g1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqluuxe.

@thinhnx-var
Copy link
Contributor Author

Just noticed that the Stringer value of an empty bft.Address{} is creator=g1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqluuxe.

Ah yeah, agree with this

@thinhnx-var thinhnx-var force-pushed the dev-thinhnx/feat_gno_std_zeroAddress branch from d5e1b54 to a5df32c Compare September 11, 2024 08:52
@thinhnx-var
Copy link
Contributor Author

I turn this PR to draft because recently gno store cache PR 2319 effected to account keeper. Will take effort on this to fix the conflict.

@thinhnx-var thinhnx-var marked this pull request as draft September 11, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: No status
Status: Backlog
Development

Successfully merging this pull request may close these issues.

[Discussion] std.ZeroAddress
4 participants