Skip to content

Bug Fix: fix unsigned underflow in per-block net calculation#2033

Open
ukane-philemon wants to merge 1 commit intodecred:masterfrom
ukane-philemon:fix-bal-chart
Open

Bug Fix: fix unsigned underflow in per-block net calculation#2033
ukane-philemon wants to merge 1 commit intodecred:masterfrom
ukane-philemon:fix-bal-chart

Conversation

@ukane-philemon
Copy link
Collaborator

The per-block net value was previously computed using uint64, which caused underflow when sent > received within a block.

This resulted in incorrect large positive values due to unsigned wraparound.

Net flow per-block can legitimately be negative, the calculation now uses int64 which correctly represents block level balance changes and prevents overflow.

Closes #2031

Checkout the balances on the Treasury page to confirm issue and also address balances like this one: https://dcrdata.decred.org/address/DsSCPWJX871jTQ8CmN1ZaCQw4pW27YW2wDa?chart=amountflow&zoom=mm6vmelc-mm6x0uy8&bin=all&flow=7

Before:
before

After
after

The per-block net value was previously computed using uint64, which
caused underflow when sent > received within a block.

This resulted in incorrect large positive values due to unsigned
wraparound.

Net flow per-block can legitimately be negative, the calculation now uses
int64 which correctly represents block level balance changes and prevents
overflow.

Signed-off-by: Philemon Ukane <ukanephilemon@gmail.com>
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.

Balance chart is wrong with reused addresses.

1 participant