Missing check in the updateValset function
The updateValset function does not verify that the sum of the new validators' powers exceeds the threshold, which could allow a new validator set with insufficient total power to be accepted. This could cause the system to become stuck, preventing any operations including further valset updates, and potentially locking all tokens.
Originally disclosed on Code4rena
Submitted by CertoraInc, also found by 0x1337, cccz, danb, dipp, dirk_y, hubble, jah, and WatchPug
The updateValset function don’t check that the sum of the powers of the new validators in the new valset is greater than the threshold, which can lead to unwanted behavior.
There are 2 main problems that can occur in that situation:
- The sum of the new validators’ powers will be lower than the
state_powerThreshold - The sum of the new validators’ power will overflow and become lower than the
state_powerThreshold
The second case is less dangerous, because it won’t stuck the system in every case (only in specific cases where every sum of validators’ power is less than the threshold). The first case is very dangerous though. It can lead to the system becoming stuck and to all of the tokens on the cudos chain to become locked for users, because the validators won’t have enough power to approve any operation - whether it is transferring tokens or updating the valset.
Proof of Concept
For the first case, consider the current validators set containing 100 validators with each ones power being equal to 10, and the threshold is 900 (91+ validators are needed for approvement). Now the updateValset function is being called with 100 validators with each ones power being equal to 1. This will lead to a state where no matter how much validators have signed a message, the sum of the powers won’t pass the threshold and the action won’t be able to be executed. This will cause all the tokens in the cudos blockchain become locked, and will DoS all the actions of the gravity contract - including updating the valset.
For the second case, consider the new validators set will have 128 validators, each validator’s power is equal to 2**249 and _powerThreshold = 2**256 - 1. In this case the system will be stuck too, because every sum of validators’ power won’t pass the threshold.
Tools Used
Remix and VS Code
Recommended Mitigation Steps
Add a check in the updateValset to assure that the sum of the new powers is greater than the threshold.
V-Staykov (Cudos) disputed and commented:
This check is done on the Gravity module side and since the message is also signed there by the validators, we can consider it to be always as per the module, unless there are malicious validators with more voting power than the threshold.
If the message is considered correct this means that the values of the power are normalized which is in the core of the power threshold calculation. When they are normalized this means that the sum of the validator set will always equal 100% of the power which is more than the threshold.
Here is a link to the power normalization in the Gravity module side.
Albert Chon (judge) decreased severity to Medium and commented:
Agreed with @V-Staykov - this would only fail if 2/3+ of the validator stake weight were controlled by malicious validators, at which point all bets are off.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the updateValset function lacks a check that the sum of the new validators' powers is greater than the power threshold.
Impact
If the new validators' total power is below the threshold, the system could become stuck and all tokens could be locked, but the judge noted this would only happen if malicious validators already controlled a large share of the stake.
What the attacker needed
Malicious validators with enough voting power
The fix
The function should be fixed by adding a check to ensure the sum of the new powers is greater than the threshold.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In a blockchain bridge, validators vote with 'power' to approve actions. If the total power of all validators is less than the required threshold, no action can ever be approved. This report shows that a function updating the validator set did not check that the new total power was high enough, which could freeze the system.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.