Liquity v2 ~ Governance (3rd audit)
Smart Contract Security Assessment
December 22, 2024
Fixes (4th) Re-Audit: January 17,2025
SUMMARY
ABSTRACT
Dedaub was commissioned to perform a 3rd security audit of the Liquity v2 Governance protocol. Dedaub has previously been commissioned to audit two earlier versions of the codebase, the reports of which can be found at (Liquity v2 ~ Governance (1st audit) - Aug 12, 2024) and (Liquity v2 ~ Governance (2nd audit) - Nov 11, 2024). In these previous versions, one important issue was the rounding errors caused by how the average timestamps were calculated. In the current version, the voting power mechanism was refactored to eliminate the rounding issues. This review considered the codebase in its entirety and not only the delta of the changes between the current and the previous versions.
The code has improved even more in several important parts compared to the previous versions and has also been simplified in several complex parts. However, some of the reported issues remained active and some new ones were found.
The test suite was also extended with more test cases to better cover the most important parts of the protocol. We highly recommend more extensive unit tests to cover complex and edge case scenarios of the protocol.
After the fixes review, the codebase was further improved addressing the rounding errors in various components of the protocol. Some new assumptions were made and the protocol’s specification was updated to reflect them properly. The test suite was also extended and most of the issues were resolved.
BRIBE DISTRIBUTION FORMULA ANALYSIS
The current version of the codebase introduced further changes in the formulas used to calculate and distribute the bribes to the eligible users in the BribeInitiative
implementation as well as to calculate and distribute the user’s allocations over a set of initiatives in Governance::allocateLQTY
implementation. The new formulas aim to account for the rounding errors that the previous mechanism had.
Below we provide a thorough explanation of the new formulas and proofs for their correctness and fairness for all the users. We perform the analysis for the formula to calculate the bribes but the same analysis can be applied for vote allocation.
Let be the amount of bribe remaining to be distributed after the user claimed his bribe, be the amount of votes of the user, be the total amount of votes, and is the total amount of bribe to be distributed.
Notice that:
Therefore,
Fact 1: If , then for all possible values of and
Proof: