code-423n4 / 2022-02-anchor-findings

0 stars 0 forks source link

Users Can Utilise Flashloans to Vote on Governance Proposals #77

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Lines of code

https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/anchor-token-contracts/contracts/gov/src/contract.rs#L364-L455 https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/anchor-token-contracts/contracts/gov/src/contract.rs#L582-L665 https://github.com/code-423n4/2022-02-anchor/blob/main/contracts/anchor-token-contracts/contracts/gov/src/staking.rs#L15-L116

Vulnerability details

Impact

There seems to be an edge case where a user can cast a vote and end a poll within the same block. As such, this exposes several attack vectors but more specifically a case where a user can use a flashloan to stake ANC tokens, vote on a poll, end the poll and withdraw their staked tokens in a single transaction. This may allows users to execute arbitrary proposals, assuming their are more liquid ANC tokens than staked ANC tokens.

Proof of Concept

Let's consider the following scenario:

Tools Used

Manual code review.

Recommended Mitigation Steps

Consider updating one of the two checks in end_poll() or cast_vote() such that there is no crossover between the two checks. There should be no way to stake tokens, cast a vote, end the poll and withdraw staked tokens, so it might also be useful to prevent staking and withdrawing ANC tokens within a single block.

bitn8 commented 2 years ago

This is not a bug.

albertchon commented 2 years ago

Agreed, not a bug