Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

### Fixed

- `LibSignatureVerification.recoverSigner` reverts with `SignatureRecoveryFailed()` when a signature recovers to the zero address, so FWSS never looks up `address(0)` as a session key. `ServiceProviderRegistry` already rejected this case.

## [1.7.0] - SP Payee and Worker Rotation

This contract-stack release lets a storage provider rotate its worker and payee wallets without moving its data sets. It upgrades ServiceProviderRegistry and PDPVerifier alongside FilecoinWarmStorageService (FWSS); the proxy addresses do not change. Upgrade the contracts in this order on each network: ServiceProviderRegistry, then PDPVerifier, then FWSS.
Expand Down
5 changes: 5 additions & 0 deletions service_contracts/abi/Errors.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,11 @@
"name": "ServiceContractMustTerminateRail",
"inputs": []
},
{
"type": "error",
"name": "SignatureRecoveryFailed",
"inputs": []
},
{
"type": "error",
"name": "StorageProviderChangesNotSupported",
Expand Down
5 changes: 5 additions & 0 deletions service_contracts/abi/FilecoinWarmStorageService.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,11 @@
}
]
},
{
"type": "error",
"name": "SignatureRecoveryFailed",
"inputs": []
},
{
"type": "error",
"name": "TooManyMetadataKeys",
Expand Down
3 changes: 3 additions & 0 deletions service_contracts/src/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ library Errors {
/// @param v The actual v value provided
error UnsupportedSignatureV(uint8 v);

/// @notice Signature recovers to the zero address, i.e. to no signer
error SignatureRecoveryFailed();

/// @notice The epoch range is invalid
/// @notice Will be emitted if any of the following conditions is NOT met:
/// @notice 1. fromEpoch must be less than toEpoch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ interface IFilecoinWarmStorageService is IFilecoinServiceMetadata, IPDPProvingSc
error ProvingPeriodPassed(uint256 dataSetId, uint256 deadline, uint256 nowBlock);
error RailNotFullySettled(uint256 railId, uint256 settledUpTo, uint256 endEpoch);
error ServiceContractMustTerminateRail();
error SignatureRecoveryFailed();
error StorageProviderChangesNotSupported();
error StorageTermsNotEnabled(bytes32 storageTermsId);
error TooManyMetadataKeys(uint256 maxAllowed, uint256 keysLength);
Expand Down
6 changes: 4 additions & 2 deletions service_contracts/src/lib/LibSignatureVerification.sol
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ library LibSignatureVerification {

require(v == 27 || v == 28, Errors.UnsupportedSignatureV(originalV));

// Recover and return the address
return ecrecover(messageHash, v, r, s);
// ecrecover returns address(0) for a signature that recovers to no key
address signer = ecrecover(messageHash, v, r, s);
require(signer != address(0), Errors.SignatureRecoveryFailed());
return signer;
}

// ============================================================================
Expand Down
42 changes: 42 additions & 0 deletions service_contracts/test/FilecoinWarmStorageService.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5076,6 +5076,15 @@ contract SignatureCheckingService {
function doRecoverSigner(bytes32 messageHash, bytes memory signature) public pure returns (address) {
return LibSignatureVerification.recoverSigner(messageHash, signature);
}

function doVerifyCreateDataSetSignature(
address payer,
bytes memory signature,
bytes32 digest,
SessionKeyRegistry sessionKeyRegistry
) public view {
LibSignatureVerification.verifyCreateDataSetSignature(payer, signature, digest, sessionKeyRegistry);
}
}

contract FilecoinWarmStorageServiceSignatureTest is Test {
Expand Down Expand Up @@ -5185,6 +5194,39 @@ contract FilecoinWarmStorageServiceSignatureTest is Test {
vm.expectRevert(abi.encodeWithSelector(Errors.UnsupportedSignatureV.selector, 25));
pdpService.doRecoverSigner(messageHash, invalidSignature);
}

// ecrecover returns address(0) for a well-formed signature that recovers to no key.
bytes private constant ZERO_RECOVERING_SIGNATURE = abi.encodePacked(bytes32(0), bytes32(0), uint8(27));

function testRecoverSignerRejectsZeroAddress() public {
vm.expectRevert(Errors.SignatureRecoveryFailed.selector);
pdpService.doRecoverSigner(keccak256(abi.encode(42)), ZERO_RECOVERING_SIGNATURE);
}

function testVerifyRejectsZeroSignerEvenWhenPayerAuthorizedIt() public {
bytes32[] memory permissions = new bytes32[](1);
permissions[0] = LibSignatureVerification.CREATE_DATA_SET_TYPEHASH;
vm.prank(payer);
sessionKeyRegistry.login(address(0), type(uint256).max, permissions, "test");

vm.expectRevert(Errors.SignatureRecoveryFailed.selector);
pdpService.doVerifyCreateDataSetSignature(
payer, ZERO_RECOVERING_SIGNATURE, keccak256(abi.encode(42)), sessionKeyRegistry
);
}

function testVerifyAcceptsPayerAndAuthorizedSessionKey() public {
bytes32 digest = keccak256(abi.encode(42));
(uint8 v, bytes32 r, bytes32 s) = vm.sign(payerPrivateKey, digest);
pdpService.doVerifyCreateDataSetSignature(payer, abi.encodePacked(r, s, v), digest, sessionKeyRegistry);

bytes32[] memory permissions = new bytes32[](1);
permissions[0] = LibSignatureVerification.CREATE_DATA_SET_TYPEHASH;
vm.prank(payer);
sessionKeyRegistry.login(wrongSigner, type(uint256).max, permissions, "test");
(v, r, s) = vm.sign(wrongSignerPrivateKey, digest);
pdpService.doVerifyCreateDataSetSignature(payer, abi.encodePacked(r, s, v), digest, sessionKeyRegistry);
}
}

// Test contract for upgrade scenarios
Expand Down
Loading