@rev-net/core-v6 0.0.35 → 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RISKS.md +19 -1
- package/package.json +9 -9
- package/src/REVDeployer.sol +19 -10
- package/src/REVLoans.sol +138 -89
- package/src/REVOwner.sol +6 -4
- package/test/REV.integrations.t.sol +14 -14
- package/test/REVInvincibility.t.sol +16 -16
- package/test/REVLifecycle.t.sol +32 -32
- package/test/REVLoansSourced.t.sol +15 -15
- package/test/TestCashOutCallerValidation.t.sol +8 -8
- package/test/TestConversionDocumentation.t.sol +2 -5
- package/test/TestCrossCurrencyReclaim.t.sol +72 -72
- package/test/TestLongTailEconomics.t.sol +56 -56
- package/test/TestSwapTerminalPermission.t.sol +21 -21
- package/test/audit/HiddenSupplyCashout.t.sol +61 -0
- package/test/audit/NemesisVerification.t.sol +97 -0
- package/test/audit/REVOwnerCurrencyMismatch.t.sol +188 -0
- package/test/audit/REVOwnerRemoteSurplusCurrencyMismatch.t.sol +140 -0
- package/test/audit/ReallocatePermission.t.sol +363 -0
- package/test/audit/RemoteLoanAccountingGap.t.sol +74 -0
- package/test/audit/SupportsInterfaceTest.t.sol +51 -0
- package/test/audit/TestFeeAllowanceLeak.t.sol +197 -0
- package/test/audit/TestLoansAndDeployerFixes.t.sol +576 -0
- package/test/fork/TestCashOutFork.t.sol +48 -48
- package/test/fork/TestLoanAdversarialFork.t.sol +744 -0
- package/test/fork/TestLoanERC20Fork.t.sol +2 -8
- package/test/fork/TestPermit2PaymentFork.t.sol +32 -32
- package/test/regression/TestBurnPermissionRequired.t.sol +5 -5
- package/test/regression/TestCashOutBuybackFeeLeak.t.sol +8 -8
- /package/test/audit/{CodexCrossChainBuybackRouteMismatch.t.sol → CrossChainBuybackRouteMismatch.t.sol} +0 -0
- /package/test/audit/{NemesisOperatorDelegation.t.sol → OperatorDelegation.t.sol} +0 -0
- /package/test/audit/{CodexPhantomSurplusTerminal.t.sol → PhantomSurplusTerminal.t.sol} +0 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.28;
|
|
3
|
+
|
|
4
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
5
|
+
import "forge-std/Test.sol";
|
|
6
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
7
|
+
import /* {*} from */ "@bananapus/core-v6/test/helpers/TestBaseWorkflow.sol";
|
|
8
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
9
|
+
import /* {*} from */ "../../src/REVDeployer.sol";
|
|
10
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
11
|
+
import "@croptop/core-v6/src/CTPublisher.sol";
|
|
12
|
+
import {MockBuybackDataHook} from "../mock/MockBuybackDataHook.sol";
|
|
13
|
+
import {REVEmpty721Config} from "../helpers/REVEmpty721Config.sol";
|
|
14
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
15
|
+
import "@bananapus/core-v6/script/helpers/CoreDeploymentLib.sol";
|
|
16
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
17
|
+
import "@bananapus/721-hook-v6/script/helpers/Hook721DeploymentLib.sol";
|
|
18
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
19
|
+
import "@bananapus/suckers-v6/script/helpers/SuckerDeploymentLib.sol";
|
|
20
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
21
|
+
import "@croptop/core-v6/script/helpers/CroptopDeploymentLib.sol";
|
|
22
|
+
// forge-lint: disable-next-line(unaliased-plain-import)
|
|
23
|
+
import "@bananapus/router-terminal-v6/script/helpers/RouterTerminalDeploymentLib.sol";
|
|
24
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
25
|
+
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
26
|
+
import {JBPermissioned} from "@bananapus/core-v6/src/abstract/JBPermissioned.sol";
|
|
27
|
+
import {JBPermissionIds} from "@bananapus/permission-ids-v6/src/JBPermissionIds.sol";
|
|
28
|
+
import {JBPermissionsData} from "@bananapus/core-v6/src/structs/JBPermissionsData.sol";
|
|
29
|
+
import {REVLoans} from "../../src/REVLoans.sol";
|
|
30
|
+
import {REVLoan} from "../../src/structs/REVLoan.sol";
|
|
31
|
+
import {REVStageConfig, REVAutoIssuance} from "../../src/structs/REVStageConfig.sol";
|
|
32
|
+
import {REVLoanSource} from "../../src/structs/REVLoanSource.sol";
|
|
33
|
+
import {REVDescription} from "../../src/structs/REVDescription.sol";
|
|
34
|
+
import {IREVLoans} from "../../src/interfaces/IREVLoans.sol";
|
|
35
|
+
import {JBSuckerDeployerConfig} from "@bananapus/suckers-v6/src/structs/JBSuckerDeployerConfig.sol";
|
|
36
|
+
import {JBSuckerRegistry} from "@bananapus/suckers-v6/src/JBSuckerRegistry.sol";
|
|
37
|
+
import {JB721TiersHookDeployer} from "@bananapus/721-hook-v6/src/JB721TiersHookDeployer.sol";
|
|
38
|
+
import {JB721TiersHook} from "@bananapus/721-hook-v6/src/JB721TiersHook.sol";
|
|
39
|
+
import {JB721TiersHookStore} from "@bananapus/721-hook-v6/src/JB721TiersHookStore.sol";
|
|
40
|
+
import {JB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/JB721CheckpointsDeployer.sol";
|
|
41
|
+
import {IJB721CheckpointsDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721CheckpointsDeployer.sol";
|
|
42
|
+
import {JBAddressRegistry} from "@bananapus/address-registry-v6/src/JBAddressRegistry.sol";
|
|
43
|
+
import {IJBAddressRegistry} from "@bananapus/address-registry-v6/src/interfaces/IJBAddressRegistry.sol";
|
|
44
|
+
import {REVOwner} from "../../src/REVOwner.sol";
|
|
45
|
+
import {IREVDeployer} from "../../src/interfaces/IREVDeployer.sol";
|
|
46
|
+
import {MockSuckerRegistry} from "../mock/MockSuckerRegistry.sol";
|
|
47
|
+
|
|
48
|
+
/// @notice Verify that reallocateCollateralFromLoan works with only REALLOCATE_LOAN permission,
|
|
49
|
+
/// without requiring OPEN_LOAN. Also verify that borrowFrom still requires OPEN_LOAN (regression).
|
|
50
|
+
contract ReallocatePermissionTest is TestBaseWorkflow {
|
|
51
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
52
|
+
bytes32 REV_DEPLOYER_SALT = "REVDeployer";
|
|
53
|
+
|
|
54
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
55
|
+
REVDeployer REV_DEPLOYER;
|
|
56
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
57
|
+
REVOwner REV_OWNER;
|
|
58
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
59
|
+
JB721TiersHook EXAMPLE_HOOK;
|
|
60
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
61
|
+
IJB721TiersHookDeployer HOOK_DEPLOYER;
|
|
62
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
63
|
+
IJB721TiersHookStore HOOK_STORE;
|
|
64
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
65
|
+
IJBAddressRegistry ADDRESS_REGISTRY;
|
|
66
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
67
|
+
IREVLoans LOANS_CONTRACT;
|
|
68
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
69
|
+
IJBSuckerRegistry SUCKER_REGISTRY;
|
|
70
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
71
|
+
CTPublisher PUBLISHER;
|
|
72
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
73
|
+
MockBuybackDataHook MOCK_BUYBACK;
|
|
74
|
+
|
|
75
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
76
|
+
uint256 FEE_PROJECT_ID;
|
|
77
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
78
|
+
uint256 REVNET_ID;
|
|
79
|
+
|
|
80
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
81
|
+
address HOLDER = makeAddr("holder");
|
|
82
|
+
// forge-lint: disable-next-line(mixed-case-variable)
|
|
83
|
+
address OPERATOR = makeAddr("operator");
|
|
84
|
+
|
|
85
|
+
address private constant TRUSTED_FORWARDER = 0xB2b5841DBeF766d4b521221732F9B618fCf34A87;
|
|
86
|
+
|
|
87
|
+
function setUp() public override {
|
|
88
|
+
super.setUp();
|
|
89
|
+
|
|
90
|
+
FEE_PROJECT_ID = jbProjects().createFor(multisig());
|
|
91
|
+
SUCKER_REGISTRY = new JBSuckerRegistry(jbDirectory(), jbPermissions(), multisig(), address(0));
|
|
92
|
+
HOOK_STORE = new JB721TiersHookStore();
|
|
93
|
+
EXAMPLE_HOOK = new JB721TiersHook(
|
|
94
|
+
jbDirectory(),
|
|
95
|
+
jbPermissions(),
|
|
96
|
+
jbPrices(),
|
|
97
|
+
jbRulesets(),
|
|
98
|
+
HOOK_STORE,
|
|
99
|
+
jbSplits(),
|
|
100
|
+
IJB721CheckpointsDeployer(address(new JB721CheckpointsDeployer())),
|
|
101
|
+
multisig()
|
|
102
|
+
);
|
|
103
|
+
ADDRESS_REGISTRY = new JBAddressRegistry();
|
|
104
|
+
HOOK_DEPLOYER = new JB721TiersHookDeployer(EXAMPLE_HOOK, HOOK_STORE, ADDRESS_REGISTRY, multisig());
|
|
105
|
+
PUBLISHER = new CTPublisher(jbDirectory(), jbPermissions(), FEE_PROJECT_ID, multisig());
|
|
106
|
+
MOCK_BUYBACK = new MockBuybackDataHook();
|
|
107
|
+
|
|
108
|
+
LOANS_CONTRACT = new REVLoans({
|
|
109
|
+
controller: jbController(),
|
|
110
|
+
suckerRegistry: IJBSuckerRegistry(address(new MockSuckerRegistry())),
|
|
111
|
+
revId: FEE_PROJECT_ID,
|
|
112
|
+
owner: address(this),
|
|
113
|
+
permit2: permit2(),
|
|
114
|
+
trustedForwarder: TRUSTED_FORWARDER
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
REV_OWNER = new REVOwner(
|
|
118
|
+
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
119
|
+
jbDirectory(),
|
|
120
|
+
FEE_PROJECT_ID,
|
|
121
|
+
SUCKER_REGISTRY,
|
|
122
|
+
address(LOANS_CONTRACT),
|
|
123
|
+
address(0)
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
REV_DEPLOYER = new REVDeployer{salt: REV_DEPLOYER_SALT}(
|
|
127
|
+
jbController(),
|
|
128
|
+
SUCKER_REGISTRY,
|
|
129
|
+
FEE_PROJECT_ID,
|
|
130
|
+
HOOK_DEPLOYER,
|
|
131
|
+
PUBLISHER,
|
|
132
|
+
IJBBuybackHookRegistry(address(MOCK_BUYBACK)),
|
|
133
|
+
address(LOANS_CONTRACT),
|
|
134
|
+
TRUSTED_FORWARDER,
|
|
135
|
+
address(REV_OWNER)
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
REV_OWNER.setDeployer(REV_DEPLOYER);
|
|
139
|
+
|
|
140
|
+
vm.prank(multisig());
|
|
141
|
+
jbProjects().approve(address(REV_DEPLOYER), FEE_PROJECT_ID);
|
|
142
|
+
|
|
143
|
+
_deployFeeProject();
|
|
144
|
+
_deployRevnet();
|
|
145
|
+
|
|
146
|
+
vm.deal(HOLDER, 1000 ether);
|
|
147
|
+
vm.deal(OPERATOR, 100 ether);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function _deployFeeProject() internal {
|
|
151
|
+
JBAccountingContext[] memory acc = new JBAccountingContext[](1);
|
|
152
|
+
acc[0] = JBAccountingContext({
|
|
153
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
154
|
+
});
|
|
155
|
+
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
156
|
+
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
157
|
+
|
|
158
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
159
|
+
splits[0].beneficiary = payable(multisig());
|
|
160
|
+
splits[0].percent = 10_000;
|
|
161
|
+
|
|
162
|
+
REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
|
|
163
|
+
ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
164
|
+
|
|
165
|
+
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
166
|
+
stages[0] = REVStageConfig({
|
|
167
|
+
startsAtOrAfter: uint40(block.timestamp),
|
|
168
|
+
autoIssuances: ai,
|
|
169
|
+
splitPercent: 2000,
|
|
170
|
+
splits: splits,
|
|
171
|
+
initialIssuance: uint112(1000e18),
|
|
172
|
+
issuanceCutFrequency: 90 days,
|
|
173
|
+
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
174
|
+
cashOutTaxRate: 6000,
|
|
175
|
+
extraMetadata: 0
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
REVConfig memory cfg = REVConfig({
|
|
179
|
+
description: REVDescription("Revnet", "$REV", "ipfs://test", "REV_TOKEN"),
|
|
180
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
181
|
+
splitOperator: multisig(),
|
|
182
|
+
stageConfigurations: stages
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
vm.prank(multisig());
|
|
186
|
+
REV_DEPLOYER.deployFor({
|
|
187
|
+
revnetId: FEE_PROJECT_ID,
|
|
188
|
+
configuration: cfg,
|
|
189
|
+
terminalConfigurations: tc,
|
|
190
|
+
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
191
|
+
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("FEE")
|
|
192
|
+
}),
|
|
193
|
+
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
194
|
+
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function _deployRevnet() internal {
|
|
199
|
+
JBAccountingContext[] memory acc = new JBAccountingContext[](1);
|
|
200
|
+
acc[0] = JBAccountingContext({
|
|
201
|
+
token: JBConstants.NATIVE_TOKEN, decimals: 18, currency: uint32(uint160(JBConstants.NATIVE_TOKEN))
|
|
202
|
+
});
|
|
203
|
+
JBTerminalConfig[] memory tc = new JBTerminalConfig[](1);
|
|
204
|
+
tc[0] = JBTerminalConfig({terminal: jbMultiTerminal(), accountingContextsToAccept: acc});
|
|
205
|
+
|
|
206
|
+
JBSplit[] memory splits = new JBSplit[](1);
|
|
207
|
+
splits[0].beneficiary = payable(multisig());
|
|
208
|
+
splits[0].percent = 10_000;
|
|
209
|
+
|
|
210
|
+
REVAutoIssuance[] memory ai = new REVAutoIssuance[](1);
|
|
211
|
+
ai[0] = REVAutoIssuance({chainId: uint32(block.chainid), count: uint104(70_000e18), beneficiary: multisig()});
|
|
212
|
+
|
|
213
|
+
REVStageConfig[] memory stages = new REVStageConfig[](1);
|
|
214
|
+
stages[0] = REVStageConfig({
|
|
215
|
+
startsAtOrAfter: uint40(block.timestamp),
|
|
216
|
+
autoIssuances: ai,
|
|
217
|
+
splitPercent: 2000,
|
|
218
|
+
splits: splits,
|
|
219
|
+
initialIssuance: uint112(1000e18),
|
|
220
|
+
issuanceCutFrequency: 90 days,
|
|
221
|
+
issuanceCutPercent: JBConstants.MAX_WEIGHT_CUT_PERCENT / 2,
|
|
222
|
+
cashOutTaxRate: 6000,
|
|
223
|
+
extraMetadata: 0
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
REVConfig memory cfg = REVConfig({
|
|
227
|
+
description: REVDescription("NANA", "$NANA", "ipfs://test2", "NANA_TOKEN"),
|
|
228
|
+
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
|
|
229
|
+
splitOperator: multisig(),
|
|
230
|
+
stageConfigurations: stages
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
(REVNET_ID,) = REV_DEPLOYER.deployFor({
|
|
234
|
+
revnetId: 0,
|
|
235
|
+
configuration: cfg,
|
|
236
|
+
terminalConfigurations: tc,
|
|
237
|
+
suckerDeploymentConfiguration: REVSuckerDeploymentConfig({
|
|
238
|
+
deployerConfigurations: new JBSuckerDeployerConfig[](0), salt: keccak256("NANA")
|
|
239
|
+
}),
|
|
240
|
+
tiered721HookConfiguration: REVEmpty721Config.empty721Config(uint32(uint160(JBConstants.NATIVE_TOKEN))),
|
|
241
|
+
allowedPosts: REVEmpty721Config.emptyAllowedPosts()
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/// @notice Helper: Grant a specific permission to an operator for HOLDER on REVNET_ID using real JBPermissions.
|
|
246
|
+
function _grantPermission(address operator, uint256 permissionId) internal {
|
|
247
|
+
uint8[] memory permissionIds = new uint8[](1);
|
|
248
|
+
permissionIds[0] = uint8(permissionId);
|
|
249
|
+
vm.prank(HOLDER);
|
|
250
|
+
jbPermissions()
|
|
251
|
+
.setPermissionsFor({
|
|
252
|
+
account: HOLDER,
|
|
253
|
+
permissionsData: JBPermissionsData({
|
|
254
|
+
operator: operator, projectId: uint64(REVNET_ID), permissionIds: permissionIds
|
|
255
|
+
})
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/// @notice Helper: create an initial loan for the HOLDER.
|
|
260
|
+
function _createInitialLoan() internal returns (uint256 loanId, uint256 tokenCount) {
|
|
261
|
+
// HOLDER pays into the revnet to get tokens.
|
|
262
|
+
vm.prank(HOLDER);
|
|
263
|
+
tokenCount =
|
|
264
|
+
jbMultiTerminal().pay{value: 10 ether}(REVNET_ID, JBConstants.NATIVE_TOKEN, 10 ether, HOLDER, 0, "", "");
|
|
265
|
+
|
|
266
|
+
// Grant LOANS_CONTRACT the BURN_TOKENS permission so it can burn HOLDER's tokens as collateral.
|
|
267
|
+
_grantPermission(address(LOANS_CONTRACT), JBPermissionIds.BURN_TOKENS);
|
|
268
|
+
|
|
269
|
+
// HOLDER calls borrowFrom directly (sender == holder, so OPEN_LOAN check is short-circuited).
|
|
270
|
+
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
271
|
+
|
|
272
|
+
vm.prank(HOLDER);
|
|
273
|
+
(loanId,) = LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, tokenCount, payable(HOLDER), 25, HOLDER);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/// @notice After fix: an operator with only REALLOCATE_LOAN permission can reallocate.
|
|
277
|
+
/// @dev Before the fix, this would revert because the inner borrowFrom call required OPEN_LOAN.
|
|
278
|
+
function test_reallocate_succeeds_with_only_REALLOCATE_LOAN_permission() public {
|
|
279
|
+
(uint256 loanId,) = _createInitialLoan();
|
|
280
|
+
require(loanId != 0, "Loan setup failed");
|
|
281
|
+
|
|
282
|
+
// Donate to inflate surplus so collateral reallocation is meaningful.
|
|
283
|
+
address donor = makeAddr("donor");
|
|
284
|
+
vm.deal(donor, 500 ether);
|
|
285
|
+
vm.prank(donor);
|
|
286
|
+
jbMultiTerminal().addToBalanceOf{value: 500 ether}(
|
|
287
|
+
REVNET_ID, JBConstants.NATIVE_TOKEN, 500 ether, false, "", ""
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
// HOLDER pays more to get extra tokens for the new loan's additional collateral.
|
|
291
|
+
vm.prank(HOLDER);
|
|
292
|
+
uint256 extraTokens =
|
|
293
|
+
jbMultiTerminal().pay{value: 50 ether}(REVNET_ID, JBConstants.NATIVE_TOKEN, 50 ether, HOLDER, 0, "", "");
|
|
294
|
+
|
|
295
|
+
// Get the loan's collateral count.
|
|
296
|
+
REVLoan memory loan = LOANS_CONTRACT.loanOf(loanId);
|
|
297
|
+
uint256 collateralToTransfer = loan.collateral / 10;
|
|
298
|
+
|
|
299
|
+
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
300
|
+
|
|
301
|
+
// Grant OPERATOR only REALLOCATE_LOAN permission (NOT OPEN_LOAN).
|
|
302
|
+
_grantPermission(OPERATOR, JBPermissionIds.REALLOCATE_LOAN);
|
|
303
|
+
|
|
304
|
+
// This should succeed: OPERATOR has REALLOCATE_LOAN, and _borrowFrom skips OPEN_LOAN check.
|
|
305
|
+
vm.prank(OPERATOR);
|
|
306
|
+
(uint256 reallocatedLoanId, uint256 newLoanId,,) = LOANS_CONTRACT.reallocateCollateralFromLoan(
|
|
307
|
+
loanId,
|
|
308
|
+
collateralToTransfer,
|
|
309
|
+
source,
|
|
310
|
+
0, // minBorrowAmount
|
|
311
|
+
extraTokens,
|
|
312
|
+
payable(HOLDER),
|
|
313
|
+
25 // prepaidFeePercent
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
// Verify both loans were created.
|
|
317
|
+
assertTrue(reallocatedLoanId != 0, "Reallocated loan should exist");
|
|
318
|
+
assertTrue(newLoanId != 0, "New loan should exist");
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/// @notice Regression: borrowFrom still requires OPEN_LOAN permission.
|
|
322
|
+
/// @dev An operator with only REALLOCATE_LOAN should NOT be able to call borrowFrom directly.
|
|
323
|
+
function test_borrowFrom_still_requires_OPEN_LOAN() public {
|
|
324
|
+
// HOLDER pays into the revnet.
|
|
325
|
+
vm.prank(HOLDER);
|
|
326
|
+
uint256 tokenCount =
|
|
327
|
+
jbMultiTerminal().pay{value: 10 ether}(REVNET_ID, JBConstants.NATIVE_TOKEN, 10 ether, HOLDER, 0, "", "");
|
|
328
|
+
|
|
329
|
+
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
330
|
+
|
|
331
|
+
// OPERATOR does NOT have OPEN_LOAN permission (no permission granted at all).
|
|
332
|
+
vm.prank(OPERATOR);
|
|
333
|
+
vm.expectRevert(
|
|
334
|
+
abi.encodeWithSelector(
|
|
335
|
+
JBPermissioned.JBPermissioned_Unauthorized.selector,
|
|
336
|
+
HOLDER, // account
|
|
337
|
+
OPERATOR, // sender
|
|
338
|
+
REVNET_ID, // projectId
|
|
339
|
+
JBPermissionIds.OPEN_LOAN // permissionId
|
|
340
|
+
)
|
|
341
|
+
);
|
|
342
|
+
LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, tokenCount, payable(HOLDER), 25, HOLDER);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/// @notice Verify that borrowFrom succeeds when the caller has OPEN_LOAN permission.
|
|
346
|
+
function test_borrowFrom_succeeds_with_OPEN_LOAN() public {
|
|
347
|
+
// HOLDER pays into the revnet.
|
|
348
|
+
vm.prank(HOLDER);
|
|
349
|
+
uint256 tokenCount =
|
|
350
|
+
jbMultiTerminal().pay{value: 10 ether}(REVNET_ID, JBConstants.NATIVE_TOKEN, 10 ether, HOLDER, 0, "", "");
|
|
351
|
+
|
|
352
|
+
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
353
|
+
|
|
354
|
+
// Grant OPERATOR the OPEN_LOAN permission.
|
|
355
|
+
_grantPermission(OPERATOR, JBPermissionIds.OPEN_LOAN);
|
|
356
|
+
// Grant LOANS_CONTRACT the BURN_TOKENS permission so it can burn tokens for collateral.
|
|
357
|
+
_grantPermission(address(LOANS_CONTRACT), JBPermissionIds.BURN_TOKENS);
|
|
358
|
+
|
|
359
|
+
vm.prank(OPERATOR);
|
|
360
|
+
(uint256 loanId,) = LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, tokenCount, payable(HOLDER), 25, HOLDER);
|
|
361
|
+
assertTrue(loanId != 0, "Loan should be created successfully");
|
|
362
|
+
}
|
|
363
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.28;
|
|
3
|
+
|
|
4
|
+
import {TestAuditFixVerification} from "../TestAuditFixVerification.t.sol";
|
|
5
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
6
|
+
import {JBCashOuts} from "@bananapus/core-v6/src/libraries/JBCashOuts.sol";
|
|
7
|
+
import {JBPermissionIds} from "@bananapus/permission-ids-v6/src/JBPermissionIds.sol";
|
|
8
|
+
import {JBPermissionsData} from "@bananapus/core-v6/src/structs/JBPermissionsData.sol";
|
|
9
|
+
import {REVLoanSource} from "../../src/structs/REVLoanSource.sol";
|
|
10
|
+
import {REVLoan} from "../../src/structs/REVLoan.sol";
|
|
11
|
+
|
|
12
|
+
contract CodexRemoteLoanAccountingGap is TestAuditFixVerification {
|
|
13
|
+
function test_remoteLoanStateInflatesLocalBorrowability() public {
|
|
14
|
+
uint256 payAmount = 100 ether;
|
|
15
|
+
|
|
16
|
+
vm.prank(USER);
|
|
17
|
+
uint256 tokens =
|
|
18
|
+
jbMultiTerminal().pay{value: payAmount}(REVNET_ID, JBConstants.NATIVE_TOKEN, payAmount, USER, 0, "", "");
|
|
19
|
+
|
|
20
|
+
// Simulate a peer chain that started from 100 ETH / 100k tokens, then originated a loan against
|
|
21
|
+
// 50k burned-collateral tokens. The registry only exports the raw post-loan values, not the
|
|
22
|
+
// remote loan's economic adjustments.
|
|
23
|
+
uint256 remoteRawSupply = 50_000e18;
|
|
24
|
+
uint256 remoteRawSurplus = 62.5e18;
|
|
25
|
+
uint256 remoteLoanCollateral = 50_000e18;
|
|
26
|
+
uint256 remoteLoanDebt = 37.5e18;
|
|
27
|
+
MOCK_SUCKER_REGISTRY.setRemoteValues(remoteRawSupply, remoteRawSurplus);
|
|
28
|
+
|
|
29
|
+
uint256 collateral = tokens / 10;
|
|
30
|
+
uint256 actualBorrowable =
|
|
31
|
+
LOANS_CONTRACT.borrowableAmountFrom(REVNET_ID, collateral, 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
32
|
+
|
|
33
|
+
uint256 localSupply = jbController().totalTokenSupplyWithReservedTokensOf(REVNET_ID);
|
|
34
|
+
uint256 localSurplus = jbMultiTerminal()
|
|
35
|
+
.currentSurplusOf(REVNET_ID, new address[](0), 18, uint32(uint160(JBConstants.NATIVE_TOKEN)));
|
|
36
|
+
|
|
37
|
+
uint256 correctedBorrowable = JBCashOuts.cashOutFrom({
|
|
38
|
+
surplus: localSurplus + remoteRawSurplus + remoteLoanDebt,
|
|
39
|
+
cashOutCount: collateral,
|
|
40
|
+
totalSupply: localSupply + remoteRawSupply + remoteLoanCollateral,
|
|
41
|
+
cashOutTaxRate: 5000
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (correctedBorrowable > localSurplus) correctedBorrowable = localSurplus;
|
|
45
|
+
|
|
46
|
+
assertGt(actualBorrowable, correctedBorrowable, "raw remote values should overstate borrowability");
|
|
47
|
+
|
|
48
|
+
_grantLoansBurnPermission(USER, REVNET_ID);
|
|
49
|
+
|
|
50
|
+
REVLoanSource memory source = REVLoanSource({token: JBConstants.NATIVE_TOKEN, terminal: jbMultiTerminal()});
|
|
51
|
+
|
|
52
|
+
vm.prank(USER);
|
|
53
|
+
(, REVLoan memory loan) =
|
|
54
|
+
LOANS_CONTRACT.borrowFrom(REVNET_ID, source, actualBorrowable, collateral, payable(USER), 25, USER);
|
|
55
|
+
|
|
56
|
+
assertEq(loan.amount, actualBorrowable, "loan should be opened at the inflated amount");
|
|
57
|
+
assertGt(loan.amount, correctedBorrowable, "loan exceeds the corrected omnichain value");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function _grantLoansBurnPermission(address account, uint256 revnetId) internal {
|
|
61
|
+
uint8[] memory permissionIds = new uint8[](1);
|
|
62
|
+
permissionIds[0] = JBPermissionIds.BURN_TOKENS;
|
|
63
|
+
|
|
64
|
+
JBPermissionsData memory permissionsData = JBPermissionsData({
|
|
65
|
+
operator: address(LOANS_CONTRACT),
|
|
66
|
+
// forge-lint: disable-next-line(unsafe-typecast)
|
|
67
|
+
projectId: uint56(revnetId),
|
|
68
|
+
permissionIds: permissionIds
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
vm.prank(account);
|
|
72
|
+
jbPermissions().setPermissionsFor(account, permissionsData);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.28;
|
|
3
|
+
|
|
4
|
+
import {Test} from "forge-std/Test.sol";
|
|
5
|
+
import {IJBBuybackHookRegistry} from "@bananapus/buyback-hook-v6/src/interfaces/IJBBuybackHookRegistry.sol";
|
|
6
|
+
import {IJBCashOutHook} from "@bananapus/core-v6/src/interfaces/IJBCashOutHook.sol";
|
|
7
|
+
import {IJBDirectory} from "@bananapus/core-v6/src/interfaces/IJBDirectory.sol";
|
|
8
|
+
import {IJBRulesetDataHook} from "@bananapus/core-v6/src/interfaces/IJBRulesetDataHook.sol";
|
|
9
|
+
import {IJBSuckerRegistry} from "@bananapus/suckers-v6/src/interfaces/IJBSuckerRegistry.sol";
|
|
10
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
11
|
+
|
|
12
|
+
import {REVOwner} from "../../src/REVOwner.sol";
|
|
13
|
+
|
|
14
|
+
/// @notice Regression test for missing IERC165 support: REVOwner.supportsInterface omits IERC165.
|
|
15
|
+
contract AuditFixL17Test is Test {
|
|
16
|
+
REVOwner revOwner;
|
|
17
|
+
|
|
18
|
+
function setUp() public {
|
|
19
|
+
revOwner = new REVOwner(
|
|
20
|
+
IJBBuybackHookRegistry(makeAddr("buybackHook")),
|
|
21
|
+
IJBDirectory(makeAddr("directory")),
|
|
22
|
+
1, // feeRevnetId
|
|
23
|
+
IJBSuckerRegistry(makeAddr("suckerRegistry")),
|
|
24
|
+
makeAddr("loans"),
|
|
25
|
+
makeAddr("hiddenTokens")
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// @notice supportsInterface returns true for IERC165 (0x01ffc9a7).
|
|
30
|
+
function test_supportsInterface_IERC165() public view {
|
|
31
|
+
assertTrue(revOwner.supportsInterface(type(IERC165).interfaceId), "should support IERC165");
|
|
32
|
+
assertEq(type(IERC165).interfaceId, bytes4(0x01ffc9a7), "IERC165 interface ID should be 0x01ffc9a7");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/// @notice supportsInterface returns true for IJBRulesetDataHook.
|
|
36
|
+
function test_supportsInterface_IJBRulesetDataHook() public view {
|
|
37
|
+
assertTrue(
|
|
38
|
+
revOwner.supportsInterface(type(IJBRulesetDataHook).interfaceId), "should support IJBRulesetDataHook"
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/// @notice supportsInterface returns true for IJBCashOutHook.
|
|
43
|
+
function test_supportsInterface_IJBCashOutHook() public view {
|
|
44
|
+
assertTrue(revOwner.supportsInterface(type(IJBCashOutHook).interfaceId), "should support IJBCashOutHook");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// @notice supportsInterface returns false for an unsupported interface.
|
|
48
|
+
function test_supportsInterface_unsupported() public view {
|
|
49
|
+
assertFalse(revOwner.supportsInterface(bytes4(0xdeadbeef)), "should not support random interface");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity 0.8.28;
|
|
3
|
+
|
|
4
|
+
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
5
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
6
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
7
|
+
import {IJBDirectory} from "@bananapus/core-v6/src/interfaces/IJBDirectory.sol";
|
|
8
|
+
import {IJBTerminal} from "@bananapus/core-v6/src/interfaces/IJBTerminal.sol";
|
|
9
|
+
import {IJBPayoutTerminal} from "@bananapus/core-v6/src/interfaces/IJBPayoutTerminal.sol";
|
|
10
|
+
import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
|
|
11
|
+
import {JBConstants} from "@bananapus/core-v6/src/libraries/JBConstants.sol";
|
|
12
|
+
import {JBRuleset} from "@bananapus/core-v6/src/structs/JBRuleset.sol";
|
|
13
|
+
import {JBPayHookSpecification} from "@bananapus/core-v6/src/structs/JBPayHookSpecification.sol";
|
|
14
|
+
import {REVLoanSource} from "../../src/structs/REVLoanSource.sol";
|
|
15
|
+
import {REVLoansFeeRecovery} from "../REVLoansFeeRecovery.t.sol";
|
|
16
|
+
|
|
17
|
+
contract StickyAllowanceFeeTerminal is ERC165, IJBPayoutTerminal {
|
|
18
|
+
IERC20 public immutable token;
|
|
19
|
+
address public immutable loans;
|
|
20
|
+
address public thief;
|
|
21
|
+
uint256 public stealAmount;
|
|
22
|
+
|
|
23
|
+
constructor(IERC20 _token, address _loans) {
|
|
24
|
+
token = _token;
|
|
25
|
+
loans = _loans;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function configureSteal(address _thief, uint256 _stealAmount) external {
|
|
29
|
+
thief = _thief;
|
|
30
|
+
stealAmount = _stealAmount;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function pay(
|
|
34
|
+
uint256,
|
|
35
|
+
address,
|
|
36
|
+
uint256,
|
|
37
|
+
address,
|
|
38
|
+
uint256,
|
|
39
|
+
string calldata,
|
|
40
|
+
bytes calldata
|
|
41
|
+
)
|
|
42
|
+
external
|
|
43
|
+
payable
|
|
44
|
+
override
|
|
45
|
+
returns (uint256)
|
|
46
|
+
{
|
|
47
|
+
uint256 amount = stealAmount;
|
|
48
|
+
if (amount != 0) {
|
|
49
|
+
stealAmount = 0;
|
|
50
|
+
token.transferFrom(loans, thief, amount);
|
|
51
|
+
}
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function accountingContextForTokenOf(uint256, address) external view override returns (JBAccountingContext memory) {
|
|
56
|
+
return JBAccountingContext({token: address(token), decimals: 6, currency: uint32(uint160(address(token)))});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function accountingContextsOf(uint256) external pure override returns (JBAccountingContext[] memory) {
|
|
60
|
+
return new JBAccountingContext[](0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function addAccountingContextsFor(uint256, JBAccountingContext[] calldata) external override {}
|
|
64
|
+
|
|
65
|
+
function addToBalanceOf(
|
|
66
|
+
uint256,
|
|
67
|
+
address,
|
|
68
|
+
uint256,
|
|
69
|
+
bool,
|
|
70
|
+
string calldata,
|
|
71
|
+
bytes calldata
|
|
72
|
+
)
|
|
73
|
+
external
|
|
74
|
+
payable
|
|
75
|
+
override
|
|
76
|
+
{}
|
|
77
|
+
|
|
78
|
+
function currentSurplusOf(uint256, address[] calldata, uint256, uint256) external pure override returns (uint256) {
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function migrateBalanceOf(uint256, address, IJBTerminal) external pure override returns (uint256) {
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function sendPayoutsOf(uint256, address, uint256, uint256, uint256) external pure override returns (uint256) {
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function useAllowanceOf(
|
|
91
|
+
uint256,
|
|
92
|
+
address,
|
|
93
|
+
uint256,
|
|
94
|
+
uint256,
|
|
95
|
+
uint256,
|
|
96
|
+
address payable,
|
|
97
|
+
address payable,
|
|
98
|
+
string calldata
|
|
99
|
+
)
|
|
100
|
+
external
|
|
101
|
+
pure
|
|
102
|
+
override
|
|
103
|
+
returns (uint256)
|
|
104
|
+
{
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function previewPayFor(
|
|
109
|
+
uint256,
|
|
110
|
+
address,
|
|
111
|
+
uint256,
|
|
112
|
+
address,
|
|
113
|
+
bytes calldata
|
|
114
|
+
)
|
|
115
|
+
external
|
|
116
|
+
pure
|
|
117
|
+
override
|
|
118
|
+
returns (JBRuleset memory, uint256, uint256, JBPayHookSpecification[] memory)
|
|
119
|
+
{
|
|
120
|
+
JBRuleset memory ruleset;
|
|
121
|
+
return (ruleset, 0, 0, new JBPayHookSpecification[](0));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function supportsInterface(bytes4 interfaceId) public view override(ERC165, IERC165) returns (bool) {
|
|
125
|
+
return interfaceId == type(IJBTerminal).interfaceId || interfaceId == type(IJBPayoutTerminal).interfaceId
|
|
126
|
+
|| super.supportsInterface(interfaceId);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
contract TestFeeAllowanceLeak is REVLoansFeeRecovery {
|
|
131
|
+
StickyAllowanceFeeTerminal internal stickyFeeTerminal;
|
|
132
|
+
address internal attacker = makeAddr("attacker");
|
|
133
|
+
|
|
134
|
+
function _stickyFeeTerminal() internal returns (StickyAllowanceFeeTerminal) {
|
|
135
|
+
if (address(stickyFeeTerminal) == address(0)) {
|
|
136
|
+
stickyFeeTerminal = new StickyAllowanceFeeTerminal(TOKEN, address(LOANS_CONTRACT));
|
|
137
|
+
}
|
|
138
|
+
return stickyFeeTerminal;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/// @notice Verifies that stale allowance is cleared — the original exploit no longer works.
|
|
142
|
+
/// @dev Previously, a sticky fee terminal could accumulate reusable allowance across borrows.
|
|
143
|
+
/// After the fix (_afterTransferTo clears allowance on success), the allowance is zero.
|
|
144
|
+
function test_feeTerminalCannotHarvestStaleAllowanceAfterFix() public {
|
|
145
|
+
StickyAllowanceFeeTerminal terminal = _stickyFeeTerminal();
|
|
146
|
+
|
|
147
|
+
vm.mockCall(
|
|
148
|
+
address(jbDirectory()),
|
|
149
|
+
abi.encodeWithSelector(IJBDirectory.primaryTerminalOf.selector, FEE_PROJECT_ID, address(TOKEN)),
|
|
150
|
+
abi.encode(address(terminal))
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
REVLoanSource memory source = REVLoanSource({token: address(TOKEN), terminal: jbMultiTerminal()});
|
|
154
|
+
uint256 payAmount = 1_000_000;
|
|
155
|
+
|
|
156
|
+
deal(address(TOKEN), USER, payAmount * 2);
|
|
157
|
+
|
|
158
|
+
vm.startPrank(USER);
|
|
159
|
+
TOKEN.approve(address(jbMultiTerminal()), payAmount * 2);
|
|
160
|
+
uint256 firstTokenCount = jbMultiTerminal().pay(REVNET_ID, address(TOKEN), payAmount, USER, 0, "", "");
|
|
161
|
+
vm.stopPrank();
|
|
162
|
+
|
|
163
|
+
_mockLoanPermission(USER);
|
|
164
|
+
vm.prank(USER);
|
|
165
|
+
LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, firstTokenCount, payable(USER), 25, USER);
|
|
166
|
+
|
|
167
|
+
// Allowance is now cleared after successful fee payment.
|
|
168
|
+
uint256 allowanceAfterBorrow = TOKEN.allowance(address(LOANS_CONTRACT), address(stickyFeeTerminal));
|
|
169
|
+
assertEq(allowanceAfterBorrow, 0, "no stale allowance after successful borrow");
|
|
170
|
+
|
|
171
|
+
// The uncollected fee is still parked in REVLoans (terminal didn't pull it),
|
|
172
|
+
// but there's no allowance for the terminal to steal it later.
|
|
173
|
+
uint256 loansBalance = TOKEN.balanceOf(address(LOANS_CONTRACT));
|
|
174
|
+
assertGt(loansBalance, 0, "uncollected fee is parked in REVLoans");
|
|
175
|
+
|
|
176
|
+
// Second borrow — terminal tries to steal but can't because allowance is 0.
|
|
177
|
+
vm.prank(USER);
|
|
178
|
+
uint256 secondTokenCount = jbMultiTerminal().pay(REVNET_ID, address(TOKEN), payAmount, USER, 0, "", "");
|
|
179
|
+
|
|
180
|
+
terminal.configureSteal(attacker, loansBalance);
|
|
181
|
+
|
|
182
|
+
_mockLoanPermission(USER);
|
|
183
|
+
vm.prank(USER);
|
|
184
|
+
LOANS_CONTRACT.borrowFrom(REVNET_ID, source, 0, secondTokenCount, payable(USER), 25, USER);
|
|
185
|
+
|
|
186
|
+
// The attacker gets nothing — the steal attempt fails silently (transferFrom reverts,
|
|
187
|
+
// caught by _tryPayFee's try-catch).
|
|
188
|
+
assertEq(TOKEN.balanceOf(attacker), 0, "attacker cannot drain stale allowance");
|
|
189
|
+
|
|
190
|
+
// And the current borrow also leaves zero allowance.
|
|
191
|
+
assertEq(
|
|
192
|
+
TOKEN.allowance(address(LOANS_CONTRACT), address(terminal)),
|
|
193
|
+
0,
|
|
194
|
+
"no fresh stale allowance after second borrow"
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|