A Vault can steal all funds from another Vault through the Registry’s flash loan contract due to insufficient access control in Connector.sendTokensToTrustedAddress()
The shared flash loan contract was treated as a trusted caller by every connector, so any vault keeper could make it pull tokens out of another vault's connector. The attacker could then redirect those tokens to an address they control, draining the victim vault.
Originally disclosed on Code4rena
Submitted by alexxander (View multiple reports submitted by additional wardens)
Impact
The keeper of a Vault can steal all funds from another Vault.
Proof of Concept
Noya Vaults are registered with the Registry contract where Registry.addVault() is used to add a particular Vault and specify the address of its AccountingManager, maintainer, keeper, etc. The Registry contract also has the state variable address flashLoan which is the address of a BalancerFlashLoan contract that is used by the Vaults to leverage flash loans. The issue is that in any Connector, the BaseConnector.sendTokensToTrustedAddress() function allows the BalancerFlashLoan contract to perform token transfers back to the BalancerFlashLoan contract - code snippet. This allows for the following exploit:
-
Assume 2 Vaults with Ids: ID-1 and ID-2
-
Assume ID-1 has a Connector C-1
-
Assume ID-2 has a Connector C-2
-
Assume C-2 holds X amount of token Y
-
The keeper of ID-1 calls
BalancerFlashLoan.makeFlashloan()code snippet -
the
tokensarray holds the address of some token -
the
amountsarray holds some amount of the token intokens -
bytes userDatais packed asuint256 vaultId = ID-1address receiver = C-1address[] destinantionConnector = [C-2, Y]bytes[] callingData = [sendTokensToTrustedAddress(Y, X, address(0), ""), transferTo(C1, X)]uint256[] gas = [enoughGas, enoughGas]
-
BalancerFlashLoan.receiveFlashLoan()is called by Balancer -
The
receiver(C-1) get’s the flash loan tokens -
destinationConnector[0].call{...}(callingData[0]), which is theBaseConnector.sendTokensToTrustedAddress()call toC-2. The ConnectorC-2allows the execution sincemsg.senderisregistry.flashLoan().C-2sends X amount of tokens toBalancerFlashLoan. -
destinationConnector[1].call{...}(callingData[1]), which is theY.transferTo()call that will transfer the X amount of tokens fromBalancerFlashLoantoC-1. -
C-1returns the borrowed tokens and keeps the X amount of token Y
Coded Proof of Concept
The aim of the POC is to showcase how one Vault can steal the funds from another Vault’s BaseConnector. The test consists of 2 Vaults (ID-5 and ID-10). In the beginning of the test ID-5 receives and executes deposits that go into its BaseConnector. The keeper of ID-10 then leverages the BalancerFlashLoan contract to call BaseConnector.sendTokensToTrustedAddress() and after that to retrieve the funds into an arbitrary address.
- Add the contents of the following gist in a solidity file under
/testsFoundry- gist with code - Execute with
forge test --match-test testVaultIssue -vv --fork-url <mainnet rpc url>
Recommended Mitigation Steps
Function BaseConnector.sendTokensToTrustedAddress() should be able to check that the caller of BalancerFlashLoan.makeFlashLoan() is authorized to perform calls into the Connector.
HadiEsna (NOYA) confirmed and commented:
Fixed in e1d9ac635b6cada731bdfc16d2a1b7b640360311 and 986d24df537bed29ebec7fc51ae2e6f442058cea.
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 connector's sendTokensToTrustedAddress() trusts the registry's flash loan contract unconditionally, without checking that the original caller of the flash loan is authorised for that connector.
What the attacker needed
Keeper role on one vault; victim vault connector holds tokens
The fix
The connector should verify that whoever initiated the flash loan is authorised to make calls into that connector; the project confirmed this was fixed.
How it was found
- The keeper of vault ID-1 calls makeFlashloan() on the BalancerFlashLoan contract.
- The flash loan contract calls receiveFlashLoan() and passes the borrowed tokens to connector C-1.
- C-1 calls sendTokensToTrustedAddress() on connector C-2, which accepts it because the caller is the registry's flash loan contract.
- C-2 sends its tokens to the flash loan contract.
- A second call transfers those tokens from the flash loan contract to C-1.
- C-1 repays the loan and keeps the stolen tokens.
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.
A vault is a smart contract that holds money for users. Connectors are helper contracts that move that money around. The code let one special helper contract move tokens out of any connector without checking who had asked it to do so, so someone running one vault could use it to empty another vault.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.