-
Notifications
You must be signed in to change notification settings - Fork 62
/
readonly_reentrancy_test.sol
60 lines (48 loc) · 1.91 KB
/
readonly_reentrancy_test.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import {VaultReentrancyLib} from "@balancer-labs/v2-pool-utils/contracts/lib/VaultReentrancyLib.sol";
import "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol";
interface IBalancerPool {
function getRate() external view returns (uint);
}
contract BalancerIntegration {
address balancerVault;
constructor() {}
function getPriceVulnerable(address vault) public returns (uint) {
return IBalancerPool(vault).getRate();
}
function getPriceVulnerable2(address vault) public {
bytes32 poolId = "0x123";
uint256[] memory balances = new uint256[](10);
(, balances, ) = IVault(balancerVault).getPoolTokens(poolId);
}
function _ensureNotReentrant() internal {
VaultReentrancyLib.ensureNotInVaultContext(IVault(balancerVault));
}
function _ensureNotReentrant2() internal {
IVault(balancerVault).manageUserBalance(new IVault.UserBalanceOp[](0));
}
function getPriceOk(address vault) public returns (uint) {
VaultReentrancyLib.ensureNotInVaultContext(IVault(balancerVault));
return IBalancerPool(vault).getRate();
}
function getPriceOk2(address vault) public returns (uint) {
_ensureNotReentrant();
return IBalancerPool(vault).getRate();
}
function getPriceOk3(address vault) public returns (uint) {
_ensureNotReentrant2();
return IBalancerPool(vault).getRate();
}
function getPriceOk4(address vault) public returns (uint) {
uint a = IBalancerPool(vault).getRate();
_ensureNotReentrant2();
return a;
}
function getPriceOk5(address vault) public {
VaultReentrancyLib.ensureNotInVaultContext(IVault(balancerVault));
bytes32 poolId = "0x123";
uint256[] memory balances = new uint256[](10);
(, balances, ) = IVault(balancerVault).getPoolTokens(poolId);
}
}