# Update to Clrfund's QF Implementation

After the recent $350k Ethstaker x Clrfund round, an issue was identified with our implementation of Quadratic Funding, resulting in funding allocations different from what is described in the original CLR paper. A fix has now been implemented, future rounds will use the correct QF implementation.

Special thanks to Zoë Hitzig and Vitalik Buterin for guiding us through some of the nuances of quadratic funding, to Yuet Loo Wong for implementing the fix in Clrfund contracts, and to Q for identifying our incorrect implementation in the first place.

Recently, in the lead-up to the much anticipated Ethereum merge, Ethstaker and Clrfund coordinated the largest Clrfund round to-date. 4,704 legends contributed a total of 64.57K Dai to allocate a 375.7K Dai matching pool, for a total of 440.3K Dai allocated to public goods for the Ethereum staking ecosystem.

For the uninitiated, Quadratic Funding (often abbreviated to QF and also know as Capital-Constrained Liberal Radicalism or CLR) is a mechanism for allocating a pool of funds (for example, a large philanthropic contribution to some category of public goods) to a group of recipients. Why use QF over more traditional grant giving mechanisms? The answer, in short, is because it’s better -- it’s more efficient and more impactful -- for everyone involved. Quadratic Funding is a grant-giving flywheel that is the mathematically optimal way to fund public goods in a democratic community.

You can learn more about the mechanism in the original CLR paper, at WTFisQF.com, or the Clrfund app. For this post, the important part to understand is that QF weighs matching pool allocations by both the amount of funds contributed to each recipient (plutocracy) along with the number of contributors to each recipient (democracy). QF is an elegant compromise between plutocracy and democracy, that lets contributors signal both their preferences and the relative strengths of their preferences.

It is in the relative weighting between these two (plutocracy and democracy) that a Clrfund contributor noticed an error in clrfund's implementation of QF. The learning process that went into implementing a fix was quite illuminating, so we thought it was worth writing up a blog post to share what we learned. *It's worth noting that the error was identified before the ETHStaker x Clrfund round was finalized, but we ultimately decided to proceed with the allocation as computed by the incorrect implementation due to the uncertainty of if and when the implementation could be fixed and because of the coordination challenges inherent in cancelling a Clrfund round.*

Quadratic Funding is derived from Quadratic Voting (QV), whereby one's vote weight towards a given vote option is the square root of the number of "voice credits" one allocates to that option. For example, four voice credits equals two votes, nine voice credits equals three votes, sixteen voice credits equals four votes, and so on and so forth. What is used for voice credits differs between QV implementations, in some cases each voter is granted an equal amount of voice credits to allocate however they like between a set of options, while in others voters may be granted different amounts of voice credits based on some criteria. One such example of the latter is using money for voice credits. In which case, QV exhibits the quality mentioned above, striking a happy balance between plutocracy and democracy.

Clrfund's original implementation allocated funds to recipients applying the ratio of quadratic votes for a given recipient to the matching pool, to determine the amount of matching funds to be received on top of the direct contributions to that recipient, or `(total votes for recipient) / (total votes to all recipients)* (total tokens in the matching poo) + (total tokens contributed to recipient)`

. This seemed to be the intuitive way to apply QV to the allocation of the matching pool (our naive understanding of how QF worked). With this implementation, the top recipient received a total of 40,387.69 Dai, while the bottom received 4,381.11 Dai.

However, as we discovered, the results turn out to be quite different from QF.

While similar, it turns out that QF is not simply QV ratios applied to a matching pool. The original CLR paper describes Liberal Radicalism (LR) as a mechanism by which one uses individual contributions towards public goods as quadratic votes towards subsidizing those public goods. Individuals contribute the public goods they value and LR suggests how much additional funding should be given to those public goods, presumably via inflation (or some other potentially limitless pool of funding). The allocation for a given recipient is the square of the sum of quadratic votes for that recipient, or `(total votes for recipient)^2`

.

Using the ETHStaker x Clrfund round as an example, 5,782.06 Dai was contributed to the top recipient, from which the LR mechanism suggested an allocation of 10,991,404.63 Dai. A little over budget, to say the least. The bottom recipient received 576.37 Dai in contributions, from which LR suggested an allocation of 132,864.81 Dai.

Capital-Constrained Liberal Radicalism (CLR, otherwise known as QF) scales the LR mechanism to account for the reality that matching pools will almost always be finite. It does so by introducing "alpha", a value between zero and one, to scale back the LR allocation while ensuring recipients always receive at least the amount that was directly contributed to them, or `alpha * (total votes for recipient)^2 + (1 - alpha) * (total tokens contributed to recipient)`. Alpha should be set at the value which results in the entire budget for the round being consumed (matching pool plus direct contributions).

Again using the ETHStaker x Clrfund round as an example, 5,782.05 Dai was contributed to the top recipient, resulting in a total allocation of 56,136.50 Dai. While 576.37 Dai was contributed to the lowest recipient, resulting in a total allocation of 1,182.73 Dai.

In other words, under the correct QF implementation, the top recipients would have received significantly more than they did under our naive implementation, while the bottom recipients would have received significantly less.

Our knee-jerk reaction to this was to assume that the more top-heavy distribution under QF (as compared to our original more naive implementation) meant that QF was more plutocratic that what we had originally implemented. The projects that received larger sums of contributions would receive a relatively larger portion of the matching pool, sounds plutocratic, right? This led us to start questioning whether we would in-fact prefer to keep our incorrect, albeit apparently less plutocratic, implementation. As it turns out, though, this assumption was incorrect. Here's why.

Thanks to MACI (the Minimal Anti-Collusion Infrastructure) that Clrfund is built on, we have limited insight into how contributors allocated their funds. We can see how much a contributor contributed to the round as a whole, but not how much they allocated to each recipient, and we can see how many votes each recipient received, along with how much each recipient received in direct contributions.

Looking at the final tally for the ETHStaker x Clrfund round, we see that the top recipient received roughly ten times more votes and Dai contributions, compared to the bottom recipient. In the original Clrfund implementation, the top recipient, similarly, received roughly ten times the allocation of the bottom recipient. While with correctly implemented QF, the top recipient would have received roughly forty-seven times the allocation of the bottom recipient.

Recipient | Votes Received | Contributions Received | Clrfund Allocation | QF Allocation |
---|---|---|---|---|

Top | `1,048,399` |
`5,782 Dai` |
`40,387 Dai` |
`56,136 Dai` |

Bottom | `115,267` |
`576 Dai` |
`4,381 Dai` |
`1,182 Dai` |

At first glance, it appears that QF would have disproportionately rewarded the recipients that received a greater amount of Dai in contributions. It turns out that this is not the case.

Remember, we can't know who or how many contributors contributed to a given recipient. But given the votes received and the amount spent on a given recipient, we can make rough guesses at it. It turns out that for 5,782 Dai in contributions to have resulted in 1,048,399 votes in MACI, roughly 2,000 contributors must have contributed roughly 3 Dai each to the top recipient. While for 576 Dai to have resulted in 115,267 votes, roughly 225 contributors must have contributed roughly 3 Dai each to the bottom recipient.

Recipient | Votes Received | Contributions Received | Contributors |
---|---|---|---|

Top | `1,048,399` |
`5,782 Dai` |
`2,000` |

Bottom | `115,267` |
`576 Dai` |
`2` |

For those wondering about the math in this table, the Dai values presented must be multiplied by 10^5 to reach the same level of precision as the MACI tally output. To arrive at the estimated number of contributors,`x`

, we find a value for`x`

where`votes received ≈ ( √(( contributions * 10^5 ) / x )) * x`

.

According to this very rough estimation, roughly ten times as many people contributed a total of roughly ten times as much Dai to the top recipient compared to the bottom recipient. So a purely democratic allocation might give the top recipient roughly ten times as much as the bottom recipient, while a purely plutocratic allocation might give the top recipient ten times as much as the bottom recipient. The allocation suggested by Liberal Radicalism essentially splits the difference, suggesting an allocation where the top recipient would receive roughly one hundred times the bottom recipient. Roughly equal weight given to both individual preference (the recipients one contributes to) and strength of preference (the amount one contributes to each recipient).

Recipient | Votes Received | Square of Votes Received | Liberal Radicalism Allocation |
---|---|---|---|

Top | `1,048,399` |
`1,099,140,463,201` |
`10,991,404 Dai` |

Bottom | `115,267` |
`13,286,481,289` |
`132,864 Dai` |

But, as we mentioned earlier, the allocations suggested by LR go way over budget. CLR/QF attempts to solve for this by scaling the total budget in a way that both:

- ensures each recipient gets at least the amount that was directly contributed to them
- minimally distorts the shape of the distribution suggested by LR

All this is to say that the top heavy distribution suggested by CLR/QF, that we erroneously attributed to plutocracy's influence, was more than likely a result of an overwhelming number of contributors making relatively small contributions to the top projects, compared to relatively few contributors making larger contributions to the bottom few recipients.

The unfortunate reality of this is that all previous Clrfund rounds have been more plutocratic than intended, disproportionately weighting the amount contributed compared to the amount of contributors. However, the good news is that we've updated our smart contracts to correctly implement CLR/QF. 🎉