Skip to content

Fix precision loss in treasury amount calculation during fee collection #291

@coderabbitai

Description

@coderabbitai

Description

There is a potential precision loss issue in the treasury amount calculation within the MarkFeesCollected method in internal/service/fees.go.

Problem

The conversion from big.Float to uint64 using the Uint64() method truncates the value and ignores the accuracy flag, which could lead to incorrect treasury amounts being calculated.

Location: internal/service/fees.go around lines 162-165

Current problematic code:

treasuryAmount := big.NewFloat(0).SetUint64(fee.Amount)
treasuryAmount = treasuryAmount.Mul(treasuryAmount, big.NewFloat(treasurySplit))
treasuryAmountUint64, _ := treasuryAmount.Uint64()  // <- Ignores accuracy flag
developerAmountUint64 := fee.Amount - treasuryAmountUint64

Solution

The code should check the accuracy returned by Uint64() and apply proper rounding before converting to uint64 to ensure the treasury amount is correctly calculated without truncation errors.

Backlinks

Reported by: @garry-sharp

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions