It’s important to understand that CoW Protocol can also be used by other applications.
For example, in 2021, Balancer integrated the protocol into its interface, creating the Balancer-CoW-Protocol (BCP).
Integration with Balancer: Security Architecture
CoW Protocol collaborates with Balancer to maximize user profit and provide additional security.
It’s important to note that the key element of this partnership is the GPv2VaultRelayer contract, which serves as a critical security component. Its main guarantee: GPv2VaultRelayer can transfer ERC-20 tokens ONLY to the GPv2Settlement contract.
This architectural decision protects user funds from potentially malicious solvers. If users granted approvals directly to the GPv2Settlement
contract, a malicious solver could abuse the "interactions" mechanism to gain access to user funds. The GPv2Settlement
contract explicitly forbids this with a check in the code: require(interaction.target != address(vaultRelayer), "GPv2: forbidden interaction")
, which further guarantees that even a malicious solver cannot directly interact with the contract holding user approvals.
The "interactions" mechanism is a specific parameter of the settle()
function in the GPv2Settlement
contract. It allows solvers to pass arbitrary calls to external smart contracts. Technically, it’s a bytecode array (bytes[] calldata interactions
) that the solver can fill with any external protocol calls.
These interactions are used to route funds through various DEXs (Uniswap, Curve, Balancer) or aggregators (1inch, Paraswap) to get the best prices.
It’s critically important to understand that:
- Interactions are not part of the data signed by the user in their order
- They are fully controlled by the solver at the time of transaction execution
- They may contain arbitrary calls to any contracts on the blockchain
This is where the vulnerability would arise: If the user approved tokens directly to the GPv2Settlement
contract and the solver was malicious, they could insert calls into the interactions
array that transfer tokens anywhere. The architecture with GPv2VaultRelayer
solves this problem by restricting the flow of funds:
- Tokens can be transferred only to the
GPv2Settlement
contract GPv2Settlement
can use the tokens only within the current transaction - Even if
GPv2Settlement
were compromised, an attacker still couldn’t move funds outside the trusted contracts
Thus, the system preserves flexible routing while eliminating the risk of fund theft through malicious interactions.
Example of Fund Flow:
Let’s say a user wants to sell 100 USDC for at least 0.05 ETH:
With VaultRelayer architecture (secure):
- The user gives
approve
for 1000 USDC to the VaultRelayer contract - VaultRelayer transfers only 100 USDC to the Settlement contract (exact amount specified in the order)
- Settlement swaps 100 USDC for 0.053 ETH via DEX interactions
- The user receives 0.053 ETH minus protocol fee
- The remaining 900 USDC are untouched by Settlement and stay secure
Without VaultRelayer (insecure):
- If the user had approved tokens directly to the Settlement contract
- A malicious solver could avoid executing the order via a DEX and instead:
- Add a call to
USDC.transferFrom(user, attacker, 100)
in the interactions
array to steal the swap amount - Never send the promised ETH to the user
- Also add
USDC.transferFrom(user, attacker, 900)
to steal the remaining balance
- All of this is possible because the solver fully controls the contents of the
interactions
array
This example clearly shows why the VaultRelayer architecture is a critically important security component in CoW Protocol. VaultRelayer not only limits the amount available per order but also guarantees that even this amount can only be transferred to the Settlement contract, where strict order execution checks are enforced.
Now let’s move on to the benefits of integrating with Balancer.
Benefits for Balancer: Balancer gains an additional trading interface without needing to develop its own. Its users get MEV protection, access to better prices, and gas-efficient trading — all without needing to interact with a new protocol. This increases trading volume in Balancer pools and, as a result, boosts fees for liquidity providers, all while keeping users within the Balancer ecosystem.
Benefits for CoW Protocol: CoW Protocol gains privileged access to Balancer liquidity, gas optimization via internal Vault balances, and the ability to reuse approvals users have already granted to the Balancer Vault. This significantly lowers the entry barrier for millions of Balancer users and expands the protocol’s user base. Additionally, the user journey is simplified and security is improved, since users can manage all approvals through a unified Balancer interface.
It’s important to understand how balances work in Balancer:
External Balancer balances – these are standard ERC-20 tokens held in users’ wallets. To use them, the user must approve
the Balancer Vault contract to access the tokens. This is the typical token management method used in most DeFi protocols.
Internal Balancer balances – this is an accounting system within the Balancer Vault contract that tracks how many tokens each user owns, without requiring additional on-chain ERC-20 transfers. The user must first "deposit" tokens into their internal balance in the Vault, after which they can be used with minimal gas costs.
Access to user funds is performed in three ways:
- Direct ERC-20 approvals – Standard
approve
calls made directly to the GPv2VaultRelayer address (explained earlier) - External Balancer balances – Uses the user’s existing ERC-20 approvals for the Balancer Vault
- Internal Balancer balances – Uses internal balances in Balancer for gas-efficient transfers
Using External Balancer Balances:
Two independent levels of authorization are required:
1. Protocol level: GPv2VaultRelayer
is authorized in Balancer as an official relayer through a Balancer DAO vote (this has already been implemented at the protocol level).