From 41be496679a184bc1b549d8082cf4249f035e5c9 Mon Sep 17 00:00:00 2001 From: Abhivansh <31abhivanshj@gmail.com> Date: Thu, 30 Oct 2025 10:07:07 +0000 Subject: [PATCH 1/2] refactor: make challengeWindowSize public and deprecate the external function --- .../src/FilecoinWarmStorageService.sol | 2 +- .../FilecoinWarmStorageServiceStateView.sol | 4 --- .../lib/FilecoinWarmStorageServiceLayout.sol | 1 + ...WarmStorageServiceStateInternalLibrary.sol | 33 ++++++++++--------- ...FilecoinWarmStorageServiceStateLibrary.sol | 14 ++++---- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/service_contracts/src/FilecoinWarmStorageService.sol b/service_contracts/src/FilecoinWarmStorageService.sol index bfe88535..4289b225 100644 --- a/service_contracts/src/FilecoinWarmStorageService.sol +++ b/service_contracts/src/FilecoinWarmStorageService.sol @@ -246,7 +246,7 @@ contract FilecoinWarmStorageService is // Proving period constants - set during initialization uint64 private maxProvingPeriod; - uint256 private challengeWindowSize; + uint256 public challengeWindowSize; // Commission rate uint256 private serviceCommissionBps; diff --git a/service_contracts/src/FilecoinWarmStorageServiceStateView.sol b/service_contracts/src/FilecoinWarmStorageServiceStateView.sol index 211917b9..ae70d564 100644 --- a/service_contracts/src/FilecoinWarmStorageServiceStateView.sol +++ b/service_contracts/src/FilecoinWarmStorageServiceStateView.sol @@ -18,10 +18,6 @@ contract FilecoinWarmStorageServiceStateView is IPDPProvingSchedule { service = _service; } - function challengeWindow() external view returns (uint256) { - return service.challengeWindow(); - } - function clientDataSets(address payer) external view returns (uint256[] memory dataSetIds) { return service.clientDataSets(payer); } diff --git a/service_contracts/src/lib/FilecoinWarmStorageServiceLayout.sol b/service_contracts/src/lib/FilecoinWarmStorageServiceLayout.sol index fb8182af..be961412 100644 --- a/service_contracts/src/lib/FilecoinWarmStorageServiceLayout.sol +++ b/service_contracts/src/lib/FilecoinWarmStorageServiceLayout.sol @@ -27,3 +27,4 @@ bytes32 constant FIL_BEAM_CONTROLLER_ADDRESS_SLOT = bytes32(uint256(18)); bytes32 constant NEXT_UPGRADE_SLOT = bytes32(uint256(19)); bytes32 constant STORAGE_PRICE_PER_TIB_PER_MONTH_SLOT = bytes32(uint256(20)); bytes32 constant MINIMUM_STORAGE_RATE_PER_MONTH_SLOT = bytes32(uint256(21)); + diff --git a/service_contracts/src/lib/FilecoinWarmStorageServiceStateInternalLibrary.sol b/service_contracts/src/lib/FilecoinWarmStorageServiceStateInternalLibrary.sol index 8df5e514..27fe13bd 100644 --- a/service_contracts/src/lib/FilecoinWarmStorageServiceStateInternalLibrary.sol +++ b/service_contracts/src/lib/FilecoinWarmStorageServiceStateInternalLibrary.sol @@ -172,12 +172,12 @@ library FilecoinWarmStorageServiceStateInternalLibrary { returns (bool) { return uint256( - service.extsload( + service.extsload( keccak256( - abi.encode(periodId >> 8, keccak256(abi.encode(dataSetId, StorageLayout.PROVEN_PERIODS_SLOT))) - ) + abi.encode(periodId >> 8, keccak256(abi.encode(dataSetId, StorageLayout.PROVEN_PERIODS_SLOT))) + ) ) - ) & (1 << (periodId & 255)) != 0; + ) & (1 << (periodId & 255)) != 0; } function provingActivationEpoch(FilecoinWarmStorageService service, uint256 dataSetId) @@ -196,11 +196,11 @@ library FilecoinWarmStorageServiceStateInternalLibrary { return uint64(uint256(service.extsload(StorageLayout.MAX_PROVING_PERIOD_SLOT))); } - // Number of epochs at the end of a proving period during which a - // proof of possession can be submitted - function challengeWindow(FilecoinWarmStorageService service) internal view returns (uint256) { - return uint256(service.extsload(StorageLayout.CHALLENGE_WINDOW_SIZE_SLOT)); - } + // // Number of epochs at the end of a proving period during which a + // // proof of possession can be submitted + // function challengeWindow(FilecoinWarmStorageService service) internal view returns (uint256) { + // return uint256(service.extsload(StorageLayout.CHALLENGE_WINDOW_SIZE_SLOT)); + // } /** * @notice Returns PDP configuration values @@ -221,7 +221,7 @@ library FilecoinWarmStorageServiceStateInternalLibrary { ) { maxProvingPeriod = getMaxProvingPeriod(service); - challengeWindowSize = challengeWindow(service); + challengeWindowSize = service.challengeWindowSize(); challengesPerProof = CHALLENGES_PER_PROOF; initChallengeWindowStart = block.number + maxProvingPeriod - challengeWindowSize; } @@ -271,7 +271,7 @@ library FilecoinWarmStorageServiceStateInternalLibrary { { uint256 deadline = provingDeadline(service, setId); uint64 maxProvingPeriod = getMaxProvingPeriod(service); - uint256 challengeWindowSize = challengeWindow(service); + uint256 challengeWindowSize = service.challengeWindowSize(); uint256 periodsSkipped; // Proving period is open 0 skipped periods @@ -398,11 +398,12 @@ library FilecoinWarmStorageServiceStateInternalLibrary { * @return exists True if the key exists * @return value The metadata value */ - function getPieceMetadata(FilecoinWarmStorageService service, uint256 dataSetId, uint256 pieceId, string memory key) - internal - view - returns (bool exists, string memory value) - { + function getPieceMetadata( + FilecoinWarmStorageService service, + uint256 dataSetId, + uint256 pieceId, + string memory key + ) internal view returns (bool exists, string memory value) { // Check if key exists in the keys array string[] memory keys = getStringArray( service, diff --git a/service_contracts/src/lib/FilecoinWarmStorageServiceStateLibrary.sol b/service_contracts/src/lib/FilecoinWarmStorageServiceStateLibrary.sol index edd6a7d7..4a42ee37 100644 --- a/service_contracts/src/lib/FilecoinWarmStorageServiceStateLibrary.sol +++ b/service_contracts/src/lib/FilecoinWarmStorageServiceStateLibrary.sol @@ -192,11 +192,11 @@ library FilecoinWarmStorageServiceStateLibrary { return uint64(uint256(service.extsload(StorageLayout.MAX_PROVING_PERIOD_SLOT))); } - // Number of epochs at the end of a proving period during which a - // proof of possession can be submitted - function challengeWindow(FilecoinWarmStorageService service) public view returns (uint256) { - return uint256(service.extsload(StorageLayout.CHALLENGE_WINDOW_SIZE_SLOT)); - } + // // Number of epochs at the end of a proving period during which a + // // proof of possession can be submitted + // function challengeWindow(FilecoinWarmStorageService service) public view returns (uint256) { + // return uint256(service.extsload(StorageLayout.CHALLENGE_WINDOW_SIZE_SLOT)); + // } /** * @notice Returns PDP configuration values @@ -217,7 +217,7 @@ library FilecoinWarmStorageServiceStateLibrary { ) { maxProvingPeriod = getMaxProvingPeriod(service); - challengeWindowSize = challengeWindow(service); + challengeWindowSize = service.challengeWindowSize(); challengesPerProof = CHALLENGES_PER_PROOF; initChallengeWindowStart = block.number + maxProvingPeriod - challengeWindowSize; } @@ -267,7 +267,7 @@ library FilecoinWarmStorageServiceStateLibrary { { uint256 deadline = provingDeadline(service, setId); uint64 maxProvingPeriod = getMaxProvingPeriod(service); - uint256 challengeWindowSize = challengeWindow(service); + uint256 challengeWindowSize = service.challengeWindowSize(); uint256 periodsSkipped; // Proving period is open 0 skipped periods From 043767e994b8a8fa9f697a60d84e59a2acb32ed7 Mon Sep 17 00:00:00 2001 From: Abhivansh <31abhivanshj@gmail.com> Date: Thu, 30 Oct 2025 12:45:21 +0000 Subject: [PATCH 2/2] formatted code --- .../src/FilecoinWarmStorageService.sol | 31 +++++++++++++------ .../src/ServiceProviderRegistry.sol | 26 +++++----------- ...FilecoinWarmStorageServiceStateLibrary.sol | 19 ++++++------ .../src/lib/SignatureVerificationLib.sol | 5 +-- .../test/FilecoinWarmStorageService.t.sol | 12 +++---- service_contracts/test/ProductTypes.t.sol | 6 ++-- service_contracts/test/mocks/SharedMocks.sol | 5 ++- 7 files changed, 52 insertions(+), 52 deletions(-) diff --git a/service_contracts/src/FilecoinWarmStorageService.sol b/service_contracts/src/FilecoinWarmStorageService.sol index 4289b225..80fd8a5d 100644 --- a/service_contracts/src/FilecoinWarmStorageService.sol +++ b/service_contracts/src/FilecoinWarmStorageService.sol @@ -738,7 +738,10 @@ contract FilecoinWarmStorageService is uint256 dataSetId, uint256, // deletedLeafCount, - not used bytes calldata // extraData, - not used - ) external onlyPDPVerifier { + ) + external + onlyPDPVerifier + { // Verify the data set exists in our mapping DataSetInfo storage info = dataSetInfo[dataSetId]; require(info.pdpRailId != 0, Errors.DataSetNotRegistered(dataSetId)); @@ -903,7 +906,10 @@ contract FilecoinWarmStorageService is uint256, /*challengedLeafCount*/ uint256, /*seed*/ uint256 challengeCount - ) external onlyPDPVerifier { + ) + external + onlyPDPVerifier + { requirePaymentNotBeyondEndEpoch(dataSetId); if (provenThisPeriod[dataSetId]) { @@ -1021,7 +1027,11 @@ contract FilecoinWarmStorageService is address, // oldServiceProvider address, // newServiceProvider bytes calldata // extraData - not used - ) external override onlyPDPVerifier { + ) + external + override + onlyPDPVerifier + { revert("Storage provider changes are not yet supported"); } @@ -1535,7 +1545,12 @@ contract FilecoinWarmStorageService is uint256 fromEpoch, uint256 toEpoch, uint256 /* rate */ - ) external view override returns (ValidationResult memory result) { + ) + external + view + override + returns (ValidationResult memory result) + { // Get the data set ID associated with this rail uint256 dataSetId = railToDataSet[railId]; require(dataSetId != 0, Errors.RailNotAssociated(railId)); @@ -1548,9 +1563,7 @@ contract FilecoinWarmStorageService is uint256 activationEpoch = provingActivationEpoch[dataSetId]; if (activationEpoch == 0) { return ValidationResult({ - modifiedAmount: 0, - settleUpto: fromEpoch, - note: "Proving never activated for this data set" + modifiedAmount: 0, settleUpto: fromEpoch, note: "Proving never activated for this data set" }); } @@ -1561,9 +1574,7 @@ contract FilecoinWarmStorageService is // If no epochs are proven, we can't settle anything if (provenEpochCount == 0) { return ValidationResult({ - modifiedAmount: 0, - settleUpto: settleUpTo, - note: "No proven epochs in the requested range" + modifiedAmount: 0, settleUpto: settleUpTo, note: "No proven epochs in the requested range" }); } diff --git a/service_contracts/src/ServiceProviderRegistry.sol b/service_contracts/src/ServiceProviderRegistry.sol index 943f5339..c390b792 100644 --- a/service_contracts/src/ServiceProviderRegistry.sol +++ b/service_contracts/src/ServiceProviderRegistry.sol @@ -175,11 +175,7 @@ contract ServiceProviderRegistry is // Store provider info providers[providerId] = ServiceProviderInfo({ - serviceProvider: msg.sender, - payee: payee, - name: name, - description: description, - isActive: true + serviceProvider: msg.sender, payee: payee, name: name, description: description, isActive: true }); // Update address mapping @@ -265,9 +261,11 @@ contract ServiceProviderRegistry is /// @param productType The type of product to update /// @param capabilityKeys Array of capability keys (max 32 chars each, max 10 keys) /// @param capabilityValues Array of capability values (max 128 chars each, max 10 values) - function updateProduct(ProductType productType, string[] calldata capabilityKeys, bytes[] calldata capabilityValues) - external - { + function updateProduct( + ProductType productType, + string[] calldata capabilityKeys, + bytes[] calldata capabilityValues + ) external { // Only support PDP for now require(productType == ProductType.PDP, "Only PDP product type currently supported"); @@ -537,11 +535,7 @@ contract ServiceProviderRegistry is /// @notice Get provider info by address /// @param providerAddress The address of the service provider /// @return info The provider information (empty struct if not registered) - function getProviderByAddress(address providerAddress) - external - view - returns (ServiceProviderInfoView memory info) - { + function getProviderByAddress(address providerAddress) external view returns (ServiceProviderInfoView memory info) { uint256 providerId = addressToProviderId[providerAddress]; if (providerId == 0) { return _getEmptyProviderInfoView(); @@ -644,11 +638,7 @@ contract ServiceProviderRegistry is return ServiceProviderInfoView({ providerId: 0, info: ServiceProviderInfo({ - serviceProvider: address(0), - payee: address(0), - name: "", - description: "", - isActive: false + serviceProvider: address(0), payee: address(0), name: "", description: "", isActive: false }) }); } diff --git a/service_contracts/src/lib/FilecoinWarmStorageServiceStateLibrary.sol b/service_contracts/src/lib/FilecoinWarmStorageServiceStateLibrary.sol index 4a42ee37..b5f4cba1 100644 --- a/service_contracts/src/lib/FilecoinWarmStorageServiceStateLibrary.sol +++ b/service_contracts/src/lib/FilecoinWarmStorageServiceStateLibrary.sol @@ -168,12 +168,12 @@ library FilecoinWarmStorageServiceStateLibrary { returns (bool) { return uint256( - service.extsload( + service.extsload( keccak256( - abi.encode(periodId >> 8, keccak256(abi.encode(dataSetId, StorageLayout.PROVEN_PERIODS_SLOT))) - ) + abi.encode(periodId >> 8, keccak256(abi.encode(dataSetId, StorageLayout.PROVEN_PERIODS_SLOT))) + ) ) - ) & (1 << (periodId & 255)) != 0; + ) & (1 << (periodId & 255)) != 0; } function provingActivationEpoch(FilecoinWarmStorageService service, uint256 dataSetId) @@ -394,11 +394,12 @@ library FilecoinWarmStorageServiceStateLibrary { * @return exists True if the key exists * @return value The metadata value */ - function getPieceMetadata(FilecoinWarmStorageService service, uint256 dataSetId, uint256 pieceId, string memory key) - public - view - returns (bool exists, string memory value) - { + function getPieceMetadata( + FilecoinWarmStorageService service, + uint256 dataSetId, + uint256 pieceId, + string memory key + ) public view returns (bool exists, string memory value) { // Check if key exists in the keys array string[] memory keys = getStringArray( service, diff --git a/service_contracts/src/lib/SignatureVerificationLib.sol b/service_contracts/src/lib/SignatureVerificationLib.sol index 5c12fb2f..e17b12c2 100644 --- a/service_contracts/src/lib/SignatureVerificationLib.sol +++ b/service_contracts/src/lib/SignatureVerificationLib.sol @@ -70,8 +70,9 @@ library SignatureVerificationLib { string[] calldata keys, string[] calldata values ) public pure returns (bytes32 structHash) { - return - keccak256(abi.encode(CREATE_DATA_SET_TYPEHASH, clientDataSetId, payee, hashMetadataEntries(keys, values))); + return keccak256( + abi.encode(CREATE_DATA_SET_TYPEHASH, clientDataSetId, payee, hashMetadataEntries(keys, values)) + ); } function hashAllCids(Cids.Cid[] calldata pieceDataArray) internal pure returns (bytes32 cidHashesHash) { diff --git a/service_contracts/test/FilecoinWarmStorageService.t.sol b/service_contracts/test/FilecoinWarmStorageService.t.sol index 2e9433ac..444a6cd4 100644 --- a/service_contracts/test/FilecoinWarmStorageService.t.sol +++ b/service_contracts/test/FilecoinWarmStorageService.t.sol @@ -762,11 +762,7 @@ contract FilecoinWarmStorageServiceTest is MockFVMTest { // Create dataset with metadataKeys/metadataValues (string[] memory dsKeys, string[] memory dsValues) = _getSingleMetadataKV("label", "Test Data Set"); FilecoinWarmStorageService.DataSetCreateData memory createData = FilecoinWarmStorageService.DataSetCreateData({ - payer: client, - clientDataSetId: 0, - metadataKeys: dsKeys, - metadataValues: dsValues, - signature: FAKE_SIGNATURE + payer: client, clientDataSetId: 0, metadataKeys: dsKeys, metadataValues: dsValues, signature: FAKE_SIGNATURE }); bytes memory encodedCreateData = abi.encode( createData.payer, @@ -1629,7 +1625,11 @@ contract FilecoinWarmStorageServiceTest is MockFVMTest { * @param clientAddress The client address * @return The created data set ID */ - function createDataSetForServiceProviderTest(address provider, address clientAddress, string memory /*metadata*/ ) + function createDataSetForServiceProviderTest( + address provider, + address clientAddress, + string memory /*metadata*/ + ) internal returns (uint256) { diff --git a/service_contracts/test/ProductTypes.t.sol b/service_contracts/test/ProductTypes.t.sol index f8131861..9a365827 100644 --- a/service_contracts/test/ProductTypes.t.sol +++ b/service_contracts/test/ProductTypes.t.sol @@ -7,12 +7,10 @@ import {BloomSet16} from "../src/lib/BloomSet.sol"; contract ProductTypesTest is Test { function testPDPKeys() public pure { - uint256 expected = ( - BloomSet16.compressed("serviceURL") | BloomSet16.compressed("minPieceSizeInBytes") + uint256 expected = (BloomSet16.compressed("serviceURL") | BloomSet16.compressed("minPieceSizeInBytes") | BloomSet16.compressed("maxPieceSizeInBytes") | BloomSet16.compressed("storagePricePerTibPerDay") | BloomSet16.compressed("minProvingPeriodInEpochs") | BloomSet16.compressed("location") - | BloomSet16.compressed("paymentTokenAddress") - ); + | BloomSet16.compressed("paymentTokenAddress")); assertEq(expected, REQUIRED_PDP_KEYS); } } diff --git a/service_contracts/test/mocks/SharedMocks.sol b/service_contracts/test/mocks/SharedMocks.sol index 39e0b267..d33120c7 100644 --- a/service_contracts/test/mocks/SharedMocks.sol +++ b/service_contracts/test/mocks/SharedMocks.sol @@ -181,9 +181,8 @@ contract MockPDPVerifier { // Call the listener's storageProviderChanged function if (listenerAddr != address(0)) { - PDPListener(listenerAddr).storageProviderChanged( - dataSetId, oldServiceProvider, newServiceProvider, extraData - ); + PDPListener(listenerAddr) + .storageProviderChanged(dataSetId, oldServiceProvider, newServiceProvider, extraData); } emit DataSetServiceProviderChanged(dataSetId, oldServiceProvider, newServiceProvider);