Skip to content

Commit

Permalink
put HashLib function cast in and rename
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Nov 4, 2024
1 parent f363d90 commit 430864c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
16 changes: 0 additions & 16 deletions src/lib/FunctionCastLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2764,20 +2764,4 @@ library FunctionCastLib {
fnOut := fnIn
}
}

/**
* @notice Function cast to provide a SplitBatchTransfer calldata struct while
* treating it as a BatchTransfer calldata struct.
* @param fnIn Function pointer to HashLib.toBatchTransferMessageHashUsingIdsAndAmountsHash(BatchTransfer calldata, uint256)
* @return fnOut Modified function for HashLib.toBatchTransferMessageHashUsingIdsAndAmountsHash(SplitBatchTransfer calldata, uint256)
*/
function usingSplitBatchTransfer(function(BatchTransfer calldata, uint256) internal view returns (bytes32) fnIn)
internal
pure
returns (function(SplitBatchTransfer calldata, uint256) internal view returns (bytes32) fnOut)
{
assembly ("memory-safe") {
fnOut := fnIn
}
}
}
4 changes: 2 additions & 2 deletions src/lib/HashLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from "../types/EIP712Types.sol";

import { EfficiencyLib } from "./EfficiencyLib.sol";
import { FunctionCastLib } from "./FunctionCastLib.sol";
import { TransferFunctionCastLib } from "./TransferFunctionCastLib.sol";

/**
* @title HashLib
Expand All @@ -39,7 +39,7 @@ import { FunctionCastLib } from "./FunctionCastLib.sol";
library HashLib {
using EfficiencyLib for bool;
using EfficiencyLib for uint256;
using FunctionCastLib for function (BatchTransfer calldata, uint256) internal view returns (bytes32);
using TransferFunctionCastLib for function (BatchTransfer calldata, uint256) internal view returns (bytes32);
using HashLib for uint256;
using HashLib for BatchTransfer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import { BasicTransfer, SplitTransfer } from "../types/Claims.sol";
import { TransferComponent, SplitByIdComponent } from "../types/Components.sol";

/**
* @title TransferLogicFunctionCastLib
* @notice Libray contract implementing function casts used in TransferLogic.
* The input function operates on a function that takes some argument that differs
* from what is currently available. The output function modifies one or more argument
* types so that they match the arguments that are being used to call the function.
* Note that from the perspective of the function being modified, the original type is
* still in force; great care should be taken to preserve offsets and general structure
* between the two structs.
* @title TransferFunctionCastLib
* @notice Libray contract implementing function casts used in TransferLogic as well as
* in HashLib. The input function operates on a function that takes some argument that
* differs from what is currently available. The output function modifies one or more
* argument types so that they match the arguments that are being used to call the
* function. Note that from the perspective of the function being modified, the original
* type is still in force; great care should be taken to preserve offsets and general
* structure between the two structs.
*/
library TransferLogicFunctionCastLib {
library TransferFunctionCastLib {
/**
* @notice Function cast to provide a SplitTransfer calldata struct while
* treating it as a BasicTransfer calldata struct.
* @param fnIn Function pointer to `_notExpiredAndSignedByAllocator`.
* @return fnOut Modified function used in `_processSplitTransfer`.
* @param fnIn Function pointer to `TransferLogic._notExpiredAndSignedByAllocator`.
* @return fnOut Modified function used in `TransferLogic._processSplitTransfer`.
*/
function usingSplitTransfer(function (bytes32, address, BasicTransfer calldata) internal fnIn) internal pure returns (function (bytes32, address, SplitTransfer calldata) internal fnOut) {
assembly ("memory-safe") {
Expand All @@ -31,8 +31,8 @@ library TransferLogicFunctionCastLib {
/**
* @notice Function cast to provide a BatchTransfer calldata struct while
* treating it as a BasicTransfer calldata struct.
* @param fnIn Function pointer to `_notExpiredAndSignedByAllocator`.
* @return fnOut Modified function used in `_processBatchTransfer`.
* @param fnIn Function pointer to `TransferLogic._notExpiredAndSignedByAllocator`.
* @return fnOut Modified function used in `TransferLogic._processBatchTransfer`.
*/
function usingBatchTransfer(function (bytes32, address, BasicTransfer calldata) internal fnIn) internal pure returns (function (bytes32, address, BatchTransfer calldata) internal fnOut) {
assembly ("memory-safe") {
Expand All @@ -43,8 +43,8 @@ library TransferLogicFunctionCastLib {
/**
* @notice Function cast to provide a SplitBatchTransfer calldata struct while
* treating it as a BasicTransfer calldata struct.
* @param fnIn Function pointer to `_notExpiredAndSignedByAllocator`.
* @return fnOut Modified function used in `_processSplitBatchTransfer`.
* @param fnIn Function pointer to `TransferLogic._notExpiredAndSignedByAllocator`.
* @return fnOut Modified function used in `TransferLogic._processSplitBatchTransfer`.
*/
function usingSplitBatchTransfer(function (bytes32, address, BasicTransfer calldata) internal fnIn)
internal
Expand All @@ -59,8 +59,8 @@ library TransferLogicFunctionCastLib {
/**
* @notice Function cast to provide a SplitByIdComponent array while treating it
* as a TransferComponent array.
* @param fnIn Function pointer to `_deriveConsistentAllocatorAndConsumeNonce`.
* @return fnOut Modified function used in `_processSplitBatchTransfer`.
* @param fnIn Function pointer to `TransferLogic._deriveConsistentAllocatorAndConsumeNonce`.
* @return fnOut Modified function used in `TransferLogic._processSplitBatchTransfer`.
*/
function usingSplitByIdComponent(function(TransferComponent[] calldata, uint256, function (TransferComponent[] calldata, uint256) internal pure returns (uint96)) internal returns (address) fnIn)
internal
Expand All @@ -71,4 +71,20 @@ library TransferLogicFunctionCastLib {
fnOut := fnIn
}
}

/**
* @notice Function cast to provide a SplitBatchTransfer calldata struct while
* treating it as a BatchTransfer calldata struct.
* @param fnIn Function pointer to `HashLib.toBatchTransferMessageHashUsingIdsAndAmountsHash`.
* @return fnOut Modified function for `HashLib.toSplitBatchTransferMessageHash`.
*/
function usingSplitBatchTransfer(function(BatchTransfer calldata, uint256) internal view returns (bytes32) fnIn)
internal
pure
returns (function(SplitBatchTransfer calldata, uint256) internal view returns (bytes32) fnOut)
{
assembly ("memory-safe") {
fnOut := fnIn
}
}
}
6 changes: 3 additions & 3 deletions src/lib/TransferLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ClaimHashLib } from "./ClaimHashLib.sol";
import { ComponentLib } from "./ComponentLib.sol";
import { EfficiencyLib } from "./EfficiencyLib.sol";
import { EventLib } from "./EventLib.sol";
import { TransferLogicFunctionCastLib } from "./TransferLogicFunctionCastLib.sol";
import { TransferFunctionCastLib } from "./TransferFunctionCastLib.sol";
import { IdLib } from "./IdLib.sol";
import { SharedLogic } from "./SharedLogic.sol";
import { ValidityLib } from "./ValidityLib.sol";
Expand All @@ -36,8 +36,8 @@ contract TransferLogic is SharedLogic {
using ValidityLib for uint96;
using ValidityLib for uint256;
using ValidityLib for bytes32;
using TransferLogicFunctionCastLib for function (bytes32, address, BasicTransfer calldata) internal;
using TransferLogicFunctionCastLib for function(TransferComponent[] calldata, uint256, function (TransferComponent[] calldata, uint256) internal pure returns (uint96)) internal returns (address);
using TransferFunctionCastLib for function (bytes32, address, BasicTransfer calldata) internal;
using TransferFunctionCastLib for function(TransferComponent[] calldata, uint256, function (TransferComponent[] calldata, uint256) internal pure returns (uint96)) internal returns (address);

// bytes4(keccak256("attest(address,address,address,uint256,uint256)")).
uint32 private constant _ATTEST_SELECTOR = 0x1a808f91;
Expand Down

0 comments on commit 430864c

Please sign in to comment.