dr497_ (@dr497_) profile picture
Joined March 2022
Photo by dr497_ (@dr497_)Photo by dr497_ (@dr497_)Photo by dr497_ (@dr497_)Photo by dr497_ (@dr497_)Photo by dr497_ (@dr497_)Photo by dr497_ (@dr497_)Photo by dr497_ (@dr497_)Photo by dr497_ (@dr497_)Photo by dr497_ (@dr497_)
Advent of Bugs Day 22: Rent is not linear One simple mistakes that devs make when calculating the rent of accounts is to assume that rent is linear. The assumption is that 10 bytes cost X rent, and 20 bytes in the same account therefore must cost 2X rent. However this isn’t correct, because we have a base rent that needs to be paid even for accounts with 0 bytes of data. This means that rent(0) = β (base rent). And this implicitly means that when we combine two accounts into one, or we want to extend one account with additional data of size diff, to calculate the new rent, we should not do rent(old_size) + rent(diff). Because imagine diff is 0, this would yield us rent(old_size) + β, meaning we get charged more for 0 added data. Instead, we need to calculate rent(old_size + diff). This way, β will only get taken into account once, as intended. -@dr497_ and @r0bre
1
4
15
1,187
Advent of Bugs #4: Bananas and Oranges Everybody knows you can't add bananas and oranges together. The same principle holds for smart contracts, you can't mix quote and base currencies. Except you can when they're all u64. This bug occurred in an AMM swap function with 4 code paths: - Buy ExactIn - Buy ExactOut - Sell ExactIn - Sell ExactOut The first paths look fine. The code is repetitive, so you're tempted to assume the rest is correct too. But Sell/ExactIn was comparing base amounts to quote amounts, like comparing bananas with oranges. The slippage check would pass even when it shouldn't. Why did this survive 3 audits? Base and Quote are both stored as u64, so no compile-time or runtime error when comparing different units A good way to prevent these bugs is to use newtype structs instead of type aliases to represent these different units in arithmetic operations. - @dr497_
2
6
1
26
2,189
🎄 Advent of Bugs 2024 'Tis the season for security bugs! Starting December 1st, we're unwrapping 24 interesting vulnerabilities we found auditing Solana programs this year. Think of it as an advent calendar, but instead of chocolate, you get real bugs. Broken account checks, logic flaws, math errors, SVM footguns... grab some hot cocoa and join us for daily lessons from the trenches. 24 bugs. 24 days. First gift drops tomorrow 🎁 - Your Accretion Team: @brymko, @0xmahdirostami, @dr497_ , @r0bre
4
5
1
53
2,906