From 973187705e45c7ceac26e834a7e8c52edd1771c0 Mon Sep 17 00:00:00 2001 From: 0age <37939117+0age@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:28:39 -0700 Subject: [PATCH] complete ClaimHashLib refactor --- src/lib/ClaimHashLib.sol | 449 ++++++++++++++++++++++++++++ src/lib/ClaimProcessorLogic.sol | 193 ++++++------ src/lib/HashLib.sol | 512 ++------------------------------ src/lib/TransferLogic.sol | 18 +- 4 files changed, 587 insertions(+), 585 deletions(-) create mode 100644 src/lib/ClaimHashLib.sol diff --git a/src/lib/ClaimHashLib.sol b/src/lib/ClaimHashLib.sol new file mode 100644 index 0000000..6131247 --- /dev/null +++ b/src/lib/ClaimHashLib.sol @@ -0,0 +1,449 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.27; + +import { + BasicTransfer, + SplitTransfer, + BasicClaim, + QualifiedClaim, + ClaimWithWitness, + QualifiedClaimWithWitness, + SplitClaim, + SplitClaimWithWitness, + QualifiedSplitClaim, + QualifiedSplitClaimWithWitness +} from "../types/Claims.sol"; + +import { + BatchTransfer, + SplitBatchTransfer, + BatchClaim, + QualifiedBatchClaim, + BatchClaimWithWitness, + QualifiedBatchClaimWithWitness, + SplitBatchClaim, + SplitBatchClaimWithWitness, + QualifiedSplitBatchClaim, + QualifiedSplitBatchClaimWithWitness +} from "../types/BatchClaims.sol"; + +import { + MultichainClaim, + QualifiedMultichainClaim, + MultichainClaimWithWitness, + QualifiedMultichainClaimWithWitness, + SplitMultichainClaim, + SplitMultichainClaimWithWitness, + QualifiedSplitMultichainClaim, + QualifiedSplitMultichainClaimWithWitness, + ExogenousMultichainClaim, + ExogenousQualifiedMultichainClaim, + ExogenousMultichainClaimWithWitness, + ExogenousQualifiedMultichainClaimWithWitness, + ExogenousSplitMultichainClaim, + ExogenousSplitMultichainClaimWithWitness, + ExogenousQualifiedSplitMultichainClaim, + ExogenousQualifiedSplitMultichainClaimWithWitness +} from "../types/MultichainClaims.sol"; + +import { + BatchMultichainClaim, + QualifiedBatchMultichainClaim, + BatchMultichainClaimWithWitness, + QualifiedBatchMultichainClaimWithWitness, + SplitBatchMultichainClaim, + SplitBatchMultichainClaimWithWitness, + QualifiedSplitBatchMultichainClaim, + QualifiedSplitBatchMultichainClaimWithWitness, + ExogenousBatchMultichainClaim, + ExogenousQualifiedBatchMultichainClaim, + ExogenousBatchMultichainClaimWithWitness, + ExogenousQualifiedBatchMultichainClaimWithWitness, + ExogenousSplitBatchMultichainClaim, + ExogenousSplitBatchMultichainClaimWithWitness, + ExogenousQualifiedSplitBatchMultichainClaim, + ExogenousQualifiedSplitBatchMultichainClaimWithWitness +} from "../types/BatchMultichainClaims.sol"; + +import { TransferComponent, SplitComponent, SplitByIdComponent, BatchClaimComponent, SplitBatchClaimComponent } from "../types/Components.sol"; + +import { ResetPeriod } from "../types/ResetPeriod.sol"; +import { Scope } from "../types/Scope.sol"; + +import { EfficiencyLib } from "./EfficiencyLib.sol"; +import { FunctionCastLib } from "./FunctionCastLib.sol"; +import { HashLib } from "./HashLib.sol"; + +/** + * @title ClaimHashLib + * @notice Libray contract implementing logic for deriving hashes as part of processing + * claims, allocated transfers, and withdrawals. + */ +library ClaimHashLib { + using EfficiencyLib for uint256; + using FunctionCastLib for function (uint256, uint256) internal pure returns (uint256); + using FunctionCastLib for function (uint256, uint256) internal view returns (bytes32, bytes32); + using FunctionCastLib for function (uint256, uint256, function(uint256, uint256) internal view returns (bytes32)) internal view returns (bytes32); + using FunctionCastLib for function (uint256, uint256, function(uint256, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32); + using FunctionCastLib for function (uint256, uint256, function(uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32); + using FunctionCastLib for function (uint256, uint256, function(uint256, uint256) internal view returns (bytes32, bytes32)) internal view returns (bytes32, bytes32, bytes32); + using FunctionCastLib for function (uint256, uint256, function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32, bytes32); + using FunctionCastLib for function (BasicClaim calldata) internal view returns (bytes32); + using FunctionCastLib for function (MultichainClaim calldata) internal view returns (bytes32); + using FunctionCastLib for function (ExogenousMultichainClaim calldata) internal view returns (bytes32); + using FunctionCastLib for function (QualifiedClaim calldata) internal view returns (bytes32, bytes32); + using FunctionCastLib for function (QualifiedMultichainClaim calldata) internal view returns (bytes32, bytes32); + using FunctionCastLib for function (ExogenousQualifiedMultichainClaim calldata) internal view returns (bytes32, bytes32); + using FunctionCastLib for function (MultichainClaimWithWitness calldata) internal view returns (bytes32, bytes32); + using FunctionCastLib for function (ExogenousMultichainClaimWithWitness calldata) internal view returns (bytes32, bytes32); + using FunctionCastLib for function (QualifiedClaimWithWitness calldata) internal view returns (bytes32, bytes32, bytes32); + using FunctionCastLib for function (QualifiedMultichainClaimWithWitness calldata) internal view returns (bytes32, bytes32, bytes32); + using FunctionCastLib for function (ExogenousQualifiedMultichainClaimWithWitness calldata) internal view returns (bytes32, bytes32, bytes32); + using HashLib for uint256; + using HashLib for BatchClaimComponent[]; + using HashLib for SplitBatchClaimComponent[]; + using HashLib for BasicTransfer; + using HashLib for SplitTransfer; + using HashLib for BatchTransfer; + using HashLib for SplitBatchTransfer; + + ///// CATEGORY 1: Transfer claim hashes ///// + function toClaimHash(BasicTransfer calldata transfer) internal view returns (bytes32 claimHash) { + return transfer.toBasicTransferMessageHash(); + } + + function toClaimHash(SplitTransfer calldata transfer) internal view returns (bytes32 claimHash) { + return transfer.toSplitTransferMessageHash(); + } + + function toClaimHash(BatchTransfer calldata transfer) internal view returns (bytes32 claimHash) { + return transfer.toBatchTransferMessageHash(); + } + + function toClaimHash(SplitBatchTransfer calldata transfer) internal view returns (bytes32 claimHash) { + return transfer.toSplitBatchTransferMessageHash(); + } + + ///// CATEGORY 2: "Simple" Claim hashes ///// + function toClaimHash(BasicClaim calldata claim) internal view returns (bytes32 claimHash) { + return _toBasicMessageHash(claim); + } + + function toClaimHash(SplitClaim calldata claim) internal view returns (bytes32 claimHash) { + return _toBasicMessageHash.usingSplitClaim()(claim); + } + + function toClaimHash(BatchClaim calldata claim) internal view returns (bytes32 claimHash) { + return _toGenericMessageHash.usingBatchClaim()(claim, claim.claims.toIdsAndAmountsHash(), HashLib.toBatchMessageHash); + } + + function toClaimHash(SplitBatchClaim calldata claim) internal view returns (bytes32 claimHash) { + return _toGenericMessageHash.usingSplitBatchClaim()(claim, claim.claims.toSplitIdsAndAmountsHash(), HashLib.toBatchMessageHash); + } + + function toClaimHash(MultichainClaim calldata claim) internal view returns (bytes32 claimHash) { + return _toMultichainMessageHash(claim); + } + + function toClaimHash(SplitMultichainClaim calldata claim) internal view returns (bytes32 claimHash) { + return _toMultichainMessageHash.usingSplitMultichainClaim()(claim); + } + + function toClaimHash(BatchMultichainClaim calldata claim) internal view returns (bytes32 claimHash) { + return _toGenericMessageHash.usingBatchMultichainClaim()(claim, claim.claims.toIdsAndAmountsHash(), HashLib.toSimpleMultichainClaimMessageHash); + } + + function toClaimHash(SplitBatchMultichainClaim calldata claim) internal view returns (bytes32 claimHash) { + return _toGenericMessageHash.usingSplitBatchMultichainClaim()(claim, claim.claims.toSplitIdsAndAmountsHash(), HashLib.toSimpleMultichainClaimMessageHash); + } + + function toClaimHash(ExogenousMultichainClaim calldata claim) internal view returns (bytes32 claimHash) { + return _toExogenousMultichainMessageHash(claim); + } + + function toClaimHash(ExogenousSplitMultichainClaim calldata claim) internal view returns (bytes32 claimHash) { + return _toExogenousMultichainMessageHash.usingExogenousSplitMultichainClaim()(claim); + } + + function toClaimHash(ExogenousBatchMultichainClaim calldata claim) internal view returns (bytes32 claimHash) { + return _toGenericMessageHash.usingExogenousBatchMultichainClaim()(claim, claim.claims.toIdsAndAmountsHash(), HashLib.toSimpleExogenousMultichainClaimMessageHash); + } + + function toClaimHash(ExogenousSplitBatchMultichainClaim calldata claim) internal view returns (bytes32 claimHash) { + return _toGenericMessageHash.usingExogenousSplitBatchMultichainClaim()(claim, claim.claims.toSplitIdsAndAmountsHash(), HashLib.toSimpleExogenousMultichainClaimMessageHash); + } + + ///// CATEGORY 3: Qualified claim message & qualification hashes ///// + function toMessageHashes(QualifiedClaim calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash) { + return _toQualifiedMessageHash(claim); + } + + function toMessageHashes(QualifiedSplitClaim calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash) { + return _toQualifiedMessageHash.usingQualifiedSplitClaim()(claim); + } + + function toMessageHashes(QualifiedBatchClaim calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash) { + return _toGenericMessageHashWithQualificationHash.usingQualifiedBatchClaim()(claim, claim.claims.toIdsAndAmountsHash(), HashLib.toBatchMessageHash); + } + + function toMessageHashes(QualifiedSplitBatchClaim calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash) { + return _toGenericMessageHashWithQualificationHash.usingQualifiedSplitBatchClaim()(claim, claim.claims.toSplitIdsAndAmountsHash(), HashLib.toBatchMessageHash); + } + + function toMessageHashes(QualifiedMultichainClaim calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash) { + return _toQualifiedMultichainMessageHash(claim); + } + + function toMessageHashes(QualifiedSplitMultichainClaim calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash) { + return _toQualifiedMultichainMessageHash.usingQualifiedSplitMultichainClaim()(claim); + } + + function toMessageHashes(QualifiedBatchMultichainClaim calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash) { + return _toGenericMessageHashWithQualificationHash.usingQualifiedBatchMultichainClaim()(claim, claim.claims.toIdsAndAmountsHash(), HashLib.toQualifiedMultichainClaimMessageHash); + } + + function toMessageHashes(QualifiedSplitBatchMultichainClaim calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash) { + return _toGenericMessageHashWithQualificationHash.usingQualifiedSplitBatchMultichainClaim()(claim, claim.claims.toSplitIdsAndAmountsHash(), HashLib.toQualifiedMultichainClaimMessageHash); + } + + function toMessageHashes(ExogenousQualifiedMultichainClaim calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash) { + return _toExogenousQualifiedMultichainMessageHash(claim); + } + + function toMessageHashes(ExogenousQualifiedSplitMultichainClaim calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash) { + return _toExogenousQualifiedMultichainMessageHash.usingExogenousQualifiedSplitMultichainClaim()(claim); + } + + function toMessageHashes(ExogenousQualifiedBatchMultichainClaim calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash) { + return + _toGenericMessageHashWithQualificationHash.usingExogenousQualifiedBatchMultichainClaim()(claim, claim.claims.toIdsAndAmountsHash(), HashLib.toExogenousQualifiedMultichainClaimMessageHash); + } + + function toMessageHashes(ExogenousQualifiedSplitBatchMultichainClaim calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash) { + return _toGenericMessageHashWithQualificationHash.usingExogenousQualifiedSplitBatchMultichainClaim()( + claim, claim.claims.toSplitIdsAndAmountsHash(), HashLib.toExogenousQualifiedMultichainClaimMessageHash + ); + } + + ///// CATEGORY 4: Claim with witness message & type hashes ///// + function toMessageHashes(ClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 typehash) { + return HashLib.toMessageHashWithWitness.usingClaimWithWitness()(claim, 0); + } + + function toMessageHashes(SplitClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 typehash) { + return HashLib.toMessageHashWithWitness.usingSplitClaimWithWitness()(claim, 0); + } + + function toMessageHashes(BatchClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 typehash) { + return HashLib.toBatchClaimWithWitnessMessageHash.usingBatchClaimWithWitness()(claim, claim.claims.toIdsAndAmountsHash()); + } + + function toMessageHashes(SplitBatchClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 typehash) { + return HashLib.toBatchClaimWithWitnessMessageHash.usingSplitBatchClaimWithWitness()(claim, claim.claims.toSplitIdsAndAmountsHash()); + } + + function toMessageHashes(MultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 typehash) { + return _toMultichainClaimWithWitnessMessageHash(claim); + } + + function toMessageHashes(SplitMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 typehash) { + return _toMultichainClaimWithWitnessMessageHash.usingSplitMultichainClaimWithWitness()(claim); + } + + function toMessageHashes(BatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 typehash) { + return _toGenericMultichainClaimWithWitnessMessageHash.usingBatchMultichainClaimWithWitness()(claim, claim.claims.toIdsAndAmountsHash(), HashLib.toMultichainClaimMessageHash); + } + + function toMessageHashes(SplitBatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 typehash) { + return _toGenericMultichainClaimWithWitnessMessageHash.usingSplitBatchMultichainClaimWithWitness()(claim, claim.claims.toSplitIdsAndAmountsHash(), HashLib.toMultichainClaimMessageHash); + } + + function toMessageHashes(ExogenousMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 typehash) { + return _toExogenousMultichainClaimWithWitnessMessageHash(claim); + } + + function toMessageHashes(ExogenousSplitMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 typehash) { + return _toExogenousMultichainClaimWithWitnessMessageHash.usingExogenousSplitMultichainClaimWithWitness()(claim); + } + + function toMessageHashes(ExogenousBatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 typehash) { + return _toGenericMultichainClaimWithWitnessMessageHash.usingExogenousBatchMultichainClaimWithWitness()(claim, claim.claims.toIdsAndAmountsHash(), HashLib.toExogenousMultichainClaimMessageHash); + } + + function toMessageHashes(ExogenousSplitBatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 typehash) { + return _toGenericMultichainClaimWithWitnessMessageHash.usingExogenousSplitBatchMultichainClaimWithWitness()( + claim, claim.claims.toSplitIdsAndAmountsHash(), HashLib.toExogenousMultichainClaimMessageHash + ); + } + + ///// CATEGORY 5: Qualified claim with witness message, qualification, & type hashes ///// + function toMessageHashes(QualifiedClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) { + return _toQualifiedClaimWithWitnessMessageHash(claim); + } + + function toMessageHashes(QualifiedSplitClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) { + return _toQualifiedClaimWithWitnessMessageHash.usingQualifiedSplitClaimWithWitness()(claim); + } + + function toMessageHashes(QualifiedBatchClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) { + return _toGenericQualifiedClaimWithWitnessMessageHash.usingQualifiedBatchClaimWithWitness()(claim, claim.claims.toIdsAndAmountsHash(), HashLib.toBatchClaimWithWitnessMessageHash); + } + + function toMessageHashes(QualifiedSplitBatchClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) { + return _toGenericQualifiedClaimWithWitnessMessageHash.usingQualifiedSplitBatchClaimWithWitness()(claim, claim.claims.toSplitIdsAndAmountsHash(), HashLib.toBatchClaimWithWitnessMessageHash); + } + + function toMessageHashes(QualifiedMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) { + return _toQualifiedMultichainClaimWithWitnessMessageHash(claim); + } + + function toMessageHashes(QualifiedSplitMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) { + return _toQualifiedMultichainClaimWithWitnessMessageHash.usingQualifiedSplitMultichainClaimWithWitness()(claim); + } + + function toMessageHashes(QualifiedBatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) { + return _toGenericQualifiedMultichainClaimWithWitnessMessageHash.usingQualifiedBatchMultichainClaimWithWitness()(claim, claim.claims.toIdsAndAmountsHash(), HashLib.toMultichainClaimMessageHash); + } + + function toMessageHashes(QualifiedSplitBatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) { + return _toGenericQualifiedMultichainClaimWithWitnessMessageHash.usingQualifiedSplitBatchMultichainClaimWithWitness()( + claim, claim.claims.toSplitIdsAndAmountsHash(), HashLib.toMultichainClaimMessageHash + ); + } + + function toMessageHashes(ExogenousQualifiedMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) { + return _toExogenousQualifiedMultichainClaimWithWitnessMessageHash(claim); + } + + function toMessageHashes(ExogenousQualifiedSplitMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) { + return _toExogenousQualifiedMultichainClaimWithWitnessMessageHash.usingExogenousQualifiedSplitMultichainClaimWithWitness()(claim); + } + + function toMessageHashes(ExogenousQualifiedBatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) { + return _toGenericQualifiedMultichainClaimWithWitnessMessageHash.usingExogenousQualifiedBatchMultichainClaimWithWitness()( + claim, claim.claims.toIdsAndAmountsHash(), HashLib.toExogenousMultichainClaimMessageHash + ); + } + + function toMessageHashes(ExogenousQualifiedSplitBatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) { + return _toGenericQualifiedMultichainClaimWithWitnessMessageHash.usingExogenousQualifiedSplitBatchMultichainClaimWithWitness()( + claim, claim.claims.toSplitIdsAndAmountsHash(), HashLib.toExogenousMultichainClaimMessageHash + ); + } + + ///// Private helper functions ///// + function _toGenericMessageHash(uint256 claim, uint256 additionalInput, function(uint256, uint256) internal view returns (bytes32) hashFn) private view returns (bytes32 claimHash) { + return hashFn(claim, additionalInput); + } + + function _toBasicMessageHash(BasicClaim calldata claim) private view returns (bytes32 claimHash) { + return _toGenericMessageHash.usingBasicClaim()(claim, uint256(0).asStubborn(), HashLib.toClaimMessageHash); + } + + function _toMultichainMessageHash(MultichainClaim calldata claim) private view returns (bytes32 claimHash) { + return _toGenericMessageHash.usingMultichainClaim()(claim, HashLib.toSingleIdAndAmountHash.usingMultichainClaim()(claim, 0), HashLib.toSimpleMultichainClaimMessageHash); + } + + function _toExogenousMultichainMessageHash(ExogenousMultichainClaim calldata claim) private view returns (bytes32 claimHash) { + return _toGenericMessageHash.usingExogenousMultichainClaim()( + claim, HashLib.toSingleIdAndAmountHash.usingExogenousMultichainClaim()(claim, uint256(0x40).asStubborn()), HashLib.toSimpleExogenousMultichainClaimMessageHash + ); + } + + function _toGenericMessageHashWithQualificationHash(uint256 claim, uint256 additionalInput, function(uint256, uint256) internal view returns (bytes32) hashFn) + private + view + returns (bytes32 claimHash, bytes32 qualificationHash) + { + claimHash = _toGenericMessageHash(claim, additionalInput, hashFn); + return (claimHash, claim.toQualificationMessageHash(claimHash, uint256(0).asStubborn())); + } + + function _toQualifiedMessageHash(QualifiedClaim calldata claim) private view returns (bytes32 claimHash, bytes32 qualificationHash) { + return _toGenericMessageHashWithQualificationHash.usingQualifiedClaim()(claim, uint256(0x40).asStubborn(), HashLib.toClaimMessageHash); + } + + function _toQualifiedMultichainMessageHash(QualifiedMultichainClaim calldata claim) private view returns (bytes32 claimHash, bytes32 qualificationHash) { + return _toGenericMessageHashWithQualificationHash.usingQualifiedMultichainClaim()( + claim, HashLib.toSingleIdAndAmountHash.usingQualifiedMultichainClaim()(claim, uint256(0x40).asStubborn()), HashLib.toQualifiedMultichainClaimMessageHash + ); + } + + function _toExogenousQualifiedMultichainMessageHash(ExogenousQualifiedMultichainClaim calldata claim) private view returns (bytes32 claimHash, bytes32 qualificationHash) { + return _toGenericMessageHashWithQualificationHash.usingExogenousQualifiedMultichainClaim()( + claim, HashLib.toSingleIdAndAmountHash.usingExogenousQualifiedMultichainClaim()(claim, uint256(0x80).asStubborn()), HashLib.toExogenousQualifiedMultichainClaimMessageHash + ); + } + + function _toGenericMultichainClaimWithWitnessMessageHash(uint256 claim, uint256 additionalInput, function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32) hashFn) + private + view + returns (bytes32 claimHash, bytes32 /* typehash */ ) + { + (bytes32 allocationTypehash, bytes32 typehash) = claim.toMultichainTypehashes(); + return (hashFn(claim, uint256(0x40).asStubborn(), allocationTypehash, typehash, additionalInput), typehash); + } + + function _toGenericMultichainClaimWithWitnessMessageHashPriorToQualification( + uint256 claim, + uint256 additionalInput, + function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32) hashFn + ) private view returns (bytes32 claimHash, bytes32 /* typehash */ ) { + (bytes32 allocationTypehash, bytes32 typehash) = claim.toMultichainTypehashes(); + return (hashFn(claim, uint256(0x80).asStubborn(), allocationTypehash, typehash, additionalInput), typehash); + } + + function _toMultichainClaimWithWitnessMessageHash(MultichainClaimWithWitness calldata claim) private view returns (bytes32 claimHash, bytes32 typehash) { + return _toGenericMultichainClaimWithWitnessMessageHash.usingMultichainClaimWithWitness()( + claim, HashLib.toSingleIdAndAmountHash.usingMultichainClaimWithWitness()(claim, uint256(0x40).asStubborn()), HashLib.toMultichainClaimMessageHash + ); + } + + function _toExogenousMultichainClaimWithWitnessMessageHash(ExogenousMultichainClaimWithWitness calldata claim) private view returns (bytes32 claimHash, bytes32 typehash) { + return _toGenericMultichainClaimWithWitnessMessageHash.usingExogenousMultichainClaimWithWitness()( + claim, HashLib.toSingleIdAndAmountHash.usingExogenousMultichainClaimWithWitness()(claim, uint256(0x80).asStubborn()), HashLib.toExogenousMultichainClaimMessageHash + ); + } + + function _toGenericQualifiedClaimWithWitnessMessageHash(uint256 claim, uint256 additionalInput, function (uint256, uint256) internal view returns (bytes32, bytes32) hashFn) + private + view + returns (bytes32, /* claimHash */ bytes32 qualificationHash, bytes32 /* typehash */ ) + { + (bytes32 messageHash, bytes32 typehash) = hashFn(claim, additionalInput); + return (messageHash, claim.toQualificationMessageHash(messageHash, uint256(0x40).asStubborn()), typehash); + } + + function _toQualifiedClaimWithWitnessMessageHash(QualifiedClaimWithWitness calldata claim) private view returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) { + return _toGenericQualifiedClaimWithWitnessMessageHash.usingQualifiedClaimWithWitness()(claim, uint256(0x40).asStubborn(), HashLib.toMessageHashWithWitness); + } + + function _toGenericQualifiedMultichainClaimWithWitnessMessageHash( + uint256 claim, + uint256 additionalInput, + function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32) hashFn + ) private view returns (bytes32, /* claimHash */ bytes32 qualificationHash, bytes32 /* typehash */ ) { + (bytes32 messageHash, bytes32 typehash) = _toGenericMultichainClaimWithWitnessMessageHashPriorToQualification(claim, additionalInput, hashFn); + return (messageHash, claim.toQualificationMessageHash(messageHash, uint256(0x40).asStubborn()), typehash); + } + + function _toQualifiedMultichainClaimWithWitnessMessageHash(QualifiedMultichainClaimWithWitness calldata claim) + private + view + returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) + { + return _toGenericQualifiedMultichainClaimWithWitnessMessageHash.usingQualifiedMultichainClaimWithWitness()( + claim, HashLib.toSingleIdAndAmountHash.usingQualifiedMultichainClaimWithWitness()(claim, uint256(0x80).asStubborn()), HashLib.toMultichainClaimMessageHash + ); + } + + function _toExogenousQualifiedMultichainClaimWithWitnessMessageHash(ExogenousQualifiedMultichainClaimWithWitness calldata claim) + private + view + returns (bytes32 claimHash, bytes32 qualificationHash, bytes32 typehash) + { + return _toGenericQualifiedMultichainClaimWithWitnessMessageHash.usingExogenousQualifiedMultichainClaimWithWitness()( + claim, HashLib.toSingleIdAndAmountHash.usingExogenousQualifiedMultichainClaimWithWitness()(claim, uint256(0xc0).asStubborn()), HashLib.toExogenousMultichainClaimMessageHash + ); + } +} diff --git a/src/lib/ClaimProcessorLogic.sol b/src/lib/ClaimProcessorLogic.sol index e3d358d..cedfe5a 100644 --- a/src/lib/ClaimProcessorLogic.sol +++ b/src/lib/ClaimProcessorLogic.sol @@ -50,6 +50,7 @@ import { } 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"; @@ -81,54 +82,54 @@ contract ClaimProcessorLogic is SharedLogic { using HashLib for address; using HashLib for bytes32; using HashLib for uint256; - using HashLib for BasicClaim; - using HashLib for QualifiedClaim; - using HashLib for ClaimWithWitness; - using HashLib for QualifiedClaimWithWitness; - using HashLib for SplitClaim; - using HashLib for SplitClaimWithWitness; - using HashLib for QualifiedSplitClaim; - using HashLib for QualifiedSplitClaimWithWitness; - using HashLib for BatchClaim; - using HashLib for QualifiedBatchClaim; - using HashLib for BatchClaimWithWitness; - using HashLib for QualifiedBatchClaimWithWitness; - using HashLib for SplitBatchClaim; - using HashLib for SplitBatchClaimWithWitness; - using HashLib for QualifiedSplitBatchClaim; - using HashLib for QualifiedSplitBatchClaimWithWitness; - using HashLib for MultichainClaim; - using HashLib for QualifiedMultichainClaim; - using HashLib for MultichainClaimWithWitness; - using HashLib for QualifiedMultichainClaimWithWitness; - using HashLib for SplitMultichainClaim; - using HashLib for SplitMultichainClaimWithWitness; - using HashLib for QualifiedSplitMultichainClaim; - using HashLib for QualifiedSplitMultichainClaimWithWitness; - using HashLib for ExogenousMultichainClaim; - using HashLib for ExogenousQualifiedMultichainClaim; - using HashLib for ExogenousMultichainClaimWithWitness; - using HashLib for ExogenousQualifiedMultichainClaimWithWitness; - using HashLib for ExogenousSplitMultichainClaim; - using HashLib for ExogenousSplitMultichainClaimWithWitness; - using HashLib for ExogenousQualifiedSplitMultichainClaim; - using HashLib for ExogenousQualifiedSplitMultichainClaimWithWitness; - using HashLib for BatchMultichainClaim; - using HashLib for QualifiedBatchMultichainClaim; - using HashLib for BatchMultichainClaimWithWitness; - using HashLib for QualifiedBatchMultichainClaimWithWitness; - using HashLib for SplitBatchMultichainClaim; - using HashLib for SplitBatchMultichainClaimWithWitness; - using HashLib for QualifiedSplitBatchMultichainClaim; - using HashLib for QualifiedSplitBatchMultichainClaimWithWitness; - using HashLib for ExogenousBatchMultichainClaim; - using HashLib for ExogenousQualifiedBatchMultichainClaim; - using HashLib for ExogenousBatchMultichainClaimWithWitness; - using HashLib for ExogenousQualifiedBatchMultichainClaimWithWitness; - using HashLib for ExogenousSplitBatchMultichainClaim; - using HashLib for ExogenousSplitBatchMultichainClaimWithWitness; - using HashLib for ExogenousQualifiedSplitBatchMultichainClaim; - using HashLib for ExogenousQualifiedSplitBatchMultichainClaimWithWitness; + using ClaimHashLib for BasicClaim; + using ClaimHashLib for QualifiedClaim; + using ClaimHashLib for ClaimWithWitness; + using ClaimHashLib for QualifiedClaimWithWitness; + using ClaimHashLib for SplitClaim; + using ClaimHashLib for SplitClaimWithWitness; + using ClaimHashLib for QualifiedSplitClaim; + using ClaimHashLib for QualifiedSplitClaimWithWitness; + using ClaimHashLib for BatchClaim; + using ClaimHashLib for QualifiedBatchClaim; + using ClaimHashLib for BatchClaimWithWitness; + using ClaimHashLib for QualifiedBatchClaimWithWitness; + using ClaimHashLib for SplitBatchClaim; + using ClaimHashLib for SplitBatchClaimWithWitness; + using ClaimHashLib for QualifiedSplitBatchClaim; + using ClaimHashLib for QualifiedSplitBatchClaimWithWitness; + using ClaimHashLib for MultichainClaim; + using ClaimHashLib for QualifiedMultichainClaim; + using ClaimHashLib for MultichainClaimWithWitness; + using ClaimHashLib for QualifiedMultichainClaimWithWitness; + using ClaimHashLib for SplitMultichainClaim; + using ClaimHashLib for SplitMultichainClaimWithWitness; + using ClaimHashLib for QualifiedSplitMultichainClaim; + using ClaimHashLib for QualifiedSplitMultichainClaimWithWitness; + using ClaimHashLib for ExogenousMultichainClaim; + using ClaimHashLib for ExogenousQualifiedMultichainClaim; + using ClaimHashLib for ExogenousMultichainClaimWithWitness; + using ClaimHashLib for ExogenousQualifiedMultichainClaimWithWitness; + using ClaimHashLib for ExogenousSplitMultichainClaim; + using ClaimHashLib for ExogenousSplitMultichainClaimWithWitness; + using ClaimHashLib for ExogenousQualifiedSplitMultichainClaim; + using ClaimHashLib for ExogenousQualifiedSplitMultichainClaimWithWitness; + using ClaimHashLib for BatchMultichainClaim; + using ClaimHashLib for QualifiedBatchMultichainClaim; + using ClaimHashLib for BatchMultichainClaimWithWitness; + using ClaimHashLib for QualifiedBatchMultichainClaimWithWitness; + using ClaimHashLib for SplitBatchMultichainClaim; + using ClaimHashLib for SplitBatchMultichainClaimWithWitness; + using ClaimHashLib for QualifiedSplitBatchMultichainClaim; + using ClaimHashLib for QualifiedSplitBatchMultichainClaimWithWitness; + using ClaimHashLib for ExogenousBatchMultichainClaim; + using ClaimHashLib for ExogenousQualifiedBatchMultichainClaim; + using ClaimHashLib for ExogenousBatchMultichainClaimWithWitness; + using ClaimHashLib for ExogenousQualifiedBatchMultichainClaimWithWitness; + using ClaimHashLib for ExogenousSplitBatchMultichainClaim; + using ClaimHashLib for ExogenousSplitBatchMultichainClaimWithWitness; + using ClaimHashLib for ExogenousQualifiedSplitBatchMultichainClaim; + using ClaimHashLib for ExogenousQualifiedSplitBatchMultichainClaimWithWitness; using IdLib for uint256; using RegistrationLib for address; using ValidityLib for uint96; @@ -137,16 +138,16 @@ contract ClaimProcessorLogic is SharedLogic { ///// 1. Claims ///// function _processBasicClaim(BasicClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - return _processSimpleClaim.usingBasicClaim()(claimPayload.toMessageHash(), claimPayload, uint256(0xa0).asStubborn(), uint256(0).asStubborn().typehashes(), operation); + return _processSimpleClaim.usingBasicClaim()(claimPayload.toClaimHash(), claimPayload, uint256(0xa0).asStubborn(), uint256(0).asStubborn().typehashes(), operation); } function _processQualifiedClaim(QualifiedClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); return _processClaimWithQualification.usingQualifiedClaim()(messageHash, qualificationMessageHash, claimPayload, 0xe0, uint256(0).asStubborn().typehashes(), operation); } function _processClaimWithWitness(ClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSimpleClaim.usingClaimWithWitness()(messageHash, claimPayload, 0xe0, typehash, operation); } @@ -154,21 +155,21 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processClaimWithQualification.usingQualifiedClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x120, typehash, operation); } function _processSplitClaim(SplitClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - return _processSimpleSplitClaim.usingSplitClaim()(claimPayload.toMessageHash(), claimPayload, 0xa0, uint256(0).asStubborn().typehashes(), operation); + return _processSimpleSplitClaim.usingSplitClaim()(claimPayload.toClaimHash(), claimPayload, 0xa0, uint256(0).asStubborn().typehashes(), operation); } function _processQualifiedSplitClaim(QualifiedSplitClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); return _processSplitClaimWithQualification.usingQualifiedSplitClaim()(messageHash, qualificationMessageHash, claimPayload, 0xe0, uint256(0).asStubborn().typehashes(), operation); } function _processSplitClaimWithWitness(SplitClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSimpleSplitClaim.usingSplitClaimWithWitness()(messageHash, claimPayload, 0xe0, typehash, operation); } @@ -176,22 +177,22 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSplitClaimWithQualification.usingQualifiedSplitClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x120, typehash, 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.toMessageHash(), claimPayload, 0xa0, uint256(1).asStubborn().typehashes(), operation); + return _processSimpleBatchClaim.usingBatchClaim()(claimPayload.toClaimHash(), claimPayload, 0xa0, uint256(1).asStubborn().typehashes(), operation); } function _processQualifiedBatchClaim(QualifiedBatchClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); return _processBatchClaimWithQualification.usingQualifiedBatchClaim()(messageHash, qualificationMessageHash, claimPayload, 0xe0, uint256(1).asStubborn().typehashes(), operation); } function _processBatchClaimWithWitness(BatchClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSimpleBatchClaim.usingBatchClaimWithWitness()(messageHash, claimPayload, 0xe0, typehash, operation); } @@ -199,16 +200,16 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processBatchClaimWithQualification.usingQualifiedBatchClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x120, typehash, operation); } function _processSplitBatchClaim(SplitBatchClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - return _processSimpleSplitBatchClaim.usingSplitBatchClaim()(claimPayload.toMessageHash(), claimPayload, 0xa0, uint256(1).asStubborn().typehashes(), operation); + return _processSimpleSplitBatchClaim.usingSplitBatchClaim()(claimPayload.toClaimHash(), claimPayload, 0xa0, uint256(1).asStubborn().typehashes(), operation); } function _processQualifiedSplitBatchClaim(QualifiedSplitBatchClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); return _processSplitBatchClaimWithQualification.usingQualifiedSplitBatchClaim()(messageHash, qualificationMessageHash, claimPayload, 0xe0, uint256(1).asStubborn().typehashes(), operation); } @@ -216,7 +217,7 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSimpleSplitBatchClaim.usingSplitBatchClaimWithWitness()(messageHash, claimPayload, 0xe0, typehash, operation); } @@ -224,17 +225,17 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSplitBatchClaimWithQualification.usingQualifiedSplitBatchClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x120, typehash, 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.toMessageHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), operation); + return _processSimpleClaim.usingMultichainClaim()(claimPayload.toClaimHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), operation); } function _processQualifiedMultichainClaim(QualifiedMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); return _processClaimWithQualification.usingQualifiedMultichainClaim()(messageHash, qualificationMessageHash, claimPayload, 0x100, uint256(2).asStubborn().typehashes(), operation); } @@ -242,7 +243,7 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSimpleClaim.usingMultichainClaimWithWitness()(messageHash, claimPayload, 0x100, typehash, operation); } @@ -250,19 +251,19 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processClaimWithQualification.usingQualifiedMultichainClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x140, typehash, operation); } function _processSplitMultichainClaim(SplitMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - return _processSimpleSplitClaim.usingSplitMultichainClaim()(claimPayload.toMessageHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), operation); + return _processSimpleSplitClaim.usingSplitMultichainClaim()(claimPayload.toClaimHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), operation); } function _processQualifiedSplitMultichainClaim(QualifiedSplitMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); return _processSplitClaimWithQualification.usingQualifiedSplitMultichainClaim()(messageHash, qualificationMessageHash, claimPayload, 0x100, uint256(2).asStubborn().typehashes(), operation); } @@ -270,7 +271,7 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSimpleSplitClaim.usingSplitMultichainClaimWithWitness()(messageHash, claimPayload, 0x100, typehash, operation); } @@ -278,20 +279,20 @@ contract ClaimProcessorLogic is SharedLogic { QualifiedSplitMultichainClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSplitClaimWithQualification.usingQualifiedSplitMultichainClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x140, typehash, 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.toMessageHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), operation); + return _processSimpleBatchClaim.usingBatchMultichainClaim()(claimPayload.toClaimHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), operation); } function _processQualifiedBatchMultichainClaim(QualifiedBatchMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); return _processBatchClaimWithQualification.usingQualifiedBatchMultichainClaim()(messageHash, qualificationMessageHash, claimPayload, 0x100, uint256(2).asStubborn().typehashes(), operation); } @@ -299,7 +300,7 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSimpleBatchClaim.usingBatchMultichainClaimWithWitness()(messageHash, claimPayload, 0x100, typehash, operation); } @@ -307,7 +308,7 @@ contract ClaimProcessorLogic is SharedLogic { QualifiedBatchMultichainClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processBatchClaimWithQualification.usingQualifiedBatchMultichainClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x140, typehash, operation); } @@ -315,14 +316,14 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - return _processSimpleSplitBatchClaim.usingSplitBatchMultichainClaim()(claimPayload.toMessageHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), operation); + return _processSimpleSplitBatchClaim.usingSplitBatchMultichainClaim()(claimPayload.toClaimHash(), claimPayload, 0xc0, uint256(2).asStubborn().typehashes(), operation); } function _processQualifiedSplitBatchMultichainClaim(QualifiedSplitBatchMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); return _processSplitBatchClaimWithQualification.usingQualifiedSplitBatchMultichainClaim()( messageHash, qualificationMessageHash, claimPayload, 0x100, uint256(1).asStubborn().typehashes(), operation ); @@ -332,7 +333,7 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSimpleSplitBatchClaim.usingSplitBatchMultichainClaimWithWitness()(messageHash, claimPayload, 0x100, typehash, operation); } @@ -340,14 +341,14 @@ contract ClaimProcessorLogic is SharedLogic { QualifiedSplitBatchMultichainClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSplitBatchClaimWithQualification.usingQualifiedSplitBatchMultichainClaimWithWitness()(messageHash, qualificationMessageHash, claimPayload, 0x140, typehash, 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.toMessageHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation + claimPayload.toClaimHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation ); } @@ -355,7 +356,7 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); return _processClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedMultichainClaim()( messageHash, qualificationMessageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation ); @@ -365,7 +366,7 @@ contract ClaimProcessorLogic is SharedLogic { internal returns (bool) { - (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processClaimWithSponsorDomain.usingExogenousMultichainClaimWithWitness()(messageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation); } @@ -374,7 +375,7 @@ contract ClaimProcessorLogic is SharedLogic { ExogenousQualifiedMultichainClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedMultichainClaimWithWitness()( messageHash, qualificationMessageHash, claimPayload, 0x180, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation ); @@ -385,7 +386,7 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { return _processSplitClaimWithSponsorDomain.usingExogenousSplitMultichainClaim()( - claimPayload.toMessageHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation + claimPayload.toClaimHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation ); } @@ -393,7 +394,7 @@ contract ClaimProcessorLogic is SharedLogic { ExogenousQualifiedSplitMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); return _processSplitClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedSplitMultichainClaim()( messageHash, qualificationMessageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation ); @@ -403,7 +404,7 @@ contract ClaimProcessorLogic is SharedLogic { ExogenousSplitMultichainClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { - (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSplitClaimWithSponsorDomain.usingExogenousSplitMultichainClaimWithWitness()( messageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation ); @@ -413,7 +414,7 @@ contract ClaimProcessorLogic is SharedLogic { ExogenousQualifiedSplitMultichainClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSplitClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedSplitMultichainClaimWithWitness()( messageHash, qualificationMessageHash, claimPayload, 0x180, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation ); @@ -425,7 +426,7 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { return _processBatchClaimWithSponsorDomain.usingExogenousBatchMultichainClaim()( - claimPayload.toMessageHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation + claimPayload.toClaimHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation ); } @@ -433,7 +434,7 @@ contract ClaimProcessorLogic is SharedLogic { ExogenousQualifiedBatchMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); return _processBatchClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedBatchMultichainClaim()( messageHash, qualificationMessageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation ); @@ -443,7 +444,7 @@ contract ClaimProcessorLogic is SharedLogic { ExogenousBatchMultichainClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { - (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processBatchClaimWithSponsorDomain.usingExogenousBatchMultichainClaimWithWitness()( messageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation ); @@ -453,7 +454,7 @@ contract ClaimProcessorLogic is SharedLogic { ExogenousQualifiedBatchMultichainClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processBatchClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedBatchMultichainClaimWithWitness()( messageHash, qualificationMessageHash, claimPayload, 0x180, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation ); @@ -464,7 +465,7 @@ contract ClaimProcessorLogic is SharedLogic { returns (bool) { return _processSplitBatchClaimWithSponsorDomain.usingExogenousSplitBatchMultichainClaim()( - claimPayload.toMessageHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation + claimPayload.toClaimHash(), claimPayload, 0x100, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation ); } @@ -472,7 +473,7 @@ contract ClaimProcessorLogic is SharedLogic { ExogenousQualifiedSplitBatchMultichainClaim calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash) = claimPayload.toMessageHashes(); return _processSplitBatchClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedSplitBatchMultichainClaim()( messageHash, qualificationMessageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), uint256(2).asStubborn().typehashes(), operation ); @@ -482,7 +483,7 @@ contract ClaimProcessorLogic is SharedLogic { ExogenousSplitBatchMultichainClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { - (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSplitBatchClaimWithSponsorDomain.usingExogenousSplitBatchMultichainClaimWithWitness()( messageHash, claimPayload, 0x140, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation ); @@ -492,7 +493,7 @@ contract ClaimProcessorLogic is SharedLogic { ExogenousQualifiedSplitBatchMultichainClaimWithWitness calldata claimPayload, function(address, address, uint256, uint256) internal returns (bool) operation ) internal returns (bool) { - (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHash(); + (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) = claimPayload.toMessageHashes(); return _processSplitBatchClaimWithQualificationAndSponsorDomain.usingExogenousQualifiedSplitBatchMultichainClaimWithWitness()( messageHash, qualificationMessageHash, claimPayload, 0x180, claimPayload.notarizedChainId.toNotarizedDomainSeparator(), typehash, operation ); diff --git a/src/lib/HashLib.sol b/src/lib/HashLib.sol index 8dffd16..c8686a2 100644 --- a/src/lib/HashLib.sol +++ b/src/lib/HashLib.sol @@ -2,122 +2,35 @@ pragma solidity ^0.8.27; import { - Compact, COMPACT_TYPEHASH, COMPACT_TYPESTRING_FRAGMENT_ONE, COMPACT_TYPESTRING_FRAGMENT_TWO, COMPACT_TYPESTRING_FRAGMENT_THREE, - BatchCompact, BATCH_COMPACT_TYPEHASH, BATCH_COMPACT_TYPESTRING_FRAGMENT_ONE, BATCH_COMPACT_TYPESTRING_FRAGMENT_TWO, BATCH_COMPACT_TYPESTRING_FRAGMENT_THREE, BATCH_COMPACT_TYPESTRING_FRAGMENT_FOUR, - Segment, SEGMENT_TYPEHASH, - MultichainCompact, MULTICHAIN_COMPACT_TYPEHASH, MULTICHAIN_COMPACT_TYPESTRING_FRAGMENT_ONE, MULTICHAIN_COMPACT_TYPESTRING_FRAGMENT_TWO, MULTICHAIN_COMPACT_TYPESTRING_FRAGMENT_THREE, MULTICHAIN_COMPACT_TYPESTRING_FRAGMENT_FOUR, MULTICHAIN_COMPACT_TYPESTRING_FRAGMENT_FIVE, - PERMIT2_ACTIVATION_COMPACT_TYPESTRING_FRAGMENT_ONE, - PERMIT2_ACTIVATION_COMPACT_TYPESTRING_FRAGMENT_TWO, - PERMIT2_ACTIVATION_COMPACT_TYPESTRING_FRAGMENT_THREE, - PERMIT2_ACTIVATION_COMPACT_TYPESTRING_FRAGMENT_FOUR, - PERMIT2_ACTIVATION_BATCH_COMPACT_TYPESTRING_FRAGMENT_ONE, - PERMIT2_ACTIVATION_BATCH_COMPACT_TYPESTRING_FRAGMENT_TWO, - PERMIT2_ACTIVATION_BATCH_COMPACT_TYPESTRING_FRAGMENT_THREE, - PERMIT2_ACTIVATION_BATCH_COMPACT_TYPESTRING_FRAGMENT_FOUR, - PERMIT2_ACTIVATION_MULTICHAIN_COMPACT_TYPESTRING_FRAGMENT_ONE, - PERMIT2_ACTIVATION_MULTICHAIN_COMPACT_TYPESTRING_FRAGMENT_TWO, - PERMIT2_ACTIVATION_MULTICHAIN_COMPACT_TYPESTRING_FRAGMENT_THREE, - PERMIT2_ACTIVATION_MULTICHAIN_COMPACT_TYPESTRING_FRAGMENT_FOUR, - PERMIT2_ACTIVATION_MULTICHAIN_COMPACT_TYPESTRING_FRAGMENT_FIVE, - PERMIT2_ACTIVATION_MULTICHAIN_COMPACT_TYPESTRING_FRAGMENT_SIX, - COMPACT_ACTIVATION_TYPEHASH, - BATCH_COMPACT_ACTIVATION_TYPEHASH, - MULTICHAIN_COMPACT_ACTIVATION_TYPEHASH, - COMPACT_BATCH_ACTIVATION_TYPEHASH, - BATCH_COMPACT_BATCH_ACTIVATION_TYPEHASH, - MULTICHAIN_COMPACT_BATCH_ACTIVATION_TYPEHASH, TOKEN_PERMISSIONS_TYPESTRING_FRAGMENT_ONE, TOKEN_PERMISSIONS_TYPESTRING_FRAGMENT_TWO, PERMIT2_DEPOSIT_WITNESS_FRAGMENT_HASH } from "../types/EIP712Types.sol"; -import { - BasicTransfer, - SplitTransfer, - BasicClaim, - QualifiedClaim, - ClaimWithWitness, - QualifiedClaimWithWitness, - SplitClaim, - SplitClaimWithWitness, - QualifiedSplitClaim, - QualifiedSplitClaimWithWitness -} from "../types/Claims.sol"; - -import { - BatchTransfer, - SplitBatchTransfer, - BatchClaim, - QualifiedBatchClaim, - BatchClaimWithWitness, - QualifiedBatchClaimWithWitness, - SplitBatchClaim, - SplitBatchClaimWithWitness, - QualifiedSplitBatchClaim, - QualifiedSplitBatchClaimWithWitness -} from "../types/BatchClaims.sol"; - -import { - MultichainClaim, - QualifiedMultichainClaim, - MultichainClaimWithWitness, - QualifiedMultichainClaimWithWitness, - SplitMultichainClaim, - SplitMultichainClaimWithWitness, - QualifiedSplitMultichainClaim, - QualifiedSplitMultichainClaimWithWitness, - ExogenousMultichainClaim, - ExogenousQualifiedMultichainClaim, - ExogenousMultichainClaimWithWitness, - ExogenousQualifiedMultichainClaimWithWitness, - ExogenousSplitMultichainClaim, - ExogenousSplitMultichainClaimWithWitness, - ExogenousQualifiedSplitMultichainClaim, - ExogenousQualifiedSplitMultichainClaimWithWitness -} from "../types/MultichainClaims.sol"; +import { BasicTransfer, SplitTransfer } from "../types/Claims.sol"; -import { - BatchMultichainClaim, - QualifiedBatchMultichainClaim, - BatchMultichainClaimWithWitness, - QualifiedBatchMultichainClaimWithWitness, - SplitBatchMultichainClaim, - SplitBatchMultichainClaimWithWitness, - QualifiedSplitBatchMultichainClaim, - QualifiedSplitBatchMultichainClaimWithWitness, - ExogenousBatchMultichainClaim, - ExogenousQualifiedBatchMultichainClaim, - ExogenousBatchMultichainClaimWithWitness, - ExogenousQualifiedBatchMultichainClaimWithWitness, - ExogenousSplitBatchMultichainClaim, - ExogenousSplitBatchMultichainClaimWithWitness, - ExogenousQualifiedSplitBatchMultichainClaim, - ExogenousQualifiedSplitBatchMultichainClaimWithWitness -} from "../types/BatchMultichainClaims.sol"; +import { BatchTransfer, SplitBatchTransfer } from "../types/BatchClaims.sol"; import { TransferComponent, SplitComponent, SplitByIdComponent, BatchClaimComponent, SplitBatchClaimComponent } from "../types/Components.sol"; -import { ResetPeriod } from "../types/ResetPeriod.sol"; -import { Scope } from "../types/Scope.sol"; - -import { FunctionCastLib } from "./FunctionCastLib.sol"; import { EfficiencyLib } from "./EfficiencyLib.sol"; +import { FunctionCastLib } from "./FunctionCastLib.sol"; /** * @title HashLib @@ -128,38 +41,7 @@ import { EfficiencyLib } from "./EfficiencyLib.sol"; library HashLib { using EfficiencyLib for bool; using EfficiencyLib for uint256; - using FunctionCastLib for function(BatchTransfer calldata, uint256) internal view returns (bytes32); - using FunctionCastLib for function(QualifiedClaim calldata) internal view returns (bytes32, bytes32); - using FunctionCastLib for function(uint256, uint256) internal view returns (bytes32, bytes32); - using FunctionCastLib for function(uint256, bytes32, uint256) internal pure returns (bytes32); - using FunctionCastLib for function(QualifiedClaimWithWitness calldata) internal view returns (bytes32, bytes32, bytes32); - using FunctionCastLib for function(SplitBatchClaim calldata, SplitBatchClaimComponent[] calldata) internal view returns (bytes32); - using FunctionCastLib for function(SplitBatchClaimWithWitness calldata, SplitBatchClaimComponent[] calldata) internal view returns (bytes32, bytes32); - using FunctionCastLib for function(uint256, bytes32) internal view returns (bytes32); - using FunctionCastLib for function(uint256, bytes32) internal view returns (bytes32, bytes32); - using FunctionCastLib for function(uint256, uint256) internal view returns (bytes32); - using FunctionCastLib for function(uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32); - using FunctionCastLib for function(BatchClaimWithWitness calldata, bytes32) internal view returns (bytes32, bytes32); - using FunctionCastLib for function(uint256) pure returns (bytes32, bytes32); - using FunctionCastLib for function(uint256, uint256) internal pure returns (uint256); - - using FunctionCastLib for function(uint256, uint256, function(uint256, uint256) internal view returns (bytes32)) internal view returns (bytes32); - using FunctionCastLib for function(uint256, uint256, function(uint256, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32); - using FunctionCastLib for function(uint256, uint256, function(uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32); - using FunctionCastLib for function (uint256, uint256, function(uint256, uint256) internal view returns (bytes32, bytes32)) internal view returns (bytes32, bytes32, bytes32); - using FunctionCastLib for function (uint256, uint256, function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32)) internal view returns (bytes32, bytes32, bytes32); - - using FunctionCastLib for function (BasicClaim calldata) internal view returns (bytes32); - using FunctionCastLib for function (MultichainClaim calldata) internal view returns (bytes32); - using FunctionCastLib for function (ExogenousMultichainClaim calldata) internal view returns (bytes32); - using FunctionCastLib for function (QualifiedClaim calldata) internal view returns (bytes32, bytes32); - using FunctionCastLib for function (QualifiedMultichainClaim calldata) internal view returns (bytes32, bytes32); - using FunctionCastLib for function (ExogenousQualifiedMultichainClaim calldata) internal view returns (bytes32, bytes32); - using FunctionCastLib for function (MultichainClaimWithWitness calldata) internal view returns (bytes32, bytes32); - using FunctionCastLib for function (ExogenousMultichainClaimWithWitness calldata) internal view returns (bytes32, bytes32); - using FunctionCastLib for function (QualifiedClaimWithWitness calldata) internal view returns (bytes32, bytes32, bytes32); - using FunctionCastLib for function (QualifiedMultichainClaimWithWitness calldata) internal view returns (bytes32, bytes32, bytes32); - using FunctionCastLib for function (ExogenousQualifiedMultichainClaimWithWitness calldata) internal view returns (bytes32, bytes32, bytes32); + using FunctionCastLib for function (BatchTransfer calldata, uint256) internal view returns (bytes32); /// @dev `keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")`. bytes32 internal constant _DOMAIN_TYPEHASH = 0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f; @@ -170,228 +52,6 @@ library HashLib { /// @dev `keccak256("0")`. bytes32 internal constant _VERSION_HASH = 0x044852b2a670ade5407e78fb2863c51de9fcb96542a07186fe3aeda6bb8a116d; - ///// CATEGORY 1: Transfer message hashes ///// - function toMessageHash(BasicTransfer calldata transfer) internal view returns (bytes32) { - return _toBasicTransferMessageHash(transfer); - } - - function toMessageHash(SplitTransfer calldata transfer) internal view returns (bytes32) { - return _toSplitTransferMessageHash(transfer); - } - - function toMessageHash(BatchTransfer calldata transfer) internal view returns (bytes32) { - return _toBatchTransferMessageHash(transfer); - } - - function toMessageHash(SplitBatchTransfer calldata transfer) internal view returns (bytes32) { - return _toSplitBatchTransferMessageHash(transfer); - } - - ///// CATEGORY 2: Claim message hashes ///// - function toMessageHash(BasicClaim calldata claim) internal view returns (bytes32) { - return _toBasicMessageHash(claim); - } - - function toMessageHash(SplitClaim calldata claim) internal view returns (bytes32) { - return _toBasicMessageHash.usingSplitClaim()(claim); - } - - function toMessageHash(BatchClaim calldata claim) internal view returns (bytes32) { - return _toGenericMessageHash.usingBatchClaim()(claim, _toIdsAndAmountsHash(claim.claims), _toBatchMessageHash); - } - - function toMessageHash(SplitBatchClaim calldata claim) internal view returns (bytes32) { - return _toGenericMessageHash.usingSplitBatchClaim()(claim, _toSplitIdsAndAmountsHash(claim.claims), _toBatchMessageHash); - } - - function toMessageHash(MultichainClaim calldata claim) internal view returns (bytes32) { - return _toMultichainMessageHash(claim); - } - - function toMessageHash(SplitMultichainClaim calldata claim) internal view returns (bytes32) { - return _toMultichainMessageHash.usingSplitMultichainClaim()(claim); - } - - function toMessageHash(BatchMultichainClaim calldata claim) internal view returns (bytes32) { - return _toGenericMessageHash.usingBatchMultichainClaim()(claim, _toIdsAndAmountsHash(claim.claims), _toSimpleMultichainClaimMessageHash); - } - - function toMessageHash(SplitBatchMultichainClaim calldata claim) internal view returns (bytes32) { - return _toGenericMessageHash.usingSplitBatchMultichainClaim()(claim, _toSplitIdsAndAmountsHash(claim.claims), _toSimpleMultichainClaimMessageHash); - } - - function toMessageHash(ExogenousMultichainClaim calldata claim) internal view returns (bytes32) { - return _toExogenousMultichainMessageHash(claim); - } - - function toMessageHash(ExogenousSplitMultichainClaim calldata claim) internal view returns (bytes32) { - return _toExogenousMultichainMessageHash.usingExogenousSplitMultichainClaim()(claim); - } - - function toMessageHash(ExogenousBatchMultichainClaim calldata claim) internal view returns (bytes32) { - return _toGenericMessageHash.usingExogenousBatchMultichainClaim()(claim, _toIdsAndAmountsHash(claim.claims), _toSimpleExogenousMultichainClaimMessageHash); - } - - function toMessageHash(ExogenousSplitBatchMultichainClaim calldata claim) internal view returns (bytes32) { - return _toGenericMessageHash.usingExogenousSplitBatchMultichainClaim()(claim, _toSplitIdsAndAmountsHash(claim.claims), _toSimpleExogenousMultichainClaimMessageHash); - } - - ///// CATEGORY 3: Qualified claim message & qualification hashes ///// - function toMessageHash(QualifiedClaim calldata claim) internal view returns (bytes32, bytes32) { - return _toQualifiedMessageHash(claim); - } - - function toMessageHash(QualifiedSplitClaim calldata claim) internal view returns (bytes32, bytes32) { - return _toQualifiedMessageHash.usingQualifiedSplitClaim()(claim); - } - - function toMessageHash(QualifiedBatchClaim calldata claim) internal view returns (bytes32, bytes32) { - return _toGenericMessageHashWithQualificationHash.usingQualifiedBatchClaim()(claim, _toIdsAndAmountsHash(claim.claims), _toBatchMessageHash); - } - - function toMessageHash(QualifiedSplitBatchClaim calldata claim) internal view returns (bytes32, bytes32) { - return _toGenericMessageHashWithQualificationHash.usingQualifiedSplitBatchClaim()(claim, _toSplitIdsAndAmountsHash(claim.claims), _toBatchMessageHash); - } - - function toMessageHash(QualifiedMultichainClaim calldata claim) internal view returns (bytes32, bytes32) { - return _toQualifiedMultichainMessageHash(claim); - } - - function toMessageHash(QualifiedSplitMultichainClaim calldata claim) internal view returns (bytes32, bytes32) { - return _toQualifiedMultichainMessageHash.usingQualifiedSplitMultichainClaim()(claim); - } - - function toMessageHash(QualifiedBatchMultichainClaim calldata claim) internal view returns (bytes32, bytes32) { - return _toGenericMessageHashWithQualificationHash.usingQualifiedBatchMultichainClaim()(claim, _toIdsAndAmountsHash(claim.claims), _toQualifiedMultichainClaimMessageHash); - } - - function toMessageHash(QualifiedSplitBatchMultichainClaim calldata claim) internal view returns (bytes32, bytes32) { - return _toGenericMessageHashWithQualificationHash.usingQualifiedSplitBatchMultichainClaim()(claim, _toSplitIdsAndAmountsHash(claim.claims), _toQualifiedMultichainClaimMessageHash); - } - - function toMessageHash(ExogenousQualifiedMultichainClaim calldata claim) internal view returns (bytes32, bytes32) { - return _toExogenousQualifiedMultichainMessageHash(claim); - } - - function toMessageHash(ExogenousQualifiedSplitMultichainClaim calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash) { - return _toExogenousQualifiedMultichainMessageHash.usingExogenousQualifiedSplitMultichainClaim()(claim); - } - - function toMessageHash(ExogenousQualifiedBatchMultichainClaim calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash) { - return _toGenericMessageHashWithQualificationHash.usingExogenousQualifiedBatchMultichainClaim()(claim, _toIdsAndAmountsHash(claim.claims), _toExogenousQualifiedMultichainClaimMessageHash); - } - - function toMessageHash(ExogenousQualifiedSplitBatchMultichainClaim calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash) { - return _toGenericMessageHashWithQualificationHash.usingExogenousQualifiedSplitBatchMultichainClaim()( - claim, _toSplitIdsAndAmountsHash(claim.claims), _toExogenousQualifiedMultichainClaimMessageHash - ); - } - - ///// CATEGORY 4: Claim with witness message & type hashes ///// - function toMessageHash(ClaimWithWitness calldata claim) internal view returns (bytes32, bytes32) { - return _toMessageHashWithWitness.usingClaimWithWitness()(claim, 0); - } - - function toMessageHash(SplitClaimWithWitness calldata claim) internal view returns (bytes32, bytes32) { - return _toMessageHashWithWitness.usingSplitClaimWithWitness()(claim, 0); - } - - function toMessageHash(BatchClaimWithWitness calldata claim) internal view returns (bytes32, bytes32) { - return _toBatchClaimWithWitnessMessageHash.usingBatchClaimWithWitness()(claim, _toIdsAndAmountsHash(claim.claims)); - } - - function toMessageHash(SplitBatchClaimWithWitness calldata claim) internal view returns (bytes32, bytes32) { - return _toBatchClaimWithWitnessMessageHash.usingSplitBatchClaimWithWitness()(claim, _toSplitIdsAndAmountsHash(claim.claims)); - } - - function toMessageHash(MultichainClaimWithWitness calldata claim) internal view returns (bytes32, bytes32) { - return _toMultichainClaimWithWitnessMessageHash(claim); - } - - function toMessageHash(SplitMultichainClaimWithWitness calldata claim) internal view returns (bytes32, bytes32) { - return _toMultichainClaimWithWitnessMessageHash.usingSplitMultichainClaimWithWitness()(claim); - } - - function toMessageHash(BatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32, bytes32) { - return _toGenericMultichainClaimWithWitnessMessageHash.usingBatchMultichainClaimWithWitness()(claim, _toIdsAndAmountsHash(claim.claims), _toMultichainClaimMessageHash); - } - - function toMessageHash(SplitBatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32, bytes32) { - return _toGenericMultichainClaimWithWitnessMessageHash.usingSplitBatchMultichainClaimWithWitness()(claim, _toSplitIdsAndAmountsHash(claim.claims), _toMultichainClaimMessageHash); - } - - function toMessageHash(ExogenousMultichainClaimWithWitness calldata claim) internal view returns (bytes32, bytes32) { - return _toExogenousMultichainClaimWithWitnessMessageHash(claim); - } - - function toMessageHash(ExogenousSplitMultichainClaimWithWitness calldata claim) internal view returns (bytes32, bytes32) { - return _toExogenousMultichainClaimWithWitnessMessageHash.usingExogenousSplitMultichainClaimWithWitness()(claim); - } - - function toMessageHash(ExogenousBatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32, bytes32) { - return _toGenericMultichainClaimWithWitnessMessageHash.usingExogenousBatchMultichainClaimWithWitness()(claim, _toIdsAndAmountsHash(claim.claims), _toExogenousMultichainClaimMessageHash); - } - - function toMessageHash(ExogenousSplitBatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32, bytes32) { - return - _toGenericMultichainClaimWithWitnessMessageHash.usingExogenousSplitBatchMultichainClaimWithWitness()(claim, _toSplitIdsAndAmountsHash(claim.claims), _toExogenousMultichainClaimMessageHash); - } - - ///// CATEGORY 5: Qualified claim with witness message, qualification, & type hashes ///// - function toMessageHash(QualifiedClaimWithWitness calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) { - return _toQualifiedClaimWithWitnessMessageHash(claim); - } - - function toMessageHash(QualifiedSplitClaimWithWitness calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) { - return _toQualifiedClaimWithWitnessMessageHash.usingQualifiedSplitClaimWithWitness()(claim); - } - - function toMessageHash(QualifiedBatchClaimWithWitness calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) { - return _toGenericQualifiedClaimWithWitnessMessageHash.usingQualifiedBatchClaimWithWitness()(claim, _toIdsAndAmountsHash(claim.claims), _toBatchClaimWithWitnessMessageHash); - } - - function toMessageHash(QualifiedSplitBatchClaimWithWitness calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) { - return _toGenericQualifiedClaimWithWitnessMessageHash.usingQualifiedSplitBatchClaimWithWitness()(claim, _toSplitIdsAndAmountsHash(claim.claims), _toBatchClaimWithWitnessMessageHash); - } - - function toMessageHash(QualifiedMultichainClaimWithWitness calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) { - return _toQualifiedMultichainClaimWithWitnessMessageHash(claim); - } - - function toMessageHash(QualifiedSplitMultichainClaimWithWitness calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) { - return _toQualifiedMultichainClaimWithWitnessMessageHash.usingQualifiedSplitMultichainClaimWithWitness()(claim); - } - - function toMessageHash(QualifiedBatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) { - return _toGenericQualifiedMultichainClaimWithWitnessMessageHash.usingQualifiedBatchMultichainClaimWithWitness()(claim, _toIdsAndAmountsHash(claim.claims), _toMultichainClaimMessageHash); - } - - function toMessageHash(QualifiedSplitBatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) { - return - _toGenericQualifiedMultichainClaimWithWitnessMessageHash.usingQualifiedSplitBatchMultichainClaimWithWitness()(claim, _toSplitIdsAndAmountsHash(claim.claims), _toMultichainClaimMessageHash); - } - - function toMessageHash(ExogenousQualifiedMultichainClaimWithWitness calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) { - return _toExogenousQualifiedMultichainClaimWithWitnessMessageHash(claim); - } - - function toMessageHash(ExogenousQualifiedSplitMultichainClaimWithWitness calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) { - return _toExogenousQualifiedMultichainClaimWithWitnessMessageHash.usingExogenousQualifiedSplitMultichainClaimWithWitness()(claim); - } - - function toMessageHash(ExogenousQualifiedBatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) { - return _toGenericQualifiedMultichainClaimWithWitnessMessageHash.usingExogenousQualifiedBatchMultichainClaimWithWitness()( - claim, _toIdsAndAmountsHash(claim.claims), _toExogenousMultichainClaimMessageHash - ); - } - - function toMessageHash(ExogenousQualifiedSplitBatchMultichainClaimWithWitness calldata claim) internal view returns (bytes32 messageHash, bytes32 qualificationMessageHash, bytes32 typehash) { - return _toGenericQualifiedMultichainClaimWithWitnessMessageHash.usingExogenousQualifiedSplitBatchMultichainClaimWithWitness()( - claim, _toSplitIdsAndAmountsHash(claim.claims), _toExogenousMultichainClaimMessageHash - ); - } - - ///// CATEGORY 6: miscellaneous utilities ///// function toLatest(bytes32 initialDomainSeparator, uint256 initialChainId) internal view returns (bytes32 domainSeparator) { domainSeparator = initialDomainSeparator; @@ -438,8 +98,7 @@ library HashLib { } } - ///// Private helper functions ///// - function _toBasicTransferMessageHash(BasicTransfer calldata transfer) private view returns (bytes32 messageHash) { + function toBasicTransferMessageHash(BasicTransfer calldata transfer) internal view returns (bytes32 messageHash) { assembly ("memory-safe") { let m := mload(0x40) // Grab the free memory pointer; memory will be left dirtied. @@ -451,7 +110,7 @@ library HashLib { } } - function _toSplitTransferMessageHash(SplitTransfer calldata transfer) private view returns (bytes32 messageHash) { + function toSplitTransferMessageHash(SplitTransfer calldata transfer) internal view returns (bytes32 messageHash) { uint256 amount = 0; uint256 currentAmount; @@ -486,7 +145,7 @@ library HashLib { } } - function _toBatchTransferMessageHash(BatchTransfer calldata transfer) private view returns (bytes32) { + function toBatchTransferMessageHash(BatchTransfer calldata transfer) internal view returns (bytes32) { TransferComponent[] calldata transfers = transfer.transfers; uint256 idsAndAmountsHash; assembly ("memory-safe") { @@ -497,10 +156,10 @@ library HashLib { idsAndAmountsHash := keccak256(m, totalTransferData) } - return _deriveBatchCompactMessageHash(transfer, idsAndAmountsHash); + return deriveBatchCompactMessageHash(transfer, idsAndAmountsHash); } - function _toSplitBatchTransferMessageHash(SplitBatchTransfer calldata transfer) private view returns (bytes32) { + function toSplitBatchTransferMessageHash(SplitBatchTransfer calldata transfer) internal view returns (bytes32) { SplitByIdComponent[] calldata transfers = transfer.transfers; uint256 totalIds = transfers.length; @@ -541,117 +200,10 @@ library HashLib { idsAndAmountsHash := keccak256(add(idsAndAmounts, 0x20), mload(idsAndAmounts)) } - return _deriveBatchCompactMessageHash.usingSplitBatchTransfer()(transfer, idsAndAmountsHash); - } - - function _toGenericMessageHash(uint256 claim, uint256 additionalInput, function(uint256, uint256) internal view returns (bytes32) hashFn) private view returns (bytes32) { - return hashFn(claim, additionalInput); - } - - function _toBasicMessageHash(BasicClaim calldata claim) private view returns (bytes32) { - return _toGenericMessageHash.usingBasicClaim()(claim, uint256(0).asStubborn(), _toClaimMessageHash); - } - - function _toMultichainMessageHash(MultichainClaim calldata claim) private view returns (bytes32) { - return _toGenericMessageHash.usingMultichainClaim()(claim, _toSingleIdAndAmountHash.usingMultichainClaim()(claim, 0), _toSimpleMultichainClaimMessageHash); - } - - function _toExogenousMultichainMessageHash(ExogenousMultichainClaim calldata claim) private view returns (bytes32) { - return _toGenericMessageHash.usingExogenousMultichainClaim()( - claim, _toSingleIdAndAmountHash.usingExogenousMultichainClaim()(claim, uint256(0x40).asStubborn()), _toSimpleExogenousMultichainClaimMessageHash - ); - } - - function _toGenericMessageHashWithQualificationHash(uint256 claim, uint256 additionalInput, function(uint256, uint256) internal view returns (bytes32) hashFn) - private - view - returns (bytes32 messageHash, bytes32) - { - messageHash = _toGenericMessageHash(claim, additionalInput, hashFn); - return (messageHash, _toQualificationMessageHash(claim, messageHash, uint256(0).asStubborn())); - } - - function _toQualifiedMessageHash(QualifiedClaim calldata claim) private view returns (bytes32, bytes32) { - return _toGenericMessageHashWithQualificationHash.usingQualifiedClaim()(claim, uint256(0x40).asStubborn(), _toClaimMessageHash); - } - - function _toQualifiedMultichainMessageHash(QualifiedMultichainClaim calldata claim) private view returns (bytes32, bytes32) { - return _toGenericMessageHashWithQualificationHash.usingQualifiedMultichainClaim()( - claim, _toSingleIdAndAmountHash.usingQualifiedMultichainClaim()(claim, uint256(0x40).asStubborn()), _toQualifiedMultichainClaimMessageHash - ); - } - - function _toExogenousQualifiedMultichainMessageHash(ExogenousQualifiedMultichainClaim calldata claim) private view returns (bytes32, bytes32) { - return _toGenericMessageHashWithQualificationHash.usingExogenousQualifiedMultichainClaim()( - claim, _toSingleIdAndAmountHash.usingExogenousQualifiedMultichainClaim()(claim, uint256(0x80).asStubborn()), _toExogenousQualifiedMultichainClaimMessageHash - ); - } - - function _toGenericMultichainClaimWithWitnessMessageHash(uint256 claim, uint256 additionalInput, function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32) hashFn) - private - view - returns (bytes32, bytes32) - { - (bytes32 allocationTypehash, bytes32 typehash) = _toMultichainTypehashes(claim); - return (hashFn(claim, uint256(0x40).asStubborn(), allocationTypehash, typehash, additionalInput), typehash); - } - - function _toGenericMultichainClaimWithWitnessMessageHashPriorToQualification( - uint256 claim, - uint256 additionalInput, - function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32) hashFn - ) private view returns (bytes32, bytes32) { - (bytes32 allocationTypehash, bytes32 typehash) = _toMultichainTypehashes(claim); - return (hashFn(claim, uint256(0x80).asStubborn(), allocationTypehash, typehash, additionalInput), typehash); - } - - function _toMultichainClaimWithWitnessMessageHash(MultichainClaimWithWitness calldata claim) private view returns (bytes32, bytes32) { - return _toGenericMultichainClaimWithWitnessMessageHash.usingMultichainClaimWithWitness()( - claim, _toSingleIdAndAmountHash.usingMultichainClaimWithWitness()(claim, uint256(0x40).asStubborn()), _toMultichainClaimMessageHash - ); - } - - function _toExogenousMultichainClaimWithWitnessMessageHash(ExogenousMultichainClaimWithWitness calldata claim) private view returns (bytes32, bytes32) { - return _toGenericMultichainClaimWithWitnessMessageHash.usingExogenousMultichainClaimWithWitness()( - claim, _toSingleIdAndAmountHash.usingExogenousMultichainClaimWithWitness()(claim, uint256(0x80).asStubborn()), _toExogenousMultichainClaimMessageHash - ); - } - - function _toGenericQualifiedClaimWithWitnessMessageHash(uint256 claim, uint256 additionalInput, function (uint256, uint256) internal view returns (bytes32, bytes32) hashFn) - private - view - returns (bytes32, bytes32, bytes32) - { - (bytes32 messageHash, bytes32 typehash) = hashFn(claim, additionalInput); - return (messageHash, _toQualificationMessageHash(claim, messageHash, uint256(0x40).asStubborn()), typehash); - } - - function _toQualifiedClaimWithWitnessMessageHash(QualifiedClaimWithWitness calldata claim) private view returns (bytes32, bytes32, bytes32) { - return _toGenericQualifiedClaimWithWitnessMessageHash.usingQualifiedClaimWithWitness()(claim, uint256(0x40).asStubborn(), _toMessageHashWithWitness); - } - - function _toGenericQualifiedMultichainClaimWithWitnessMessageHash( - uint256 claim, - uint256 additionalInput, - function (uint256, uint256, bytes32, bytes32, uint256) internal view returns (bytes32) hashFn - ) private view returns (bytes32, bytes32, bytes32) { - (bytes32 messageHash, bytes32 typehash) = _toGenericMultichainClaimWithWitnessMessageHashPriorToQualification(claim, additionalInput, hashFn); - return (messageHash, _toQualificationMessageHash(claim, messageHash, uint256(0x40).asStubborn()), typehash); - } - - function _toQualifiedMultichainClaimWithWitnessMessageHash(QualifiedMultichainClaimWithWitness calldata claim) private view returns (bytes32, bytes32, bytes32) { - return _toGenericQualifiedMultichainClaimWithWitnessMessageHash.usingQualifiedMultichainClaimWithWitness()( - claim, _toSingleIdAndAmountHash.usingQualifiedMultichainClaimWithWitness()(claim, uint256(0x80).asStubborn()), _toMultichainClaimMessageHash - ); - } - - function _toExogenousQualifiedMultichainClaimWithWitnessMessageHash(ExogenousQualifiedMultichainClaimWithWitness calldata claim) private view returns (bytes32, bytes32, bytes32) { - return _toGenericQualifiedMultichainClaimWithWitnessMessageHash.usingExogenousQualifiedMultichainClaimWithWitness()( - claim, _toSingleIdAndAmountHash.usingExogenousQualifiedMultichainClaimWithWitness()(claim, uint256(0xc0).asStubborn()), _toExogenousMultichainClaimMessageHash - ); + return deriveBatchCompactMessageHash.usingSplitBatchTransfer()(transfer, idsAndAmountsHash); } - function _toClaimMessageHash(uint256 claim, uint256 additionalOffset) private view returns (bytes32 messageHash) { + function toClaimMessageHash(uint256 claim, uint256 additionalOffset) internal view returns (bytes32 messageHash) { assembly ("memory-safe") { let m := mload(0x40) // Grab the free memory pointer; memory will be left dirtied. @@ -666,7 +218,7 @@ library HashLib { } } - function _toMessageHashWithWitness(uint256 claim, uint256 qualificationOffset) private view returns (bytes32 messageHash, bytes32 typehash) { + function toMessageHashWithWitness(uint256 claim, uint256 qualificationOffset) internal view returns (bytes32 messageHash, bytes32 typehash) { assembly ("memory-safe") { let m := mload(0x40) // Grab the free memory pointer; memory will be left dirtied. @@ -690,7 +242,7 @@ library HashLib { } } - function _deriveBatchCompactMessageHash(BatchTransfer calldata transfer, uint256 idsAndAmountsHash) private view returns (bytes32 messageHash) { + function deriveBatchCompactMessageHash(BatchTransfer calldata transfer, uint256 idsAndAmountsHash) internal view returns (bytes32 messageHash) { assembly ("memory-safe") { let m := mload(0x40) // Grab the free memory pointer; memory will be left dirtied. @@ -704,7 +256,7 @@ library HashLib { } } - function _toBatchMessageHash(uint256 claim, uint256 idsAndAmountsHash) private view returns (bytes32 messageHash) { + function toBatchMessageHash(uint256 claim, uint256 idsAndAmountsHash) internal view returns (bytes32 messageHash) { assembly ("memory-safe") { let m := mload(0x40) // Grab the free memory pointer; memory will be left dirtied. @@ -716,7 +268,7 @@ library HashLib { } } - function _toBatchClaimWithWitnessMessageHash(uint256 claim, uint256 idsAndAmountsHash) private view returns (bytes32 messageHash, bytes32 typehash) { + function toBatchClaimWithWitnessMessageHash(uint256 claim, uint256 idsAndAmountsHash) internal view returns (bytes32 messageHash, bytes32 typehash) { assembly ("memory-safe") { let m := mload(0x40) // Grab the free memory pointer; memory will be left dirtied. @@ -740,7 +292,7 @@ library HashLib { } } - function _toSingleIdAndAmountHash(uint256 claim, uint256 additionalOffset) private pure returns (uint256 idsAndAmountsHash) { + function toSingleIdAndAmountHash(uint256 claim, uint256 additionalOffset) internal pure returns (uint256 idsAndAmountsHash) { assembly ("memory-safe") { let claimWithAdditionalOffset := add(claim, additionalOffset) @@ -751,16 +303,16 @@ library HashLib { } } - function _toSimpleMultichainClaimMessageHash(uint256 claim, uint256 idsAndAmountsHash) private view returns (bytes32 messageHash) { - return _toMultichainClaimMessageHash(claim, uint256(0).asStubborn(), SEGMENT_TYPEHASH, MULTICHAIN_COMPACT_TYPEHASH, idsAndAmountsHash); + function toSimpleMultichainClaimMessageHash(uint256 claim, uint256 idsAndAmountsHash) internal view returns (bytes32 messageHash) { + return toMultichainClaimMessageHash(claim, uint256(0).asStubborn(), SEGMENT_TYPEHASH, MULTICHAIN_COMPACT_TYPEHASH, idsAndAmountsHash); } - function _toQualifiedMultichainClaimMessageHash(uint256 claim, uint256 idsAndAmountsHash) private view returns (bytes32 messageHash) { - return _toMultichainClaimMessageHash(claim, uint256(0x40).asStubborn(), SEGMENT_TYPEHASH, MULTICHAIN_COMPACT_TYPEHASH, idsAndAmountsHash); + function toQualifiedMultichainClaimMessageHash(uint256 claim, uint256 idsAndAmountsHash) internal view returns (bytes32 messageHash) { + return toMultichainClaimMessageHash(claim, uint256(0x40).asStubborn(), SEGMENT_TYPEHASH, MULTICHAIN_COMPACT_TYPEHASH, idsAndAmountsHash); } - function _toMultichainClaimMessageHash(uint256 claim, uint256 additionalOffset, bytes32 allocationTypehash, bytes32 multichainCompactTypehash, uint256 idsAndAmountsHash) - private + function toMultichainClaimMessageHash(uint256 claim, uint256 additionalOffset, bytes32 allocationTypehash, bytes32 multichainCompactTypehash, uint256 idsAndAmountsHash) + internal view returns (bytes32 messageHash) { @@ -792,16 +344,16 @@ library HashLib { } } - function _toSimpleExogenousMultichainClaimMessageHash(uint256 claim, uint256 idsAndAmountsHash) private view returns (bytes32 messageHash) { - return _toExogenousMultichainClaimMessageHash(claim, uint256(0).asStubborn(), SEGMENT_TYPEHASH, MULTICHAIN_COMPACT_TYPEHASH, idsAndAmountsHash); + function toSimpleExogenousMultichainClaimMessageHash(uint256 claim, uint256 idsAndAmountsHash) internal view returns (bytes32 messageHash) { + return toExogenousMultichainClaimMessageHash(claim, uint256(0).asStubborn(), SEGMENT_TYPEHASH, MULTICHAIN_COMPACT_TYPEHASH, idsAndAmountsHash); } - function _toExogenousQualifiedMultichainClaimMessageHash(uint256 claim, uint256 idsAndAmountsHash) private view returns (bytes32 messageHash) { - return _toExogenousMultichainClaimMessageHash(claim, uint256(0x40).asStubborn(), SEGMENT_TYPEHASH, MULTICHAIN_COMPACT_TYPEHASH, idsAndAmountsHash); + function toExogenousQualifiedMultichainClaimMessageHash(uint256 claim, uint256 idsAndAmountsHash) internal view returns (bytes32 messageHash) { + return toExogenousMultichainClaimMessageHash(claim, uint256(0x40).asStubborn(), SEGMENT_TYPEHASH, MULTICHAIN_COMPACT_TYPEHASH, idsAndAmountsHash); } - function _toExogenousMultichainClaimMessageHash(uint256 claim, uint256 additionalOffset, bytes32 allocationTypehash, bytes32 multichainCompactTypehash, uint256 idsAndAmountsHash) - private + function toExogenousMultichainClaimMessageHash(uint256 claim, uint256 additionalOffset, bytes32 allocationTypehash, bytes32 multichainCompactTypehash, uint256 idsAndAmountsHash) + internal view returns (bytes32 messageHash) { @@ -846,7 +398,7 @@ library HashLib { } } - function _toIdsAndAmountsHash(BatchClaimComponent[] calldata claims) private pure returns (uint256 idsAndAmountsHash) { + function toIdsAndAmountsHash(BatchClaimComponent[] calldata claims) internal pure returns (uint256 idsAndAmountsHash) { uint256 totalIds = claims.length; bytes memory idsAndAmounts = new bytes(totalIds * 0x40); @@ -866,7 +418,7 @@ library HashLib { } } - function _toSplitIdsAndAmountsHash(SplitBatchClaimComponent[] calldata claims) private pure returns (uint256 idsAndAmountsHash) { + function toSplitIdsAndAmountsHash(SplitBatchClaimComponent[] calldata claims) internal pure returns (uint256 idsAndAmountsHash) { uint256 totalIds = claims.length; bytes memory idsAndAmounts = new bytes(totalIds * 0x40); @@ -886,7 +438,7 @@ library HashLib { } } - function _toMultichainTypehashes(uint256 claim) private pure returns (bytes32 allocationTypehash, bytes32 multichainCompactTypehash) { + function toMultichainTypehashes(uint256 claim) internal pure returns (bytes32 allocationTypehash, bytes32 multichainCompactTypehash) { assembly ("memory-safe") { let m := mload(0x40) // Grab the free memory pointer; memory will be left dirtied. @@ -906,7 +458,7 @@ library HashLib { } } - function _toQualificationMessageHash(uint256 claim, bytes32 messageHash, uint256 witnessOffset) private pure returns (bytes32 qualificationMessageHash) { + function toQualificationMessageHash(uint256 claim, bytes32 messageHash, uint256 witnessOffset) internal pure returns (bytes32 qualificationMessageHash) { assembly ("memory-safe") { let m := mload(0x40) // Grab the free memory pointer; memory will be left dirtied. diff --git a/src/lib/TransferLogic.sol b/src/lib/TransferLogic.sol index 1758132..9936e71 100644 --- a/src/lib/TransferLogic.sol +++ b/src/lib/TransferLogic.sol @@ -5,9 +5,9 @@ import { BatchTransfer, SplitBatchTransfer } from "../types/BatchClaims.sol"; import { BasicTransfer, SplitTransfer } from "../types/Claims.sol"; import { SplitComponent, TransferComponent, SplitByIdComponent } from "../types/Components.sol"; +import { ClaimHashLib } from "./ClaimHashLib.sol"; import { EfficiencyLib } from "./EfficiencyLib.sol"; import { FunctionCastLib } from "./FunctionCastLib.sol"; -import { HashLib } from "./HashLib.sol"; import { IdLib } from "./IdLib.sol"; import { SharedLogic } from "./SharedLogic.sol"; import { ValidityLib } from "./ValidityLib.sol"; @@ -21,10 +21,10 @@ import { ValidityLib } from "./ValidityLib.sol"; * sponsor. */ contract TransferLogic is SharedLogic { - using HashLib for BasicTransfer; - using HashLib for SplitTransfer; - using HashLib for BatchTransfer; - using HashLib for SplitBatchTransfer; + using ClaimHashLib for BasicTransfer; + using ClaimHashLib for SplitTransfer; + using ClaimHashLib for BatchTransfer; + using ClaimHashLib for SplitBatchTransfer; using IdLib for uint256; using EfficiencyLib for bool; using ValidityLib for uint96; @@ -45,7 +45,7 @@ contract TransferLogic is SharedLogic { */ function _processBasicTransfer(BasicTransfer calldata transfer, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { // Derive hash, validate expiry, consume nonce, and check allocator signature. - _notExpiredAndSignedByAllocator(transfer.toMessageHash(), transfer.id.toRegisteredAllocatorWithConsumed(transfer.nonce), transfer); + _notExpiredAndSignedByAllocator(transfer.toClaimHash(), transfer.id.toRegisteredAllocatorWithConsumed(transfer.nonce), transfer); // Perform the transfer or withdrawal. return operation(msg.sender, transfer.recipient, transfer.id, transfer.amount); @@ -61,7 +61,7 @@ contract TransferLogic is SharedLogic { */ function _processSplitTransfer(SplitTransfer calldata transfer, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { // Derive hash, validate expiry, consume nonce, and check allocator signature. - _notExpiredAndSignedByAllocator.usingSplitTransfer()(transfer.toMessageHash(), transfer.id.toRegisteredAllocatorWithConsumed(transfer.nonce), transfer); + _notExpiredAndSignedByAllocator.usingSplitTransfer()(transfer.toClaimHash(), transfer.id.toRegisteredAllocatorWithConsumed(transfer.nonce), transfer); // Retrieve the total number of components. uint256 totalSplits = transfer.recipients.length; @@ -91,7 +91,7 @@ contract TransferLogic is SharedLogic { */ function _processBatchTransfer(BatchTransfer calldata transfer, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { // Derive hash, validate expiry, consume nonce, and check allocator signature. - _notExpiredAndSignedByAllocator.usingBatchTransfer()(transfer.toMessageHash(), _deriveConsistentAllocatorAndConsumeNonce(transfer.transfers, transfer.nonce), transfer); + _notExpiredAndSignedByAllocator.usingBatchTransfer()(transfer.toClaimHash(), _deriveConsistentAllocatorAndConsumeNonce(transfer.transfers, transfer.nonce), transfer); // Retrieve the total number of components. uint256 totalTransfers = transfer.transfers.length; @@ -121,7 +121,7 @@ contract TransferLogic is SharedLogic { */ function _processSplitBatchTransfer(SplitBatchTransfer calldata transfer, function(address, address, uint256, uint256) internal returns (bool) operation) internal returns (bool) { // Derive hash, validate expiry, consume nonce, and check allocator signature. - _notExpiredAndSignedByAllocator.usingSplitBatchTransfer()(transfer.toMessageHash(), _deriveConsistentAllocatorAndConsumeNonceWithSplit(transfer.transfers, transfer.nonce), transfer); + _notExpiredAndSignedByAllocator.usingSplitBatchTransfer()(transfer.toClaimHash(), _deriveConsistentAllocatorAndConsumeNonceWithSplit(transfer.transfers, transfer.nonce), transfer); // Declare a variable for tracking the id of each component. uint256 id;