Skip to content

Commit 1b780d2

Browse files
committed
Yul exception
1 parent 677e78f commit 1b780d2

File tree

2 files changed

+15
-71
lines changed

2 files changed

+15
-71
lines changed

src/Client.sol

Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,9 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
171171
);
172172

173173
/**
174-
* @notice Thrown if beneficiary claim extension expiration is insufficient
174+
* @notice Thrown if no allocation is found
175175
*/
176-
error InsufficientBeneficiaryClaimExtensionExpiration(
177-
CommonTypes.FilActorId provider, int64 claimExpiration, int64 requiredExpiration
178-
);
179-
180-
/**
181-
* @notice Thrown if no allocation or claim is found
182-
*/
183-
error NoAllocationOrClaim();
176+
error NoAllocationFound();
184177

185178
struct ProviderAllocation {
186179
CommonTypes.FilActorId provider;
@@ -191,7 +184,6 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
191184
struct ProviderClaim {
192185
CommonTypes.FilActorId provider;
193186
CommonTypes.FilActorId claim;
194-
int64 termMax;
195187
}
196188

197189
struct ClientDataUsage {
@@ -284,11 +276,10 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
284276
(
285277
ProviderAllocation[] memory allocations,
286278
ProviderClaim[] memory claimExtensions,
287-
ProviderAllocation memory longestAllocation,
288-
ProviderClaim memory longestClaimExtension
279+
ProviderAllocation memory longestAllocation
289280
) = _deserializeVerifregOperatorData(params.operator_data);
290281

291-
_verifyBeneficiaryExpiration(longestAllocation, longestClaimExtension);
282+
_verifyBeneficiaryExpiration(longestAllocation);
292283
_verifyAndRegisterAllocations(allocations);
293284
_verifyAndRegisterClaimExtensions(claimExtensions);
294285
emit DatacapSpent(msg.sender, datacapAmount);
@@ -394,34 +385,13 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
394385
/**
395386
* @notice Verifies that the beneficiary expiration is sufficient for the longest allocation.
396387
* @param longestAllocation The longest allocation.
397-
* @param longestClaimExtension The longest claim extension.
398388
* @dev Reverts with InsufficientBeneficiaryExpiration if the beneficiary expiration is insufficient.
399389
*/
400-
function _verifyBeneficiaryExpiration(
401-
ProviderAllocation memory longestAllocation,
402-
ProviderClaim memory longestClaimExtension
403-
) internal {
404-
MinerTypes.GetBeneficiaryReturn memory beneficiary;
405-
int64 beneficiaryExpiration;
406-
407-
if (longestClaimExtension.termMax != 0) {
408-
beneficiary = MinerUtils.getBeneficiaryWithChecks(
409-
longestClaimExtension.provider, beneficiaryFactory, true, true, true
410-
);
411-
int64 beneficiaryExpiration = CommonTypes.ChainEpoch.unwrap(beneficiary.active.term.expiration);
412-
413-
if (longestClaimExtension.termMax > beneficiaryExpiration + 250 weeks) {
414-
revert InsufficientBeneficiaryClaimExtensionExpiration(
415-
longestClaimExtension.provider, beneficiaryExpiration, longestClaimExtension.termMax
416-
);
417-
}
418-
return;
419-
}
420-
390+
function _verifyBeneficiaryExpiration(ProviderAllocation memory longestAllocation) internal view {
421391
if (longestAllocation.allocationTime != 0) {
422-
beneficiary =
392+
MinerTypes.GetBeneficiaryReturn memory beneficiary =
423393
MinerUtils.getBeneficiaryWithChecks(longestAllocation.provider, beneficiaryFactory, true, true, true);
424-
beneficiaryExpiration = CommonTypes.ChainEpoch.unwrap(beneficiary.active.term.expiration);
394+
int64 beneficiaryExpiration = CommonTypes.ChainEpoch.unwrap(beneficiary.active.term.expiration);
425395

426396
if (longestAllocation.allocationTime > beneficiaryExpiration + 180 days) {
427397
revert InsufficientBeneficiaryAllocationExpiration(
@@ -432,7 +402,7 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
432402
return;
433403
}
434404

435-
revert NoAllocationOrClaim();
405+
revert NoAllocationFound();
436406
}
437407

438408
// solhint-disable function-max-lines
@@ -442,22 +412,18 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
442412
* @return allocations Array of provider allocations.
443413
* @return claimExtensions Array of provider claims.
444414
* @return longestAllocation Allocation with the longest term.
445-
* @return longestClaimExtension Claim extension with the longest term.
446415
*/
447416
function _deserializeVerifregOperatorData(bytes memory cborData)
448417
internal
449418
pure
450419
returns (
451420
ProviderAllocation[] memory allocations,
452421
ProviderClaim[] memory claimExtensions,
453-
ProviderAllocation memory longestAllocation,
454-
ProviderClaim memory longestClaimExtension
422+
ProviderAllocation memory longestAllocation
455423
)
456424
{
457425
uint256 resultLength;
458426
uint64 provider;
459-
int64 termMax;
460-
int64 expiration;
461427
uint256 byteIdx = 0;
462428

463429
{
@@ -466,6 +432,8 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
466432
}
467433
{
468434
uint64 size;
435+
int64 termMax;
436+
int64 expiration;
469437
(resultLength, byteIdx) = CBORDecoder.readFixedArray(cborData, byteIdx);
470438
allocations = new ProviderAllocation[](resultLength);
471439
for (uint256 i = 0; i < resultLength; i++) {
@@ -494,7 +462,6 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
494462
}
495463
}
496464
}
497-
498465
{
499466
uint64 claimId;
500467
(resultLength, byteIdx) = CBORDecoder.readFixedArray(cborData, byteIdx);
@@ -509,15 +476,12 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
509476

510477
(provider, byteIdx) = CBORDecoder.readUInt64(cborData, byteIdx);
511478
(claimId, byteIdx) = CBORDecoder.readUInt64(cborData, byteIdx);
512-
(termMax, byteIdx) = CBORDecoder.readInt64(cborData, byteIdx);
479+
// slither-disable-start unused-return
480+
(, byteIdx) = CBORDecoder.readInt64(cborData, byteIdx);
481+
// slither-disable-end unused-return
513482

514483
claimExtensions[i].provider = CommonTypes.FilActorId.wrap(provider);
515484
claimExtensions[i].claim = CommonTypes.FilActorId.wrap(claimId);
516-
claimExtensions[i].termMax = termMax;
517-
518-
if (termMax > longestClaimExtension.termMax) {
519-
longestClaimExtension = claimExtensions[i];
520-
}
521485
}
522486
}
523487
}

test/Client.t.sol

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ contract ClientTest is Test {
590590
resolveAddress.setAddress(hex"00C2A101", uint64(20000));
591591
transferParams.operator_data = hex"828080";
592592
vm.prank(clientAddress);
593-
vm.expectRevert(abi.encodeWithSelector(Client.NoAllocationOrClaim.selector));
593+
vm.expectRevert(abi.encodeWithSelector(Client.NoAllocationFound.selector));
594594
client.transfer(transferParams);
595595
}
596596

@@ -619,24 +619,4 @@ contract ClientTest is Test {
619619
);
620620
client.transfer(transferParams);
621621
}
622-
623-
/**
624-
* allocations: []
625-
* claimExtensions: [{
626-
* provider: 20000,
627-
* termMax: 1250000000000
628-
* }]
629-
*/
630-
function testTransferRevertInsufficientExpirationForClaimExtension() public {
631-
resolveAddress.setId(address(this), uint64(20000));
632-
resolveAddress.setAddress(hex"00C2A101", uint64(20000));
633-
transferParams.operator_data = hex"82808183194E201927101B0000012309CE5400";
634-
vm.prank(clientAddress);
635-
vm.expectRevert(
636-
abi.encodeWithSelector(
637-
Client.InsufficientBeneficiaryClaimExtensionExpiration.selector, SP2, 6000000, 1250000000000
638-
)
639-
);
640-
client.transfer(transferParams);
641-
}
642622
}

0 commit comments

Comments
 (0)