Conversation
This comment has been minimized.
This comment has been minimized.
| #[external("public")] | ||
| #[view] | ||
| fn private_supply() -> u128 { | ||
| self.storage.total_supply.read() - self.storage.public_supply.read() |
There was a problem hiding this comment.
This enters the list of invariants (that we never wrote) we need to hold,
total_supply must be always >= public_supply
There was a problem hiding this comment.
Yess, we should add the invariant list!
src/token_contract/src/main.nr
Outdated
| #[external("public")] | ||
| #[only_self] | ||
| fn increase_public_balance_internal(to: AztecAddress, amount: u128) { | ||
| fn increase_public_balance_and_supply_internal(to: AztecAddress, amount: u128) { |
There was a problem hiding this comment.
Just thinking out loud...
This makes me wonder if it should be increase_public_balance_and_supply_internal or increase_public_balance_and_public_supply_internal,
I think the latter is better but it's too verbose IMO.
There was a problem hiding this comment.
Agree ser, will use it tho, as we have supply and public_supply now -> 2068577
Review Summary by QodoAdd public and private supply tracking to token contract
WalkthroughsDescription• Add public_supply storage field tracking public token distribution • Implement public_supply() and private_supply() view functions • Rename internal functions to include supply updates in their names • Add comprehensive supply assertions across all token transfer, mint, and burn tests Diagramflowchart LR
A["Token Storage"] -->|adds| B["public_supply field"]
C["View Functions"] -->|adds| D["public_supply()"]
C -->|adds| E["private_supply()"]
F["Internal Functions"] -->|renamed| G["increase_public_balance_and_supply_internal"]
F -->|renamed| H["decrease_public_balance_and_supply_internal"]
I["Tests"] -->|adds| J["assertSupply helper"]
I -->|updates| K["All transfer/mint/burn tests"]
File Changes1. src/token_contract/src/main.nr
|
Code Review by Qodo
|
|
Persistent review updated to latest commit 2068577 |
Benchmark Comparison
Contract: escrow
Contract: logic
Contract: nft
Contract: token
Contract: vault
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| transfer_private_to_public_amount, | ||
| mint_amount - transfer_private_to_public_amount, |
There was a problem hiding this comment.
does transfer_private_to_public_amount change supply? 👀
| utils::assert_supply( | ||
| env, | ||
| token_contract_address, | ||
| transfer_amount, | ||
| total_amount - transfer_amount, | ||
| ); |
There was a problem hiding this comment.
i'm not following why the transfer amount changes supply, will keep on reading and come back
There was a problem hiding this comment.
ok, i understand now, hm idk about the need for the feature tbh, but it's true that's an onchain untracked metric on current design, wonder what's the use case of querying that
|
like: gate-count remains constant because is just public logic and storage, +5% doesn't seem prohibitive, tho we need to analyze and understand the actual mainnet costs |
🤖 Linear
Closes AZT-XXX
Description
public_supplystorage field to the token contract, tracking how much of the total supply lives in public balancesprivate_supplyastotal_supply - public_supplypublic_supply()andprivate_supply()view functionsincrease_public_balance_internal/decrease_public_balance_internaltoincrease_public_balance_and_supply_internal/decrease_public_balance_and_supply_internalassert_supplytest helper (Noir + JS) that validates public, private, and total supply in a single callMotivation
Tracking the public/private supply split gives other contracts an on-chain oracle for the token's "visibility distribution" — a property unique to Aztec. This enables use cases like dynamic risk parameters in lending markets, liquidity visibility for DEXes, governance quorum calculations, compliance circuit breakers, and more.
Design decisions
total_supply + public_supply(notprivate_supply): Every change to public supply already involves a public execution, making it the natural value to update directly.total_supplyis already needed for mint overflow checks._increase_public_supply/_decrease_public_supplyinternal functions: Consistent with the existing pattern for_increase_total_supply/_decrease_total_supply. Trades a small function dispatch overhead for cleaner reuse across 6 call sites.