Skip to content

prevent overflow#39

Merged
nialexsan merged 2 commits intomainfrom
nialexsan/tweak-update-interest
Sep 9, 2025
Merged

prevent overflow#39
nialexsan merged 2 commits intomainfrom
nialexsan/tweak-update-interest

Conversation

@nialexsan
Copy link
Copy Markdown
Contributor

No description provided.

@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 20, 2025

Codecov Report

❌ Patch coverage is 47.05882% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cadence/contracts/TidalProtocol.cdc 47.05% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

self.lastUpdate = currentTime

// Update deposit capacity based on time
let newDepositCapacity = self.depositCapacity + (self.depositRate * timeDelta)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this calculation causes overflow if time delta is big

@nialexsan nialexsan marked this pull request as ready for review August 21, 2025 16:42
Comment thread cadence/contracts/TidalProtocol.cdc Outdated
Comment on lines +344 to +347
if remaining <= 0.0 {
self.depositCapacity = self.depositCapacityCap
return
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should never hit this block due to the conditional at L334, I think it's safe to remove

Comment thread cadence/contracts/TidalProtocol.cdc Outdated
Comment on lines +356 to +358
// Safe: growth <= remaining, so the addition cannot overflow
let growth: UFix64 = effectiveRate * dt
self.depositCapacity = self.depositCapacity + growth
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we're worried about overflow on addition here, we could do something like

if growth <= self.depositCapacityCap && self.depositCapacity < (self.depositCapacityCap - growth) {
    self.depositCapacity = self.depositCapacity + growth
} else {
    self.depositCapacity = self.depositCapacityCap
}

But I'm taking your comment here to mean overflow was an issue on multiplication

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

growth should be always less than depositCapacityCap

@nialexsan nialexsan merged commit 31c0afa into main Sep 9, 2025
1 of 2 checks passed
@nialexsan nialexsan deleted the nialexsan/tweak-update-interest branch September 9, 2025 15:13
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.

2 participants