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

Use an account for tracking the total circulation. #91

Conversation

kantp
Copy link
Collaborator

@kantp kantp commented Jul 15, 2024

Instead of using actions and reducers to update the current circulation in the contract state, we now use an account where the balance corresponds to the current circulation.

  • We use an account with the key of the token contract.
  • The account balance is updated at every call of mint() and burn().
  • The approveBase() method checks that none of the involved AccountUpdates does involve this
  • special account.

kantp added 4 commits July 15, 2024 14:37
Instead of using actions and reducers to update the current circulation in the contract state, we
now use an account where the balance corresponds to the current circulation.

- We use an account with the key of the token contract.
- The account balance is updated at every call of `mint()` and `burn()`.
- The `approveBase()` method checks that none of the involved `AccountUpdate`s does involve this
- special account.
@kantp kantp force-pushed the 66-eliminate-dos-vulnerability-in-the-reducer-calculating-the-circulating-supply branch from 64df44b to 4096eb0 Compare July 15, 2024 18:35
@kantp kantp marked this pull request as ready for review July 15, 2024 18:55
FungibleToken.ts Outdated
return accountUpdate
}

@method.returns(AccountUpdate)
async burn(from: PublicKey, amount: UInt64): Promise<AccountUpdate> {
this.paused.getAndRequireEquals().assertFalse()
const accountUpdate = this.internal.burn({ address: from, amount })
const circulationUpdate = AccountUpdate.create(this.address, this.deriveTokenId())
circulationUpdate.balanceChange = Int64.fromUnsigned(amount).mul(Int64.minusOne)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Int64.fromUnsigned(amount).negV2() should be more efficient (in terms of constraints) than using mul()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks!

@kantp kantp added this pull request to the merge queue Jul 16, 2024
Merged via the queue into main with commit f6a4238 Jul 16, 2024
3 checks passed
@kantp kantp deleted the 66-eliminate-dos-vulnerability-in-the-reducer-calculating-the-circulating-supply branch July 16, 2024 08:05
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.

Eliminate DoS vulnerability in the reducer calculating the circulating supply
2 participants