diff --git a/snapshots/TheCompactTest.json b/snapshots/TheCompactTest.json index 91e4836..c95050d 100644 --- a/snapshots/TheCompactTest.json +++ b/snapshots/TheCompactTest.json @@ -1,17 +1,17 @@ { "basicTransfer": "56850", "basicWithdrawal": "59816", - "batchClaim": "111783", - "batchClaimRegisteredWithDeposit": "111783", - "batchClaimRegisteredWithDepositWithWitness": "112651", - "batchClaimWithWitness": "112645", + "batchClaim": "111810", + "batchClaimRegisteredWithDeposit": "111810", + "batchClaimRegisteredWithDepositWithWitness": "112675", + "batchClaimWithWitness": "112669", "batchDepositAndRegisterViaPermit2": "221877", "batchDepositAndRegisterWithWitnessViaPermit2": "221855", "batchTransfer": "81520", "batchWithdrawal": "99951", - "claim": "56784", - "claimAndWithdraw": "73083", - "claimWithWitness": "59432", + "claim": "56817", + "claimAndWithdraw": "73116", + "claimWithWitness": "59462", "depositAndRegisterViaPermit2": "124247", "depositBatchSingleERC20": "67868", "depositBatchSingleNative": "28171", @@ -22,21 +22,21 @@ "depositERC20ViaPermit2AndURI": "98289", "depositETHAndURI": "26754", "depositETHBasic": "28391", - "qualifiedBatchClaim": "113318", - "qualifiedBatchClaimWithWitness": "112858", - "qualifiedClaim": "60196", - "qualifiedClaimWithWitness": "58885", - "qualifiedSplitBatchClaim": "140892", - "qualifiedSplitBatchClaimWithWitness": "140960", - "qualifiedSplitClaim": "86521", - "qualifiedSplitClaimWithWitness": "86998", + "qualifiedBatchClaim": "113348", + "qualifiedBatchClaimWithWitness": "112885", + "qualifiedClaim": "60238", + "qualifiedClaimWithWitness": "58927", + "qualifiedSplitBatchClaim": "140922", + "qualifiedSplitBatchClaimWithWitness": "140987", + "qualifiedSplitClaim": "86554", + "qualifiedSplitClaimWithWitness": "87031", "register": "25379", - "splitBatchClaim": "140237", - "splitBatchClaimWithWitness": "140307", + "splitBatchClaim": "140264", + "splitBatchClaimWithWitness": "140331", "splitBatchTransfer": "110587", "splitBatchWithdrawal": "139819", - "splitClaim": "86242", - "splitClaimWithWitness": "85906", + "splitClaim": "86275", + "splitClaimWithWitness": "85936", "splitTransfer": "82732", "splitWithdrawal": "93702" } \ No newline at end of file diff --git a/src/lib/ClaimProcessorLib.sol b/src/lib/ClaimProcessorLib.sol index b95980e..e891ffc 100644 --- a/src/lib/ClaimProcessorLib.sol +++ b/src/lib/ClaimProcessorLib.sol @@ -2,21 +2,382 @@ pragma solidity ^0.8.27; import { COMPACT_TYPEHASH, BATCH_COMPACT_TYPEHASH, MULTICHAIN_COMPACT_TYPEHASH } from "../types/EIP712Types.sol"; -import { SplitComponent } from "../types/Components.sol"; -import { Scope } from "../types/Scope.sol"; +import { SplitComponent, BatchClaimComponent, SplitBatchClaimComponent } from "../types/Components.sol"; import { EfficiencyLib } from "./EfficiencyLib.sol"; +import { EventLib } from "./EventLib.sol"; import { IdLib } from "./IdLib.sol"; +import { RegistrationLib } from "./RegistrationLib.sol"; +import { ValidityLib } from "./ValidityLib.sol"; /** * @title ClaimProcessorLib * @notice Library contract implementing internal functions with helper logic for * processing claims against a signed or registered compact. + * @dev IMPORTANT NOTE: logic for processing claims assumes that the utilized structs are + * formatted in a very specific manner — if parameters are rearranged or new parameters + * are inserted, much of this functionality will break. Proceed with caution when making + * any changes. */ library ClaimProcessorLib { using ClaimProcessorLib for uint256; + using ClaimProcessorLib for bytes32; + using ClaimProcessorLib for SplitComponent[]; using EfficiencyLib for bool; + using EfficiencyLib for uint256; + using EfficiencyLib for bytes32; + using EventLib for address; using IdLib for uint256; + using ValidityLib for uint256; + using ValidityLib for uint96; + using ValidityLib for bytes32; + using RegistrationLib for address; + + /** + * @notice Internal function for validating claim execution parameters. Extracts and validates + * signatures from calldata, checks expiration, verifies allocator registration, consumes the + * nonce, derives the domain separator, and validates both the sponsor authorization (either + * through direct registration or a provided signature or EIP-1271 call) and the (potentially + * qualified) allocator authorization. Finally, emits a Claim event. + * @param messageHash The EIP-712 hash of the claim message. + * @param allocatorId The unique identifier for the allocator mediating the claim. + * @param qualificationMessageHash The EIP-712 hash of the allocator's qualification message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param domainSeparator The local domain separator. + * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. + * @param typehash The EIP-712 typehash used for the claim message. + * @return sponsor The extracted address of the claim sponsor. + */ + function validate(bytes32 messageHash, uint96 allocatorId, bytes32 qualificationMessageHash, uint256 calldataPointer, bytes32 domainSeparator, bytes32 sponsorDomainSeparator, bytes32 typehash) + internal + returns (address sponsor) + { + // Declare variables for signatures and parameters that will be extracted from calldata. + bytes calldata allocatorSignature; + bytes calldata sponsorSignature; + uint256 nonce; + uint256 expires; + + assembly ("memory-safe") { + // Extract allocator signature from calldata using offset stored at calldataPointer. + let allocatorSignaturePtr := add(calldataPointer, calldataload(calldataPointer)) + allocatorSignature.offset := add(0x20, allocatorSignaturePtr) + allocatorSignature.length := calldataload(allocatorSignaturePtr) + + // Extract sponsor signature from calldata using offset stored at calldataPointer + 0x20. + let sponsorSignaturePtr := add(calldataPointer, calldataload(add(calldataPointer, 0x20))) + sponsorSignature.offset := add(0x20, sponsorSignaturePtr) + sponsorSignature.length := calldataload(sponsorSignaturePtr) + + // Extract sponsor address, sanitizing upper 96 bits. + sponsor := shr(96, shl(96, calldataload(add(calldataPointer, 0x40)))) + + // Extract nonce and expiration timestamp. + nonce := calldataload(add(calldataPointer, 0x60)) + expires := calldataload(add(calldataPointer, 0x80)) + } + + // Ensure that the claim hasn't expired. + expires.later(); + + // Retrieve allocator address and consume nonce, ensuring it has not already been consumed. + address allocator = allocatorId.fromRegisteredAllocatorIdWithConsumed(nonce); + + assembly ("memory-safe") { + // Swap domain separator for provided sponsorDomainSeparator if a nonzero value was supplied. + sponsorDomainSeparator := add(sponsorDomainSeparator, mul(iszero(sponsorDomainSeparator), domainSeparator)) + } + + // Validate sponsor authorization through either ECDSA, EIP-1271, or direct registration. + if ((sponsorDomainSeparator != domainSeparator).or(sponsorSignature.length != 0) || sponsor.hasNoActiveRegistration(messageHash, typehash)) { + messageHash.signedBy(sponsor, sponsorSignature, sponsorDomainSeparator); + } + + // Validate allocator authorization against qualification message. + qualificationMessageHash.signedBy(allocator, allocatorSignature, domainSeparator); + + // Emit claim event. + sponsor.emitClaim(messageHash, allocator); + } + + /** + * @notice Internal function for processing qualified claims with potentially exogenous + * sponsor signatures. Extracts claim parameters from calldata, validates the scope, + * ensures the claimed amount is within the allocated amount, validates the claim, + * and executes either a release of ERC6909 tokens or a withdrawal of underlying tokens. + * @param messageHash The EIP-712 hash of the claim message. + * @param qualificationMessageHash The EIP-712 hash of the allocator's qualification message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the claim was successfully processed. + */ + function processClaimWithQualificationAndSponsorDomain( + bytes32 messageHash, + bytes32 qualificationMessageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 sponsorDomainSeparator, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + // Declare variables for parameters that will be extracted from calldata. + uint256 id; + uint256 allocatedAmount; + address claimant; + uint256 amount; + + assembly ("memory-safe") { + // Calculate pointer to claim parameters using provided offset. + let calldataPointerWithOffset := add(calldataPointer, offsetToId) + + // Extract resource lock id, allocated amount, claimant address, and claim amount. + id := calldataload(calldataPointerWithOffset) + allocatedAmount := calldataload(add(calldataPointerWithOffset, 0x20)) + claimant := shr(96, shl(96, calldataload(add(calldataPointerWithOffset, 0x40)))) + amount := calldataload(add(calldataPointerWithOffset, 0x60)) + } + + // Verify the resource lock scope is compatible with the provided domain separator. + sponsorDomainSeparator.ensureValidScope(id); + + // Ensure the claimed amount does not exceed the allocated amount. + amount.withinAllocated(allocatedAmount); + + // Validate the claim and execute the specified operation (either release or withdraw). + return operation(messageHash.validate(id.toAllocatorId(), qualificationMessageHash, calldataPointer, domainSeparator, sponsorDomainSeparator, typehash), claimant, id, amount); + } + + /** + * @notice Internal function for processing qualified split claims with potentially exogenous + * sponsor signatures. Extracts claim parameters from calldata, validates the claim, + * validates the scope, and executes either releases of ERC6909 tokens or withdrawals of + * underlying tokens to multiple recipients. + * @param messageHash The EIP-712 hash of the claim message. + * @param qualificationMessageHash The EIP-712 hash of the allocator's qualification message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the split claim was successfully processed. + */ + function processSplitClaimWithQualificationAndSponsorDomain( + bytes32 messageHash, + bytes32 qualificationMessageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 sponsorDomainSeparator, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + // Declare variables for parameters that will be extracted from calldata. + uint256 id; + uint256 allocatedAmount; + SplitComponent[] calldata components; + + assembly ("memory-safe") { + // Calculate pointer to claim parameters using provided offset. + let calldataPointerWithOffset := add(calldataPointer, offsetToId) + + // Extract resource lock id and allocated amount. + id := calldataload(calldataPointerWithOffset) + allocatedAmount := calldataload(add(calldataPointerWithOffset, 0x20)) + + // Extract array of split components containing claimant addresses and amounts. + let componentsPtr := add(calldataPointer, calldataload(add(calldataPointerWithOffset, 0x40))) + components.offset := add(0x20, componentsPtr) + components.length := calldataload(componentsPtr) + } + + // Validate the claim and extract the sponsor address. + address sponsor = messageHash.validate(id.toAllocatorId(), qualificationMessageHash, calldataPointer, domainSeparator, sponsorDomainSeparator, typehash); + + // Verify the resource lock scope is compatible with the provided domain separator. + sponsorDomainSeparator.ensureValidScope(id); + + // Process each split component, verifying total amount and executing operations. + return components.verifyAndProcessSplitComponents(sponsor, id, allocatedAmount, operation); + } + + /** + * @notice Internal function for processing qualified batch claims with potentially exogenous + * sponsor signatures. Extracts batch claim parameters from calldata, validates the claim, + * executes operations, and performs optimized validation of allocator consistency, amounts, + * and scopes. If any validation fails, all operations are reverted after explicitly + * identifying the specific validation failures. + * @param messageHash The EIP-712 hash of the claim message. + * @param qualificationMessageHash The EIP-712 hash of the allocator's qualification message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the batch claim was successfully processed. + */ + function processBatchClaimWithQualificationAndSponsorDomain( + bytes32 messageHash, + bytes32 qualificationMessageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 sponsorDomainSeparator, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + // Declare variables for parameters that will be extracted from calldata. + BatchClaimComponent[] calldata claims; + address claimant; + + assembly ("memory-safe") { + // Calculate pointer to claim parameters using provided offset. + let calldataPointerWithOffset := add(calldataPointer, offsetToId) + + // Extract array of batch claim components and claimant address. + let claimsPtr := add(calldataPointer, calldataload(calldataPointerWithOffset)) + claims.offset := add(0x20, claimsPtr) + claims.length := calldataload(claimsPtr) + claimant := calldataload(add(calldataPointerWithOffset, 0x20)) + } + + // Extract allocator id from first claim for validation. + uint96 firstAllocatorId = claims[0].id.toAllocatorId(); + + // Validate the claim and extract the sponsor address. + address sponsor = messageHash.validate(firstAllocatorId, qualificationMessageHash, calldataPointer, domainSeparator, sponsorDomainSeparator, typehash); + + // Revert if the batch is empty. + uint256 totalClaims = claims.length; + assembly ("memory-safe") { + if iszero(totalClaims) { + // revert InvalidBatchAllocation() + mstore(0, 0x3a03d3bb) + revert(0x1c, 0x04) + } + } + + // Process first claim and initialize error tracking. + // NOTE: many of the bounds checks on these array accesses can be skipped as an optimization + BatchClaimComponent calldata component = claims[0]; + uint256 id = component.id; + uint256 amount = component.amount; + uint256 errorBuffer = component.allocatedAmount.allocationExceededOrScopeNotMultichain(amount, id, sponsorDomainSeparator).asUint256(); + + // Execute transfer or withdrawal for first claim. + operation(sponsor, claimant, id, amount); + + unchecked { + // Process remaining claims while accumulating potential errors. + for (uint256 i = 1; i < totalClaims; ++i) { + component = claims[i]; + id = component.id; + amount = component.amount; + errorBuffer |= (id.toAllocatorId() != firstAllocatorId).or(component.allocatedAmount.allocationExceededOrScopeNotMultichain(amount, id, sponsorDomainSeparator)).asUint256(); + + operation(sponsor, claimant, id, amount); + } + + // If any errors occurred, identify specific failures and revert. + if (errorBuffer.asBool()) { + for (uint256 i = 0; i < totalClaims; ++i) { + component = claims[i]; + component.amount.withinAllocated(component.allocatedAmount); + id = component.id; + sponsorDomainSeparator.ensureValidScope(component.id); + } + + assembly ("memory-safe") { + // revert InvalidBatchAllocation() + mstore(0, 0x3a03d3bb) + revert(0x1c, 0x04) + } + } + } + + return true; + } + + /** + * @notice Internal function for processing qualified split batch claims with potentially + * exogenous sponsor signatures. Extracts split batch claim parameters from calldata, + * validates the claim, and executes split operations for each resource lock. Uses optimized + * validation of allocator consistency and scopes, with explicit validation on failure to + * identify specific issues. Each resource lock can be split among multiple recipients. + * @param messageHash The EIP-712 hash of the claim message. + * @param qualificationMessageHash The EIP-712 hash of the allocator's qualification message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the split batch claim was successfully processed. + */ + function processSplitBatchClaimWithQualificationAndSponsorDomain( + bytes32 messageHash, + bytes32 qualificationMessageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 sponsorDomainSeparator, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + // Declare variable for SplitBatchClaimComponent array that will be extracted from calldata. + SplitBatchClaimComponent[] calldata claims; + + assembly ("memory-safe") { + // Extract array of split batch claim components. + let claimsPtr := add(calldataPointer, calldataload(add(calldataPointer, offsetToId))) + claims.offset := add(0x20, claimsPtr) + claims.length := calldataload(claimsPtr) + } + + // Extract allocator id from first claim for validation. + uint96 firstAllocatorId = claims[0].id.toAllocatorId(); + + // Validate the claim and extract the sponsor address. + address sponsor = messageHash.validate(firstAllocatorId, qualificationMessageHash, calldataPointer, domainSeparator, sponsorDomainSeparator, typehash); + + // Initialize tracking variables. + uint256 totalClaims = claims.length; + uint256 errorBuffer = (totalClaims == 0).asUint256(); + uint256 id; + + unchecked { + // Process each claim component while accumulating potential errors. + for (uint256 i = 0; i < totalClaims; ++i) { + SplitBatchClaimComponent calldata claimComponent = claims[i]; + id = claimComponent.id; + errorBuffer |= (id.toAllocatorId() != firstAllocatorId).or(id.scopeNotMultichain(sponsorDomainSeparator)).asUint256(); + + // Process each split component, verifying total amount and executing operations. + claimComponent.portions.verifyAndProcessSplitComponents(sponsor, id, claimComponent.allocatedAmount, operation); + } + + // If any errors occurred, identify specific scope failures and revert. + if (errorBuffer.asBool()) { + for (uint256 i = 0; i < totalClaims; ++i) { + sponsorDomainSeparator.ensureValidScope(claims[i].id); + } + + assembly ("memory-safe") { + // revert InvalidBatchAllocation() + mstore(0, 0x3a03d3bb) + revert(0x1c, 0x04) + } + } + } + + return true; + } /** * @notice Internal function for verifying and processing split components. Ensures that the @@ -74,22 +435,309 @@ library ClaimProcessorLib { } /** - * @notice Internal pure function for validating that a resource lock's scope is compatible - * with the provided sponsor domain separator. Reverts if an exogenous claim (indicated by - * a non-zero sponsor domain separator) attempts to claim against a chain-specific resource - * lock (indicated by the most significant bit of the id). - * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. - * @param id The ERC6909 token identifier of the resource lock. + * @notice Internal function for processing simple claims with local domain signatures. + * Extracts claim parameters from calldata, validates the claim, and executes the + * operation. Uses the message hash itself as the qualification message and a zero + * sponsor domain separator. + * @param messageHash The EIP-712 hash of the claim message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the claim was successfully processed. */ - function ensureValidScope(bytes32 sponsorDomainSeparator, uint256 id) internal pure { - assembly ("memory-safe") { - if iszero(or(iszero(sponsorDomainSeparator), iszero(shr(255, id)))) { - // revert InvalidScope(id) - mstore(0, 0xa06356f5) - mstore(0x20, id) - revert(0x1c, 0x24) - } - } + function processSimpleClaim( + bytes32 messageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + return messageHash.processClaimWithQualificationAndSponsorDomain(messageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, domainSeparator, operation); + } + + /** + * @notice Internal function for processing simple split claims with local domain + * signatures. Extracts split claim parameters from calldata, validates the claim, + * and executes operations for multiple recipients. Uses the message hash itself as + * the qualification message and a zero sponsor domain separator. + * @param messageHash The EIP-712 hash of the claim message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the split claim was successfully processed. + */ + function processSimpleSplitClaim( + bytes32 messageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + return messageHash.processSplitClaimWithQualificationAndSponsorDomain(messageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, domainSeparator, operation); + } + + /** + * @notice Internal function for processing simple batch claims with local domain + * signatures. Extracts batch claim parameters from calldata, validates the claim, + * and executes operations for multiple resource locks to a single recipient. Uses + * the message hash itself as the qualification message and a zero sponsor domain + * separator. + * @param messageHash The EIP-712 hash of the claim message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the batch claim was successfully processed. + */ + function processSimpleBatchClaim( + bytes32 messageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + return messageHash.processBatchClaimWithQualificationAndSponsorDomain(messageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, domainSeparator, operation); + } + + /** + * @notice Internal function for processing batch claims with qualification messages. + * Extracts batch claim parameters from calldata, validates the claim using the provided + * qualification message, and executes operations for multiple resource locks to a single + * recipient. Uses a zero sponsor domain separator. + * @param messageHash The EIP-712 hash of the claim message. + * @param qualificationMessageHash The EIP-712 hash of the allocator's qualification message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the batch claim was successfully processed. + */ + function processBatchClaimWithQualification( + bytes32 messageHash, + bytes32 qualificationMessageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + return messageHash.processBatchClaimWithQualificationAndSponsorDomain(qualificationMessageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, domainSeparator, operation); + } + + /** + * @notice Internal function for processing simple split batch claims with local domain + * signatures. Extracts split batch claim parameters from calldata, validates the claim, + * and executes operations for multiple resource locks to multiple recipients. Uses the + * message hash itself as the qualification message and a zero sponsor domain separator. + * @param messageHash The EIP-712 hash of the claim message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the split batch claim was successfully processed. + */ + function processSimpleSplitBatchClaim( + bytes32 messageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + return messageHash.processSplitBatchClaimWithQualificationAndSponsorDomain(messageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, domainSeparator, operation); + } + + /** + * @notice Internal function for processing split batch claims with qualification + * messages. Extracts split batch claim parameters from calldata, validates the claim + * using the provided qualification message, and executes operations for multiple + * resource locks to multiple recipients. Uses a zero sponsor domain separator. + * @param messageHash The EIP-712 hash of the claim message. + * @param qualificationMessageHash The EIP-712 hash of the allocator's qualification message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the split batch claim was successfully processed. + */ + function processSplitBatchClaimWithQualification( + bytes32 messageHash, + bytes32 qualificationMessageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + return messageHash.processSplitBatchClaimWithQualificationAndSponsorDomain(qualificationMessageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, domainSeparator, operation); + } + + /** + * @notice Internal function for processing claims with sponsor domain signatures. + * Extracts claim parameters from calldata, validates the claim using the provided + * sponsor domain, and executes the operation. Uses the message hash itself as the + * qualification message. + * @param messageHash The EIP-712 hash of the claim message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param sponsorDomain The domain separator for the sponsor's signature. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the claim was successfully processed. + */ + function processClaimWithSponsorDomain( + bytes32 messageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 sponsorDomain, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + return messageHash.processClaimWithQualificationAndSponsorDomain(messageHash, calldataPointer, offsetToId, sponsorDomain, typehash, domainSeparator, operation); + } + + /** + * @notice Internal function for processing claims with qualification messages. + * Extracts claim parameters from calldata, validates the claim using the provided + * qualification message, and executes the operation. Uses a zero sponsor domain + * separator. + * @param messageHash The EIP-712 hash of the claim message. + * @param qualificationMessageHash The EIP-712 hash of the allocator's qualification message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the claim was successfully processed. + */ + function processClaimWithQualification( + bytes32 messageHash, + bytes32 qualificationMessageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + return messageHash.processClaimWithQualificationAndSponsorDomain(qualificationMessageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, domainSeparator, operation); + } + + /** + * @notice Internal function for processing split claims with qualification messages. + * Extracts split claim parameters from calldata, validates the claim using the provided + * qualification message, and executes operations for multiple recipients. Uses a zero + * sponsor domain separator. + * @param messageHash The EIP-712 hash of the claim message. + * @param qualificationMessageHash The EIP-712 hash of the allocator's qualification message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the split claim was successfully processed. + */ + function processSplitClaimWithQualification( + bytes32 messageHash, + bytes32 qualificationMessageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + return messageHash.processSplitClaimWithQualificationAndSponsorDomain(qualificationMessageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, domainSeparator, operation); + } + + /** + * @notice Internal function for processing split claims with sponsor domain signatures. + * Extracts split claim parameters from calldata, validates the claim using the provided + * sponsor domain, and executes operations for multiple recipients. Uses the message + * hash itself as the qualification message. + * @param messageHash The EIP-712 hash of the claim message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param sponsorDomain The domain separator for the sponsor's signature. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the split claim was successfully processed. + */ + function processSplitClaimWithSponsorDomain( + bytes32 messageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 sponsorDomain, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + return messageHash.processSplitClaimWithQualificationAndSponsorDomain(messageHash, calldataPointer, offsetToId, sponsorDomain, typehash, domainSeparator, operation); + } + + /** + * @notice Internal function for processing batch claims with sponsor domain signatures. + * Extracts batch claim parameters from calldata, validates the claim using the provided + * sponsor domain, and executes operations for multiple resource locks to a single + * recipient. Uses the message hash itself as the qualification message. + * @param messageHash The EIP-712 hash of the claim message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param sponsorDomain The domain separator for the sponsor's signature. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the batch claim was successfully processed. + */ + function processBatchClaimWithSponsorDomain( + bytes32 messageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 sponsorDomain, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + return messageHash.processBatchClaimWithQualificationAndSponsorDomain(messageHash, calldataPointer, offsetToId, sponsorDomain, typehash, domainSeparator, operation); + } + + /** + * @notice Internal function for processing split batch claims with sponsor domain + * signatures. Extracts split batch claim parameters from calldata, validates the claim + * using the provided sponsor domain, and executes operations for multiple resource + * locks to multiple recipients. Uses the message hash itself as the qualification + * message. + * @param messageHash The EIP-712 hash of the claim message. + * @param calldataPointer Pointer to the location of the associated struct in calldata. + * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. + * @param sponsorDomain The domain separator for the sponsor's signature. + * @param typehash The EIP-712 typehash used for the claim message. + * @param domainSeparator The local domain separator. + * @param operation Function pointer to either _release or _withdraw for executing the claim. + * @return Whether the split batch claim was successfully processed. + */ + function processSplitBatchClaimWithSponsorDomain( + bytes32 messageHash, + uint256 calldataPointer, + uint256 offsetToId, + bytes32 sponsorDomain, + bytes32 typehash, + bytes32 domainSeparator, + function(address, address, uint256, uint256) internal returns (bool) operation + ) internal returns (bool) { + return messageHash.processSplitBatchClaimWithQualificationAndSponsorDomain(messageHash, calldataPointer, offsetToId, sponsorDomain, typehash, domainSeparator, operation); } /** @@ -112,31 +760,4 @@ library ClaimProcessorLib { mstore(0x40, m) } } - - /** - * @notice Internal function for determining if a resource lock has chain-specific scope - * in the context of an exogenous claim. Returns true if the claim is exogenous (indicated - * by non-zero sponsor domain separator) and the resource lock is chain-specific. - * @param id The ERC6909 token identifier of the resource lock. - * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. - * @return Whether the resource lock's scope is incompatible with the claim context. - */ - function scopeNotMultichain(uint256 id, bytes32 sponsorDomainSeparator) internal pure returns (bool) { - return (sponsorDomainSeparator != bytes32(0)).and(id.toScope() == Scope.ChainSpecific); - } - - /** - * @notice Internal function that combines two claim validations: whether the amount exceeds - * allocation and whether the resource lock's scope is compatible with the claim context. - * Returns true if either the allocated amount is exceeded or if the claim is exogenous but - * the resource lock is chain-specific. - * @param allocatedAmount The total amount allocated for the claim. - * @param amount The amount being claimed. - * @param id The ERC6909 token identifier of the resource lock. - * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. - * @return Whether either validation fails. - */ - function allocationExceededOrScopeNotMultichain(uint256 allocatedAmount, uint256 amount, uint256 id, bytes32 sponsorDomainSeparator) internal pure returns (bool) { - return (allocatedAmount < amount).or(id.scopeNotMultichain(sponsorDomainSeparator)); - } } diff --git a/src/lib/ClaimProcessorLogic.sol b/src/lib/ClaimProcessorLogic.sol index cedfe5a..6dc41b5 100644 --- a/src/lib/ClaimProcessorLogic.sol +++ b/src/lib/ClaimProcessorLogic.sol @@ -48,40 +48,26 @@ import { ExogenousQualifiedSplitBatchMultichainClaim, ExogenousQualifiedSplitBatchMultichainClaimWithWitness } from "../types/BatchMultichainClaims.sol"; -import { SplitComponent, BatchClaimComponent, SplitBatchClaimComponent } from "../types/Components.sol"; import { ClaimHashLib } from "./ClaimHashLib.sol"; import { ClaimProcessorLib } from "./ClaimProcessorLib.sol"; import { EfficiencyLib } from "./EfficiencyLib.sol"; import { FunctionCastLib } from "./FunctionCastLib.sol"; import { HashLib } from "./HashLib.sol"; -import { IdLib } from "./IdLib.sol"; -import { RegistrationLib } from "./RegistrationLib.sol"; -import { ValidityLib } from "./ValidityLib.sol"; import { SharedLogic } from "./SharedLogic.sol"; +import { ValidityLib } from "./ValidityLib.sol"; /** * @title ClaimProcessorLogic * @notice Inherited contract implementing internal functions with logic for processing - * claims against a signed or registered compact. + * claims against a signed or registered compact. Each function derives the respective + * claim hash as well as a qualification hash or typehash if applicable, then processes + * the claim. * @dev IMPORTANT NOTE: this logic assumes that the utilized structs are formatted in a * very specific manner — if parameters are rearranged or new parameters are inserted, * much of this functionality will break. Proceed with caution when making any changes. */ contract ClaimProcessorLogic is SharedLogic { - using ClaimProcessorLib for uint256; - using ClaimProcessorLib for bytes32; - using ClaimProcessorLib for SplitComponent[]; - using EfficiencyLib for bool; - using EfficiencyLib for bytes32; - using EfficiencyLib for uint256; - using FunctionCastLib for function(bytes32, uint256, uint256, bytes32, function(address, address, uint256, uint256) internal returns (bool)) internal returns (bool); - using FunctionCastLib for function(bytes32, uint256, uint256, bytes32, bytes32, function(address, address, uint256, uint256) internal returns (bool)) internal returns (bool); - using FunctionCastLib for function(bytes32, bytes32, uint256, uint256, bytes32, function(address, address, uint256, uint256) internal returns (bool)) internal returns (bool); - using FunctionCastLib for function(bytes32, bytes32, uint256, uint256, bytes32, bytes32, function(address, address, uint256, uint256) internal returns (bool)) internal returns (bool); - using HashLib for address; - using HashLib for bytes32; - using HashLib for uint256; using ClaimHashLib for BasicClaim; using ClaimHashLib for QualifiedClaim; using ClaimHashLib for ClaimWithWitness; @@ -130,25 +116,34 @@ contract ClaimProcessorLogic is SharedLogic { using ClaimHashLib for ExogenousSplitBatchMultichainClaimWithWitness; using ClaimHashLib for ExogenousQualifiedSplitBatchMultichainClaim; using ClaimHashLib for ExogenousQualifiedSplitBatchMultichainClaimWithWitness; - using IdLib for uint256; - using RegistrationLib for address; + using ClaimProcessorLib for uint256; + using EfficiencyLib for uint256; + using FunctionCastLib for function(bytes32, uint256, uint256, bytes32, bytes32, function(address, address, uint256, uint256) internal returns (bool)) internal returns (bool); + using FunctionCastLib for function(bytes32, uint256, uint256, bytes32, bytes32, bytes32, function(address, address, uint256, uint256) internal returns (bool)) internal returns (bool); + using FunctionCastLib for function(bytes32, bytes32, uint256, uint256, bytes32, bytes32, function(address, address, uint256, uint256) internal returns (bool)) internal returns (bool); + using FunctionCastLib for function(bytes32, bytes32, uint256, uint256, bytes32, bytes32, bytes32, function(address, address, uint256, uint256) internal returns (bool)) internal returns (bool); + using HashLib for uint256; using ValidityLib for uint96; using ValidityLib for uint256; using ValidityLib for bytes32; ///// 1. Claims ///// function _processBasicClaim(BasicClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - return _processSimpleClaim.usingBasicClaim()(claimPayload.toClaimHash(), claimPayload, uint256(0xa0).asStubborn(), uint256(0).asStubborn().typehashes(), operation); + return ClaimProcessorLib.processSimpleClaim.usingBasicClaim()( + claimPayload.toClaimHash(), claimPayload, uint256(0xa0).asStubborn(), uint256(0).asStubborn().typehashes(), _domainSeparator(), operation + ); } function _processQualifiedClaim(QualifiedClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); - return _processClaimWithQualification.usingQualifiedClaim()(messageHash, qualificationMessageHash, claimPayload, 0xe0, uint256(0).asStubborn().typehashes(), operation); + return ClaimProcessorLib.processClaimWithQualification.usingQualifiedClaim()( + messageHash, qualificationMessageHash, claimPayload, 0xe0, uint256(0).asStubborn().typehashes(), _domainSeparator(), operation + ); } function _processClaimWithWitness(ClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSimpleClaim.usingClaimWithWitness()(messageHash, claimPayload, 0xe0, typehash, operation); + return ClaimProcessorLib.processSimpleClaim.usingClaimWithWitness()(messageHash, claimPayload, 0xe0, typehash, _domainSeparator(), operation); } function _processQualifiedClaimWithWitness(QualifiedClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) @@ -156,21 +151,23 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processClaimWithQualification.usingQualifiedClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x120, typehash, operation); + return ClaimProcessorLib.processClaimWithQualification.usingQualifiedClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x120, typehash, _domainSeparator(), operation); } function _processSplitClaim(SplitClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - return _processSimpleSplitClaim.usingSplitClaim()(claimPayload.toClaimHash(), claimPayload, 0xa0, uint256(0).asStubborn().typehashes(), operation); + return ClaimProcessorLib.processSimpleSplitClaim.usingSplitClaim()(claimPayload.toClaimHash(), claimPayload, 0xa0, uint256(0).asStubborn().typehashes(), _domainSeparator(), operation); } function _processQualifiedSplitClaim(QualifiedSplitClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); - return _processSplitClaimWithQualification.usingQualifiedSplitClaim()(messageHash, qualificationMessageHash, claimPayload, 0xe0, uint256(0).asStubborn().typehashes(), operation); + return ClaimProcessorLib.processSplitClaimWithQualification.usingQualifiedSplitClaim()( + messageHash, qualificationMessageHash, claimPayload, 0xe0, uint256(0).asStubborn().typehashes(), _domainSeparator(), operation + ); } function _processSplitClaimWithWitness(SplitClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSimpleSplitClaim.usingSplitClaimWithWitness()(messageHash, claimPayload, 0xe0, typehash, operation); + return ClaimProcessorLib.processSimpleSplitClaim.usingSplitClaimWithWitness()(messageHash, claimPayload, 0xe0, typehash, _domainSeparator(), operation); } function _processQualifiedSplitClaimWithWitness(QualifiedSplitClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) @@ -178,22 +175,26 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSplitClaimWithQualification.usingQualifiedSplitClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x120, typehash, operation); + return ClaimProcessorLib.processSplitClaimWithQualification.usingQualifiedSplitClaimWithWitness()( + messageHash, qualificationMessageHash, claimPayload, 0x120, typehash, _domainSeparator(), operation + ); } ///// 2. Batch Claims ///// function _processBatchClaim(BatchClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - return _processSimpleBatchClaim.usingBatchClaim()(claimPayload.toClaimHash(), claimPayload, 0xa0, uint256(1).asStubborn().typehashes(), operation); + return ClaimProcessorLib.processSimpleBatchClaim.usingBatchClaim()(claimPayload.toClaimHash(), claimPayload, 0xa0, uint256(1).asStubborn().typehashes(), _domainSeparator(), operation); } function _processQualifiedBatchClaim(QualifiedBatchClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); - return _processBatchClaimWithQualification.usingQualifiedBatchClaim()(messageHash, qualificationMessageHash, claimPayload, 0xe0, uint256(1).asStubborn().typehashes(), operation); + return ClaimProcessorLib.processBatchClaimWithQualification.usingQualifiedBatchClaim()( + messageHash, qualificationMessageHash, claimPayload, 0xe0, uint256(1).asStubborn().typehashes(), _domainSeparator(), operation + ); } function _processBatchClaimWithWitness(BatchClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSimpleBatchClaim.usingBatchClaimWithWitness()(messageHash, claimPayload, 0xe0, typehash, operation); + return ClaimProcessorLib.processSimpleBatchClaim.usingBatchClaimWithWitness()(messageHash, claimPayload, 0xe0, typehash, _domainSeparator(), operation); } function _processQualifiedBatchClaimWithWitness(QualifiedBatchClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) @@ -201,16 +202,21 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processBatchClaimWithQualification.usingQualifiedBatchClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x120, typehash, operation); + return ClaimProcessorLib.processBatchClaimWithQualification.usingQualifiedBatchClaimWithWitness()( + messageHash, qualificationMessageHash, claimPayload, 0x120, typehash, _domainSeparator(), operation + ); } function _processSplitBatchClaim(SplitBatchClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - return _processSimpleSplitBatchClaim.usingSplitBatchClaim()(claimPayload.toClaimHash(), claimPayload, 0xa0, uint256(1).asStubborn().typehashes(), operation); + return + ClaimProcessorLib.processSimpleSplitBatchClaim.usingSplitBatchClaim()(claimPayload.toClaimHash(), claimPayload, 0xa0, uint256(1).asStubborn().typehashes(), _domainSeparator(), operation); } function _processQualifiedSplitBatchClaim(QualifiedSplitBatchClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); - return _processSplitBatchClaimWithQualification.usingQualifiedSplitBatchClaim()(messageHash, qualificationMessageHash, claimPayload, 0xe0, uint256(1).asStubborn().typehashes(), operation); + return ClaimProcessorLib.processSplitBatchClaimWithQualification.usingQualifiedSplitBatchClaim()( + messageHash, qualificationMessageHash, claimPayload, 0xe0, uint256(1).asStubborn().typehashes(), _domainSeparator(), operation + ); } function _processSplitBatchClaimWithWitness(SplitBatchClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) @@ -218,7 +224,7 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSimpleSplitBatchClaim.usingSplitBatchClaimWithWitness()(messageHash, claimPayload, 0xe0, typehash, operation); + return ClaimProcessorLib.processSimpleSplitBatchClaim.usingSplitBatchClaimWithWitness()(messageHash, claimPayload, 0xe0, typehash, _domainSeparator(), operation); } function _processQualifiedSplitBatchClaimWithWitness(QualifiedSplitBatchClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) @@ -226,17 +232,21 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSplitBatchClaimWithQualification.usingQualifiedSplitBatchClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x120, typehash, operation); + return ClaimProcessorLib.processSplitBatchClaimWithQualification.usingQualifiedSplitBatchClaimWithWitness()( + messageHash, qualificationMessageHash, claimPayload, 0x120, typehash, _domainSeparator(), operation + ); } ///// 3. Multichain Claims ///// function _processMultichainClaim(MultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - return _processSimpleClaim.usingMultichainClaim()(claimPayload.toClaimHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), operation); + return ClaimProcessorLib.processSimpleClaim.usingMultichainClaim()(claimPayload.toClaimHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), _domainSeparator(), operation); } function _processQualifiedMultichainClaim(QualifiedMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); - return _processClaimWithQualification.usingQualifiedMultichainClaim()(messageHash, qualificationMessageHash, claimPayload, 0x100, uint256(2).asStubborn().typehashes(), operation); + return ClaimProcessorLib.processClaimWithQualification.usingQualifiedMultichainClaim()( + messageHash, qualificationMessageHash, claimPayload, 0x100, uint256(2).asStubborn().typehashes(), _domainSeparator(), operation + ); } function _processMultichainClaimWithWitness(MultichainClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) @@ -244,7 +254,7 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSimpleClaim.usingMultichainClaimWithWitness()(messageHash, claimPayload, 0x100, typehash, operation); + return ClaimProcessorLib.processSimpleClaim.usingMultichainClaimWithWitness()(messageHash, claimPayload, 0x100, typehash, _domainSeparator(), operation); } function _processQualifiedMultichainClaimWithWitness(QualifiedMultichainClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) @@ -252,11 +262,14 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processClaimWithQualification.usingQualifiedMultichainClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x140, typehash, operation); + return ClaimProcessorLib.processClaimWithQualification.usingQualifiedMultichainClaimWithWitness()( + messageHash, qualificationMessageHash, claimPayload, 0x140, typehash, _domainSeparator(), operation + ); } function _processSplitMultichainClaim(SplitMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - return _processSimpleSplitClaim.usingSplitMultichainClaim()(claimPayload.toClaimHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), operation); + return + ClaimProcessorLib.processSimpleSplitClaim.usingSplitMultichainClaim()(claimPayload.toClaimHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), _domainSeparator(), operation); } function _processQualifiedSplitMultichainClaim(QualifiedSplitMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) @@ -264,7 +277,9 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); - return _processSplitClaimWithQualification.usingQualifiedSplitMultichainClaim()(messageHash, qualificationMessageHash, claimPayload, 0x100, uint256(2).asStubborn().typehashes(), operation); + return ClaimProcessorLib.processSplitClaimWithQualification.usingQualifiedSplitMultichainClaim()( + messageHash, qualificationMessageHash, claimPayload, 0x100, uint256(2).asStubborn().typehashes(), _domainSeparator(), operation + ); } function _processSplitMultichainClaimWithWitness(SplitMultichainClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) @@ -272,7 +287,7 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSimpleSplitClaim.usingSplitMultichainClaimWithWitness()(messageHash, claimPayload, 0x100, typehash, operation); + return ClaimProcessorLib.processSimpleSplitClaim.usingSplitMultichainClaimWithWitness()(messageHash, claimPayload, 0x100, typehash, _domainSeparator(), operation); } function _processQualifiedSplitMultichainClaimWithWitness( @@ -280,12 +295,15 @@ contract ClaimProcessorLogic is SharedLogic { function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSplitClaimWithQualification.usingQualifiedSplitMultichainClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x140, typehash, operation); + return ClaimProcessorLib.processSplitClaimWithQualification.usingQualifiedSplitMultichainClaimWithWitness()( + messageHash, qualificationMessageHash, claimPayload, 0x140, typehash, _domainSeparator(), operation + ); } ///// 4. Batch Multichain Claims ///// function _processBatchMultichainClaim(BatchMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - return _processSimpleBatchClaim.usingBatchMultichainClaim()(claimPayload.toClaimHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), operation); + return + ClaimProcessorLib.processSimpleBatchClaim.usingBatchMultichainClaim()(claimPayload.toClaimHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), _domainSeparator(), operation); } function _processQualifiedBatchMultichainClaim(QualifiedBatchMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) @@ -293,7 +311,9 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); - return _processBatchClaimWithQualification.usingQualifiedBatchMultichainClaim()(messageHash, qualificationMessageHash, claimPayload, 0x100, uint256(2).asStubborn().typehashes(), operation); + return ClaimProcessorLib.processBatchClaimWithQualification.usingQualifiedBatchMultichainClaim()( + messageHash, qualificationMessageHash, claimPayload, 0x100, uint256(2).asStubborn().typehashes(), _domainSeparator(), operation + ); } function _processBatchMultichainClaimWithWitness(BatchMultichainClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) @@ -301,7 +321,7 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSimpleBatchClaim.usingBatchMultichainClaimWithWitness()(messageHash, claimPayload, 0x100, typehash, operation); + return ClaimProcessorLib.processSimpleBatchClaim.usingBatchMultichainClaimWithWitness()(messageHash, claimPayload, 0x100, typehash, _domainSeparator(), operation); } function _processQualifiedBatchMultichainClaimWithWitness( @@ -309,14 +329,18 @@ contract ClaimProcessorLogic is SharedLogic { function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processBatchClaimWithQualification.usingQualifiedBatchMultichainClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x140, typehash, operation); + return ClaimProcessorLib.processBatchClaimWithQualification.usingQualifiedBatchMultichainClaimWithWitness()( + messageHash, qualificationMessageHash, claimPayload, 0x140, typehash, _domainSeparator(), operation + ); } function _processSplitBatchMultichainClaim(SplitBatchMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - return _processSimpleSplitBatchClaim.usingSplitBatchMultichainClaim()(claimPayload.toClaimHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), operation); + return ClaimProcessorLib.processSimpleSplitBatchClaim.usingSplitBatchMultichainClaim()( + claimPayload.toClaimHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), _domainSeparator(), operation + ); } function _processQualifiedSplitBatchMultichainClaim(QualifiedSplitBatchMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) @@ -324,8 +348,8 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); - return _processSplitBatchClaimWithQualification.usingQualifiedSplitBatchMultichainClaim()( - messageHash, qualificationMessageHash, claimPayload, 0x100, uint256(1).asStubborn().typehashes(), operation + return ClaimProcessorLib.processSplitBatchClaimWithQualification.usingQualifiedSplitBatchMultichainClaim()( + messageHash, qualificationMessageHash, claimPayload, 0x100, uint256(1).asStubborn().typehashes(), _domainSeparator(), operation ); } @@ -334,7 +358,7 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSimpleSplitBatchClaim.usingSplitBatchMultichainClaimWithWitness()(messageHash, claimPayload, 0x100, typehash, operation); + return ClaimProcessorLib.processSimpleSplitBatchClaim.usingSplitBatchMultichainClaimWithWitness()(messageHash, claimPayload, 0x100, typehash, _domainSeparator(), operation); } function _processQualifiedSplitBatchMultichainClaimWithWitness( @@ -342,13 +366,15 @@ contract ClaimProcessorLogic is SharedLogic { function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSplitBatchClaimWithQualification.usingQualifiedSplitBatchMultichainClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x140, typehash, operation); + return ClaimProcessorLib.processSplitBatchClaimWithQualification.usingQualifiedSplitBatchMultichainClaimWithWitness()( + messageHash, qualificationMessageHash, claimPayload, 0x140, typehash, _domainSeparator(), operation + ); } ///// 5. Exogenous Multichain Claims ///// function _processExogenousMultichainClaim(ExogenousMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - return _processClaimWithSponsorDomain.usingExogenousMultichainClaim()( - claimPayload.toClaimHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation + return ClaimProcessorLib.processClaimWithSponsorDomain.usingExogenousMultichainClaim()( + claimPayload.toClaimHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), _domainSeparator(), operation ); } @@ -357,8 +383,8 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); - return _processClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedMultichainClaim()( - messageHash, qualificationMessageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation + return ClaimProcessorLib.processClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedMultichainClaim()( + messageHash, qualificationMessageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), _domainSeparator(), operation ); } @@ -367,8 +393,9 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return - _processClaimWithSponsorDomain.usingExogenousMultichainClaimWithWitness()(messageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation); + return ClaimProcessorLib.processClaimWithSponsorDomain.usingExogenousMultichainClaimWithWitness()( + messageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, _domainSeparator(), operation + ); } function _processExogenousQualifiedMultichainClaimWithWitness( @@ -376,8 +403,8 @@ contract ClaimProcessorLogic is SharedLogic { function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedMultichainClaimWithWitness()( - messageHash, qualificationMessageHash, claimPayload, 0x180, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation + return ClaimProcessorLib.processClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedMultichainClaimWithWitness()( + messageHash, qualificationMessageHash, claimPayload, 0x180, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, _domainSeparator(), operation ); } @@ -385,8 +412,8 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - return _processSplitClaimWithSponsorDomain.usingExogenousSplitMultichainClaim()( - claimPayload.toClaimHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation + return ClaimProcessorLib.processSplitClaimWithSponsorDomain.usingExogenousSplitMultichainClaim()( + claimPayload.toClaimHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), _domainSeparator(), operation ); } @@ -395,8 +422,8 @@ contract ClaimProcessorLogic is SharedLogic { function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); - return _processSplitClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedSplitMultichainClaim()( - messageHash, qualificationMessageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation + return ClaimProcessorLib.processSplitClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedSplitMultichainClaim()( + messageHash, qualificationMessageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), _domainSeparator(), operation ); } @@ -405,8 +432,8 @@ contract ClaimProcessorLogic is SharedLogic { function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSplitClaimWithSponsorDomain.usingExogenousSplitMultichainClaimWithWitness()( - messageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation + return ClaimProcessorLib.processSplitClaimWithSponsorDomain.usingExogenousSplitMultichainClaimWithWitness()( + messageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, _domainSeparator(), operation ); } @@ -415,8 +442,8 @@ contract ClaimProcessorLogic is SharedLogic { function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSplitClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedSplitMultichainClaimWithWitness()( - messageHash, qualificationMessageHash, claimPayload, 0x180, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation + return ClaimProcessorLib.processSplitClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedSplitMultichainClaimWithWitness()( + messageHash, qualificationMessageHash, claimPayload, 0x180, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, _domainSeparator(), operation ); } @@ -425,8 +452,8 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - return _processBatchClaimWithSponsorDomain.usingExogenousBatchMultichainClaim()( - claimPayload.toClaimHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation + return ClaimProcessorLib.processBatchClaimWithSponsorDomain.usingExogenousBatchMultichainClaim()( + claimPayload.toClaimHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), _domainSeparator(), operation ); } @@ -435,8 +462,8 @@ contract ClaimProcessorLogic is SharedLogic { function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); - return _processBatchClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedBatchMultichainClaim()( - messageHash, qualificationMessageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation + return ClaimProcessorLib.processBatchClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedBatchMultichainClaim()( + messageHash, qualificationMessageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), _domainSeparator(), operation ); } @@ -445,8 +472,8 @@ contract ClaimProcessorLogic is SharedLogic { function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processBatchClaimWithSponsorDomain.usingExogenousBatchMultichainClaimWithWitness()( - messageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation + return ClaimProcessorLib.processBatchClaimWithSponsorDomain.usingExogenousBatchMultichainClaimWithWitness()( + messageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, _domainSeparator(), operation ); } @@ -455,8 +482,8 @@ contract ClaimProcessorLogic is SharedLogic { function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processBatchClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedBatchMultichainClaimWithWitness()( - messageHash, qualificationMessageHash, claimPayload, 0x180, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation + return ClaimProcessorLib.processBatchClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedBatchMultichainClaimWithWitness()( + messageHash, qualificationMessageHash, claimPayload, 0x180, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, _domainSeparator(), operation ); } @@ -464,8 +491,8 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - return _processSplitBatchClaimWithSponsorDomain.usingExogenousSplitBatchMultichainClaim()( - claimPayload.toClaimHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation + return ClaimProcessorLib.processSplitBatchClaimWithSponsorDomain.usingExogenousSplitBatchMultichainClaim()( + claimPayload.toClaimHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), _domainSeparator(), operation ); } @@ -474,8 +501,8 @@ contract ClaimProcessorLogic is SharedLogic { function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); - return _processSplitBatchClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedSplitBatchMultichainClaim()( - messageHash, qualificationMessageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation + return ClaimProcessorLib.processSplitBatchClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedSplitBatchMultichainClaim()( + messageHash, qualificationMessageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), _domainSeparator(), operation ); } @@ -484,8 +511,8 @@ contract ClaimProcessorLogic is SharedLogic { function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSplitBatchClaimWithSponsorDomain.usingExogenousSplitBatchMultichainClaimWithWitness()( - messageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation + return ClaimProcessorLib.processSplitBatchClaimWithSponsorDomain.usingExogenousSplitBatchMultichainClaimWithWitness()( + messageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, _domainSeparator(), operation ); } @@ -494,474 +521,8 @@ contract ClaimProcessorLogic is SharedLogic { function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); - return _processSplitBatchClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedSplitBatchMultichainClaimWithWitness()( - messageHash, qualificationMessageHash, claimPayload, 0x180, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation - ); - } - - ///// 7. Private helper functions ///// - - /** - * @notice Internal function for validating claim execution parameters. Extracts and validates - * signatures from calldata, checks expiration, verifies allocator registration, consumes the - * nonce, derives the domain separator, and validates both the sponsor authorization (either - * through direct registration or a provided signature or EIP-1271 call) and the (potentially - * qualified) allocator authorization. Finally, emits a Claim event. - * @param allocatorId The unique identifier for the allocator mediating the claim. - * @param messageHash The EIP-712 hash of the claim message. - * @param qualificationMessageHash The EIP-712 hash of the allocator's qualification message. - * @param calldataPointer Pointer to the location of the associated struct in calldata. - * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. - * @param typehash The EIP-712 typehash used for the claim message. - * @return sponsor The extracted address of the claim sponsor. - */ - function _validate(uint96 allocatorId, bytes32 messageHash, bytes32 qualificationMessageHash, uint256 calldataPointer, bytes32 sponsorDomainSeparator, bytes32 typehash) - private - returns (address sponsor) - { - // Declare variables for signatures and parameters that will be extracted from calldata. - bytes calldata allocatorSignature; - bytes calldata sponsorSignature; - uint256 nonce; - uint256 expires; - - assembly ("memory-safe") { - // Extract allocator signature from calldata using offset stored at calldataPointer. - let allocatorSignaturePtr := add(calldataPointer, calldataload(calldataPointer)) - allocatorSignature.offset := add(0x20, allocatorSignaturePtr) - allocatorSignature.length := calldataload(allocatorSignaturePtr) - - // Extract sponsor signature from calldata using offset stored at calldataPointer + 0x20. - let sponsorSignaturePtr := add(calldataPointer, calldataload(add(calldataPointer, 0x20))) - sponsorSignature.offset := add(0x20, sponsorSignaturePtr) - sponsorSignature.length := calldataload(sponsorSignaturePtr) - - // Extract sponsor address, sanitizing upper 96 bits. - sponsor := shr(96, shl(96, calldataload(add(calldataPointer, 0x40)))) - - // Extract nonce and expiration timestamp. - nonce := calldataload(add(calldataPointer, 0x60)) - expires := calldataload(add(calldataPointer, 0x80)) - } - - // Ensure that the claim hasn't expired. - expires.later(); - - // Retrieve allocator address and consume nonce, ensuring it has not already been consumed. - address allocator = allocatorId.fromRegisteredAllocatorIdWithConsumed(nonce); - - // Derive the default domain separator. - bytes32 domainSeparator = _domainSeparator(); - assembly ("memory-safe") { - // Substitue for provided sponsorDomainSeparator if a nonzero value was supplied. - sponsorDomainSeparator := add(sponsorDomainSeparator, mul(iszero(sponsorDomainSeparator), domainSeparator)) - } - - // Validate sponsor authorization through either ECDSA, EIP-1271, or direct registration. - if ((sponsorDomainSeparator != domainSeparator).or(sponsorSignature.length != 0) || sponsor.hasNoActiveRegistration(messageHash, typehash)) { - messageHash.signedBy(sponsor, sponsorSignature, sponsorDomainSeparator); - } - - // Validate allocator authorization against qualification message. - qualificationMessageHash.signedBy(allocator, allocatorSignature, domainSeparator); - - // Emit claim event. - _emitClaim(sponsor, messageHash, allocator); - } - - /** - * @notice Private function for processing qualified claims with potentially exogenous - * sponsor signatures. Extracts claim parameters from calldata, validates the scope, - * ensures the claimed amount is within the allocated amount, validates the claim, - * and executes either a release of ERC6909 tokens or a withdrawal of underlying tokens. - * @param messageHash The EIP-712 hash of the claim message. - * @param qualificationMessageHash The EIP-712 hash of the allocator's qualification message. - * @param calldataPointer Pointer to the location of the associated struct in calldata. - * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. - * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. - * @param typehash The EIP-712 typehash used for the claim message. - * @param operation Function pointer to either _release or _withdraw for executing the claim. - * @return Whether the claim was successfully processed. - */ - function _processClaimWithQualificationAndSponsorDomain( - bytes32 messageHash, - bytes32 qualificationMessageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 sponsorDomainSeparator, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - // Declare variables for parameters that will be extracted from calldata. - uint256 id; - uint256 allocatedAmount; - address claimant; - uint256 amount; - - assembly ("memory-safe") { - // Calculate pointer to claim parameters using provided offset. - let calldataPointerWithOffset := add(calldataPointer, offsetToId) - - // Extract resource lock id, allocated amount, claimant address, and claim amount. - id := calldataload(calldataPointerWithOffset) - allocatedAmount := calldataload(add(calldataPointerWithOffset, 0x20)) - claimant := shr(96, shl(96, calldataload(add(calldataPointerWithOffset, 0x40)))) - amount := calldataload(add(calldataPointerWithOffset, 0x60)) - } - - // Verify the resource lock scope is compatible with the provided domain separator. - sponsorDomainSeparator.ensureValidScope(id); - - // Ensure the claimed amount does not exceed the allocated amount. - amount.withinAllocated(allocatedAmount); - - // Validate the claim and execute the specified operation (either release or withdraw). - return operation(_validate(id.toAllocatorId(), messageHash, qualificationMessageHash, calldataPointer, sponsorDomainSeparator, typehash), claimant, id, amount); - } - - /** - * @notice Private function for processing qualified split claims with potentially exogenous - * sponsor signatures. Extracts claim parameters from calldata, validates the claim, - * validates the scope, and executes either releases of ERC6909 tokens or withdrawals of - * underlying tokens to multiple recipients. - * @param messageHash The EIP-712 hash of the claim message. - * @param qualificationMessageHash The EIP-712 hash of the allocator's qualification message. - * @param calldataPointer Pointer to the location of the associated struct in calldata. - * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. - * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. - * @param typehash The EIP-712 typehash used for the claim message. - * @param operation Function pointer to either _release or _withdraw for executing the claim. - * @return Whether the split claim was successfully processed. - */ - function _processSplitClaimWithQualificationAndSponsorDomain( - bytes32 messageHash, - bytes32 qualificationMessageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 sponsorDomainSeparator, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - // Declare variables for parameters that will be extracted from calldata. - uint256 id; - uint256 allocatedAmount; - SplitComponent[] calldata components; - - assembly ("memory-safe") { - // Calculate pointer to claim parameters using provided offset. - let calldataPointerWithOffset := add(calldataPointer, offsetToId) - - // Extract resource lock id and allocated amount. - id := calldataload(calldataPointerWithOffset) - allocatedAmount := calldataload(add(calldataPointerWithOffset, 0x20)) - - // Extract array of split components containing claimant addresses and amounts. - let componentsPtr := add(calldataPointer, calldataload(add(calldataPointerWithOffset, 0x40))) - components.offset := add(0x20, componentsPtr) - components.length := calldataload(componentsPtr) - } - - // Validate the claim and extract the sponsor address. - address sponsor = _validate(id.toAllocatorId(), messageHash, qualificationMessageHash, calldataPointer, sponsorDomainSeparator, typehash); - - // Verify the resource lock scope is compatible with the provided domain separator. - sponsorDomainSeparator.ensureValidScope(id); - - // Process each split component, verifying total amount and executing operations. - return components.verifyAndProcessSplitComponents(sponsor, id, allocatedAmount, operation); - } - - /** - * @notice Private function for processing qualified batch claims with potentially exogenous - * sponsor signatures. Extracts batch claim parameters from calldata, validates the claim, - * executes operations, and performs optimized validation of allocator consistency, amounts, - * and scopes. If any validation fails, all operations are reverted after explicitly - * identifying the specific validation failures. - * @param messageHash The EIP-712 hash of the claim message. - * @param qualificationMessageHash The EIP-712 hash of the allocator's qualification message. - * @param calldataPointer Pointer to the location of the associated struct in calldata. - * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. - * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. - * @param typehash The EIP-712 typehash used for the claim message. - * @param operation Function pointer to either _release or _withdraw for executing the claim. - * @return Whether the batch claim was successfully processed. - */ - function _processBatchClaimWithQualificationAndSponsorDomain( - bytes32 messageHash, - bytes32 qualificationMessageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 sponsorDomainSeparator, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - // Declare variables for parameters that will be extracted from calldata. - BatchClaimComponent[] calldata claims; - address claimant; - - assembly ("memory-safe") { - // Calculate pointer to claim parameters using provided offset. - let calldataPointerWithOffset := add(calldataPointer, offsetToId) - - // Extract array of batch claim components and claimant address. - let claimsPtr := add(calldataPointer, calldataload(calldataPointerWithOffset)) - claims.offset := add(0x20, claimsPtr) - claims.length := calldataload(claimsPtr) - claimant := calldataload(add(calldataPointerWithOffset, 0x20)) - } - - // Extract allocator id from first claim for validation. - uint96 firstAllocatorId = claims[0].id.toAllocatorId(); - - // Validate the claim and extract the sponsor address. - address sponsor = _validate(firstAllocatorId, messageHash, qualificationMessageHash, calldataPointer, sponsorDomainSeparator, typehash); - - // Revert if the batch is empty. - uint256 totalClaims = claims.length; - assembly ("memory-safe") { - if iszero(totalClaims) { - // revert InvalidBatchAllocation() - mstore(0, 0x3a03d3bb) - revert(0x1c, 0x04) - } - } - - // Process first claim and initialize error tracking. - // NOTE: many of the bounds checks on these array accesses can be skipped as an optimization - BatchClaimComponent calldata component = claims[0]; - uint256 id = component.id; - uint256 amount = component.amount; - uint256 errorBuffer = component.allocatedAmount.allocationExceededOrScopeNotMultichain(amount, id, sponsorDomainSeparator).asUint256(); - - // Execute transfer or withdrawal for first claim. - operation(sponsor, claimant, id, amount); - - unchecked { - // Process remaining claims while accumulating potential errors. - for (uint256 i = 1; i < totalClaims; ++i) { - component = claims[i]; - id = component.id; - amount = component.amount; - errorBuffer |= (id.toAllocatorId() != firstAllocatorId).or(component.allocatedAmount.allocationExceededOrScopeNotMultichain(amount, id, sponsorDomainSeparator)).asUint256(); - - operation(sponsor, claimant, id, amount); - } - - // If any errors occurred, identify specific failures and revert. - if (errorBuffer.asBool()) { - for (uint256 i = 0; i < totalClaims; ++i) { - component = claims[i]; - component.amount.withinAllocated(component.allocatedAmount); - id = component.id; - sponsorDomainSeparator.ensureValidScope(component.id); - } - - assembly ("memory-safe") { - // revert InvalidBatchAllocation() - mstore(0, 0x3a03d3bb) - revert(0x1c, 0x04) - } - } - } - - return true; - } - - /** - * @notice Private function for processing qualified split batch claims with potentially - * exogenous sponsor signatures. Extracts split batch claim parameters from calldata, - * validates the claim, and executes split operations for each resource lock. Uses optimized - * validation of allocator consistency and scopes, with explicit validation on failure to - * identify specific issues. Each resource lock can be split among multiple recipients. - * @param messageHash The EIP-712 hash of the claim message. - * @param qualificationMessageHash The EIP-712 hash of the allocator's qualification message. - * @param calldataPointer Pointer to the location of the associated struct in calldata. - * @param offsetToId Offset to segment of calldata where relevant claim parameters begin. - * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. - * @param typehash The EIP-712 typehash used for the claim message. - * @param operation Function pointer to either _release or _withdraw for executing the claim. - * @return Whether the split batch claim was successfully processed. - */ - function _processSplitBatchClaimWithQualificationAndSponsorDomain( - bytes32 messageHash, - bytes32 qualificationMessageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 sponsorDomainSeparator, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - // Declare variable for SplitBatchClaimComponent array that will be extracted from calldata. - SplitBatchClaimComponent[] calldata claims; - - assembly ("memory-safe") { - // Extract array of split batch claim components. - let claimsPtr := add(calldataPointer, calldataload(add(calldataPointer, offsetToId))) - claims.offset := add(0x20, claimsPtr) - claims.length := calldataload(claimsPtr) - } - - // Extract allocator id from first claim for validation. - uint96 firstAllocatorId = claims[0].id.toAllocatorId(); - - // Validate the claim and extract the sponsor address. - address sponsor = _validate(firstAllocatorId, messageHash, qualificationMessageHash, calldataPointer, sponsorDomainSeparator, typehash); - - // Initialize tracking variables. - uint256 totalClaims = claims.length; - uint256 errorBuffer = (totalClaims == 0).asUint256(); - uint256 id; - - unchecked { - // Process each claim component while accumulating potential errors. - for (uint256 i = 0; i < totalClaims; ++i) { - SplitBatchClaimComponent calldata claimComponent = claims[i]; - id = claimComponent.id; - errorBuffer |= (id.toAllocatorId() != firstAllocatorId).or(id.scopeNotMultichain(sponsorDomainSeparator)).asUint256(); - - // Process each split component, verifying total amount and executing operations. - claimComponent.portions.verifyAndProcessSplitComponents(sponsor, id, claimComponent.allocatedAmount, operation); - } - - // If any errors occurred, identify specific scope failures and revert. - if (errorBuffer.asBool()) { - for (uint256 i = 0; i < totalClaims; ++i) { - sponsorDomainSeparator.ensureValidScope(claims[i].id); - } - - assembly ("memory-safe") { - // revert InvalidBatchAllocation() - mstore(0, 0x3a03d3bb) - revert(0x1c, 0x04) - } - } - } - - return true; - } - - function _processSimpleClaim(bytes32 messageHash, uint256 calldataPointer, uint256 offsetToId, bytes32 typehash, function(address, address, uint256, uint256) internal returns (bool) operation) - private - returns (bool) - { - return _processClaimWithQualificationAndSponsorDomain(messageHash, messageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, operation); - } - - function _processSimpleSplitClaim( - bytes32 messageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - return _processSplitClaimWithQualificationAndSponsorDomain(messageHash, messageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, operation); - } - - function _processSimpleBatchClaim( - bytes32 messageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - return _processBatchClaimWithQualificationAndSponsorDomain(messageHash, messageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, operation); - } - - function _processBatchClaimWithQualification( - bytes32 messageHash, - bytes32 qualificationMessageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - return _processBatchClaimWithQualificationAndSponsorDomain(messageHash, qualificationMessageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, operation); - } - - function _processSimpleSplitBatchClaim( - bytes32 messageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - return _processSplitBatchClaimWithQualificationAndSponsorDomain(messageHash, messageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, operation); - } - - function _processSplitBatchClaimWithQualification( - bytes32 messageHash, - bytes32 qualificationMessageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - return _processSplitBatchClaimWithQualificationAndSponsorDomain(messageHash, qualificationMessageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, operation); - } - - function _processClaimWithSponsorDomain( - bytes32 messageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 sponsorDomain, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - return _processClaimWithQualificationAndSponsorDomain(messageHash, messageHash, calldataPointer, offsetToId, sponsorDomain, typehash, operation); - } - - function _processClaimWithQualification( - bytes32 messageHash, - bytes32 qualificationMessageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - return _processClaimWithQualificationAndSponsorDomain(messageHash, qualificationMessageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, operation); - } - - function _processSplitClaimWithQualification( - bytes32 messageHash, - bytes32 qualificationMessageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - return _processSplitClaimWithQualificationAndSponsorDomain(messageHash, qualificationMessageHash, calldataPointer, offsetToId, bytes32(0).asStubborn(), typehash, operation); - } - - function _processSplitClaimWithSponsorDomain( - bytes32 messageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 sponsorDomain, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - return _processSplitClaimWithQualificationAndSponsorDomain(messageHash, messageHash, calldataPointer, offsetToId, sponsorDomain, typehash, operation); - } - - function _processBatchClaimWithSponsorDomain( - bytes32 messageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 sponsorDomain, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - return _processBatchClaimWithQualificationAndSponsorDomain(messageHash, messageHash, calldataPointer, offsetToId, sponsorDomain, typehash, operation); - } - - function _processSplitBatchClaimWithSponsorDomain( - bytes32 messageHash, - uint256 calldataPointer, - uint256 offsetToId, - bytes32 sponsorDomain, - bytes32 typehash, - function(address, address, uint256, uint256) internal returns (bool) operation - ) private returns (bool) { - return _processSplitBatchClaimWithQualificationAndSponsorDomain(messageHash, messageHash, calldataPointer, offsetToId, sponsorDomain, typehash, operation); + return ClaimProcessorLib.processSplitBatchClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedSplitBatchMultichainClaimWithWitness()( + messageHash, qualificationMessageHash, claimPayload, 0x180, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, _domainSeparator(), operation + ); } } diff --git a/src/lib/EventLib.sol b/src/lib/EventLib.sol new file mode 100644 index 0000000..4f7728e --- /dev/null +++ b/src/lib/EventLib.sol @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.27; + +/** + * @title EventLib + * @notice Library contract implementing logic for internal functions to + * emit various events. + * @dev Note that most events are still emitted using inline logic; this + * library only implements a few events. + */ +library EventLib { + // keccak256(bytes("Claim(address,address,address,bytes32)")). + uint256 private constant _CLAIM_EVENT_SIGNATURE = 0x770c32a2314b700d6239ee35ba23a9690f2fceb93a55d8c753e953059b3b18d4; + + // keccak256(bytes("ForcedWithdrawalStatusUpdated(address,uint256,bool,uint256)")). + uint256 private constant _FORCED_WITHDRAWAL_STATUS_UPDATED_SIGNATURE = 0xe27f5e0382cf5347965fc81d5c81cd141897fe9ce402d22c496b7c2ddc84e5fd; + + /** + * @notice Internal function for emitting claim events. The sponsor and allocator + * addresses are sanitized before emission. + * @param sponsor The account sponsoring the compact that the claim is for. + * @param messageHash The EIP-712 hash of the claim message. + * @param allocator The account mediating the claim. + */ + function emitClaim(address sponsor, bytes32 messageHash, address allocator) internal { + assembly ("memory-safe") { + // Emit the Claim event: + // - topic1: Claim event signature + // - topic2: sponsor address (sanitized) + // - topic3: allocator address (sanitized) + // - topic4: caller address + // - data: messageHash + mstore(0, messageHash) + log4(0, 0x20, _CLAIM_EVENT_SIGNATURE, shr(0x60, shl(0x60, sponsor)), shr(0x60, shl(0x60, allocator)), caller()) + } + } + + /** + * @notice Internal function for emitting forced withdrawal status update events. + * @param id The ERC6909 token identifier of the resource lock. + * @param withdrawableAt The timestamp when withdrawal becomes possible. + */ + function emitForcedWithdrawalStatusUpdatedEvent(uint256 id, uint256 withdrawableAt) internal { + assembly ("memory-safe") { + // Emit ForcedWithdrawalStatusUpdated event: + // - topic1: Event signature + // - topic2: Caller address + // - topic3: Token id + // - data: [activating flag, withdrawableAt timestamp] + mstore(0, iszero(iszero(withdrawableAt))) + mstore(0x20, withdrawableAt) + log3(0, 0x40, _FORCED_WITHDRAWAL_STATUS_UPDATED_SIGNATURE, caller(), id) + } + } +} diff --git a/src/lib/FunctionCastLib.sol b/src/lib/FunctionCastLib.sol index 5a31269..fed4abf 100644 --- a/src/lib/FunctionCastLib.sol +++ b/src/lib/FunctionCastLib.sol @@ -615,6 +615,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -626,6 +627,7 @@ library FunctionCastLib { BasicClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -642,6 +644,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -654,6 +657,7 @@ library FunctionCastLib { QualifiedClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -669,6 +673,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -680,6 +685,7 @@ library FunctionCastLib { ClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -696,6 +702,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -708,6 +715,7 @@ library FunctionCastLib { QualifiedClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -723,6 +731,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -734,6 +743,7 @@ library FunctionCastLib { SplitClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -750,6 +760,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -762,6 +773,7 @@ library FunctionCastLib { QualifiedSplitClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -777,6 +789,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -788,6 +801,7 @@ library FunctionCastLib { SplitClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -804,6 +818,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -816,6 +831,7 @@ library FunctionCastLib { QualifiedSplitClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -831,6 +847,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -842,6 +859,7 @@ library FunctionCastLib { BatchClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -858,6 +876,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -870,6 +889,7 @@ library FunctionCastLib { QualifiedBatchClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -885,6 +905,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -896,6 +917,7 @@ library FunctionCastLib { BatchClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -912,6 +934,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -924,6 +947,7 @@ library FunctionCastLib { QualifiedBatchClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -939,6 +963,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -950,6 +975,7 @@ library FunctionCastLib { SplitBatchClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -966,6 +992,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -978,6 +1005,7 @@ library FunctionCastLib { QualifiedSplitBatchClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -993,6 +1021,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1004,6 +1033,7 @@ library FunctionCastLib { SplitBatchClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1020,6 +1050,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1032,6 +1063,7 @@ library FunctionCastLib { QualifiedSplitBatchClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1047,6 +1079,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1058,6 +1091,7 @@ library FunctionCastLib { MultichainClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1074,6 +1108,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1086,6 +1121,7 @@ library FunctionCastLib { QualifiedMultichainClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1101,6 +1137,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1112,6 +1149,7 @@ library FunctionCastLib { MultichainClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1128,6 +1166,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1140,6 +1179,7 @@ library FunctionCastLib { QualifiedMultichainClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1155,6 +1195,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1166,6 +1207,7 @@ library FunctionCastLib { SplitMultichainClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1182,6 +1224,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1194,6 +1237,7 @@ library FunctionCastLib { QualifiedSplitMultichainClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1209,6 +1253,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1220,6 +1265,7 @@ library FunctionCastLib { SplitMultichainClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1236,6 +1282,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1248,6 +1295,7 @@ library FunctionCastLib { QualifiedSplitMultichainClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1263,6 +1311,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1274,6 +1323,7 @@ library FunctionCastLib { BatchMultichainClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1290,6 +1340,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1302,6 +1353,7 @@ library FunctionCastLib { QualifiedBatchMultichainClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1317,6 +1369,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1328,6 +1381,7 @@ library FunctionCastLib { BatchMultichainClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1344,6 +1398,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1356,6 +1411,7 @@ library FunctionCastLib { QualifiedBatchMultichainClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1371,6 +1427,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1382,6 +1439,7 @@ library FunctionCastLib { SplitBatchMultichainClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1398,6 +1456,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1410,6 +1469,7 @@ library FunctionCastLib { QualifiedSplitBatchMultichainClaim calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1425,6 +1485,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1436,6 +1497,7 @@ library FunctionCastLib { SplitBatchMultichainClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1452,6 +1514,7 @@ library FunctionCastLib { uint256, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1464,6 +1527,7 @@ library FunctionCastLib { QualifiedSplitBatchMultichainClaimWithWitness calldata, uint256, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1480,6 +1544,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1492,6 +1557,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1509,6 +1575,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1522,6 +1589,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1538,6 +1606,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1550,6 +1619,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1567,6 +1637,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1580,6 +1651,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1596,6 +1668,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1608,6 +1681,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1625,6 +1699,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1638,6 +1713,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1654,6 +1730,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1666,6 +1743,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1683,6 +1761,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1696,6 +1775,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1712,6 +1792,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1724,6 +1805,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1741,6 +1823,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1754,6 +1837,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1770,6 +1854,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1782,6 +1867,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1799,6 +1885,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1812,6 +1899,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1828,6 +1916,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1840,6 +1929,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1857,6 +1947,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1870,6 +1961,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1886,6 +1978,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1898,6 +1991,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) @@ -1915,6 +2009,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnIn ) @@ -1928,6 +2023,7 @@ library FunctionCastLib { uint256, bytes32, bytes32, + bytes32, function(address, address, uint256, uint256) internal returns (bool) ) internal returns (bool) fnOut ) diff --git a/src/lib/SharedLogic.sol b/src/lib/SharedLogic.sol index b486802..87a32b6 100644 --- a/src/lib/SharedLogic.sol +++ b/src/lib/SharedLogic.sol @@ -15,35 +15,12 @@ contract SharedLogic is ConstructorLogic { using IdLib for uint256; using SafeTransferLib for address; - // keccak256(bytes("Claim(address,address,address,bytes32)")). - uint256 private constant _CLAIM_EVENT_SIGNATURE = 0x770c32a2314b700d6239ee35ba23a9690f2fceb93a55d8c753e953059b3b18d4; - // Storage slot seed for ERC6909 state, used in computing balance slots. uint256 private constant _ERC6909_MASTER_SLOT_SEED = 0xedcaa89a82293940; // keccak256(bytes("Transfer(address,address,address,uint256,uint256)")). uint256 private constant _TRANSFER_EVENT_SIGNATURE = 0x1b3d7edb2e9c0b0e7c525b20aaaef0f5940d2ed71663c7d39266ecafac728859; - /** - * @notice Internal function for emitting claim events. The sponsor and allocator - * addresses are sanitized before emission. - * @param sponsor The account sponsoring the compact that the claim is for. - * @param messageHash The EIP-712 hash of the claim message. - * @param allocator The account mediating the claim. - */ - function _emitClaim(address sponsor, bytes32 messageHash, address allocator) internal { - assembly ("memory-safe") { - // Emit the Claim event: - // - topic1: Claim event signature - // - topic2: sponsor address (sanitized) - // - topic3: allocator address (sanitized) - // - topic4: caller address - // - data: messageHash - mstore(0, messageHash) - log4(0, 0x20, _CLAIM_EVENT_SIGNATURE, shr(0x60, shl(0x60, sponsor)), shr(0x60, shl(0x60, allocator)), caller()) - } - } - /** * @notice Internal function for transferring ERC6909 tokens between accounts. Updates * both balances, checking for overflow and insufficient balance. This function bypasses diff --git a/src/lib/TransferLogic.sol b/src/lib/TransferLogic.sol index 9936e71..e5b13e0 100644 --- a/src/lib/TransferLogic.sol +++ b/src/lib/TransferLogic.sol @@ -7,6 +7,7 @@ import { SplitComponent, TransferComponent, SplitByIdComponent } from "../types/ import { ClaimHashLib } from "./ClaimHashLib.sol"; import { EfficiencyLib } from "./EfficiencyLib.sol"; +import { EventLib } from "./EventLib.sol"; import { FunctionCastLib } from "./FunctionCastLib.sol"; import { IdLib } from "./IdLib.sol"; import { SharedLogic } from "./SharedLogic.sol"; @@ -27,6 +28,7 @@ contract TransferLogic is SharedLogic { using ClaimHashLib for SplitBatchTransfer; using IdLib for uint256; using EfficiencyLib for bool; + using EventLib for address; using ValidityLib for uint96; using ValidityLib for uint256; using ValidityLib for bytes32; @@ -228,7 +230,7 @@ contract TransferLogic is SharedLogic { messageHash.signedBy(allocator, transferPayload.allocatorSignature, _domainSeparator()); // Emit Claim event. - _emitClaim(msg.sender, messageHash, allocator); + msg.sender.emitClaim(messageHash, allocator); } /** diff --git a/src/lib/ValidityLib.sol b/src/lib/ValidityLib.sol index ce01305..be1d269 100644 --- a/src/lib/ValidityLib.sol +++ b/src/lib/ValidityLib.sol @@ -1,8 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.27; +import { Scope } from "../types/Scope.sol"; + import { IdLib } from "./IdLib.sol"; import { ConsumerLib } from "./ConsumerLib.sol"; +import { EfficiencyLib } from "./EfficiencyLib.sol"; import { HashLib } from "./HashLib.sol"; import { SignatureCheckerLib } from "solady/utils/SignatureCheckerLib.sol"; @@ -15,8 +18,10 @@ library ValidityLib { using IdLib for uint96; using IdLib for uint256; using ConsumerLib for uint256; + using EfficiencyLib for bool; using HashLib for bytes32; using SignatureCheckerLib for address; + using ValidityLib for uint256; /** * @notice Internal function that retrieves an allocator's address from their ID and @@ -128,4 +133,51 @@ library ValidityLib { } } } + + /** + * @notice Internal pure function for validating that a resource lock's scope is compatible + * with the provided sponsor domain separator. Reverts if an exogenous claim (indicated by + * a non-zero sponsor domain separator) attempts to claim against a chain-specific resource + * lock (indicated by the most significant bit of the id). + * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. + * @param id The ERC6909 token identifier of the resource lock. + */ + function ensureValidScope(bytes32 sponsorDomainSeparator, uint256 id) internal pure { + assembly ("memory-safe") { + if iszero(or(iszero(sponsorDomainSeparator), iszero(shr(255, id)))) { + // revert InvalidScope(id) + mstore(0, 0xa06356f5) + mstore(0x20, id) + revert(0x1c, 0x24) + } + } + } + + /** + * @notice Internal pure function for determining if a resource lock has chain-specific + * scope in the context of an exogenous claim. Returns true if the claim is exogenous + * (indicated by a non-zero sponsor domain separator) and the resource lock is + * chain-specific. + * @param id The ERC6909 token identifier of the resource lock. + * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. + * @return Whether the resource lock's scope is incompatible with the claim context. + */ + function scopeNotMultichain(uint256 id, bytes32 sponsorDomainSeparator) internal pure returns (bool) { + return (sponsorDomainSeparator != bytes32(0)).and(id.toScope() == Scope.ChainSpecific); + } + + /** + * @notice Internal function that combines two claim validations: whether the amount exceeds + * allocation and whether the resource lock's scope is compatible with the claim context. + * Returns true if either the allocated amount is exceeded or if the claim is exogenous but + * the resource lock is chain-specific. + * @param allocatedAmount The total amount allocated for the claim. + * @param amount The amount being claimed. + * @param id The ERC6909 token identifier of the resource lock. + * @param sponsorDomainSeparator The domain separator for the sponsor's signature, or zero for non-exogenous claims. + * @return Whether either validation fails. + */ + function allocationExceededOrScopeNotMultichain(uint256 allocatedAmount, uint256 amount, uint256 id, bytes32 sponsorDomainSeparator) internal pure returns (bool) { + return (allocatedAmount < amount).or(id.scopeNotMultichain(sponsorDomainSeparator)); + } } diff --git a/src/lib/WithdrawalLogic.sol b/src/lib/WithdrawalLogic.sol index 461cf93..59b8512 100644 --- a/src/lib/WithdrawalLogic.sol +++ b/src/lib/WithdrawalLogic.sol @@ -6,6 +6,7 @@ import { ResetPeriod } from "../types/ResetPeriod.sol"; import { SharedLogic } from "./SharedLogic.sol"; import { EfficiencyLib } from "./EfficiencyLib.sol"; +import { EventLib } from "./EventLib.sol"; import { IdLib } from "./IdLib.sol"; /** @@ -18,9 +19,7 @@ contract WithdrawalLogic is SharedLogic { using IdLib for uint256; using IdLib for ResetPeriod; using EfficiencyLib for uint256; - - // keccak256(bytes("ForcedWithdrawalStatusUpdated(address,uint256,bool,uint256)")). - uint256 private constant _FORCED_WITHDRAWAL_STATUS_UPDATED_SIGNATURE = 0xe27f5e0382cf5347965fc81d5c81cd141897fe9ce402d22c496b7c2ddc84e5fd; + using EventLib for uint256; // Storage scope for forced withdrawal activation times: // slot: keccak256(_FORCED_WITHDRAWAL_ACTIVATIONS_SCOPE ++ account ++ id) => activates. @@ -48,7 +47,7 @@ contract WithdrawalLogic is SharedLogic { } // emit the ForcedWithdrawalStatusUpdated event. - _emitForcedWithdrawalStatusUpdatedEvent(id, withdrawableAt); + id.emitForcedWithdrawalStatusUpdatedEvent(withdrawableAt); } /** @@ -77,7 +76,7 @@ contract WithdrawalLogic is SharedLogic { } // emit the ForcedWithdrawalStatusUpdated event. - _emitForcedWithdrawalStatusUpdatedEvent(id, uint256(0).asStubborn()); + id.emitForcedWithdrawalStatusUpdatedEvent(uint256(0).asStubborn()); return true; } @@ -134,24 +133,6 @@ contract WithdrawalLogic is SharedLogic { } } - /** - * @notice Private function for emitting forced withdrawal status update events. - * @param id The ERC6909 token identifier of the resource lock. - * @param withdrawableAt The timestamp when withdrawal becomes possible. - */ - function _emitForcedWithdrawalStatusUpdatedEvent(uint256 id, uint256 withdrawableAt) private { - assembly ("memory-safe") { - // Emit ForcedWithdrawalStatusUpdated event: - // - topic1: Event signature - // - topic2: Caller address - // - topic3: Token id - // - data: [activating flag, withdrawableAt timestamp] - mstore(0, iszero(iszero(withdrawableAt))) - mstore(0x20, withdrawableAt) - log3(0, 0x40, _FORCED_WITHDRAWAL_STATUS_UPDATED_SIGNATURE, caller(), id) - } - } - /** * @notice Private pure function for computing the storage slot for a forced * withdrawal activation timestamp.