SignatureTransfer

Git Source

Inherits: ISignatureTransfer, EIP712

State Variables

nonceBitmap

A map from token owner address and a caller specified word index to a bitmap. Used to set bits in the bitmap to prevent against signature replay protection

Uses unordered nonces so that permit messages do not need to be spent in a certain order

mapping(address => mapping(uint256 => uint256)) public nonceBitmap;

Functions

permitTransferFrom

Transfers a token using a signed permit message

Reverts if the requested amount is greater than the permitted signed amount

function permitTransferFrom(
    PermitTransferFrom memory permit,
    SignatureTransferDetails calldata transferDetails,
    address owner,
    bytes calldata signature
) external;

Parameters

NameTypeDescription
permitPermitTransferFromThe permit data signed over by the owner
transferDetailsSignatureTransferDetailsThe spender's requested transfer details for the permitted token
owneraddressThe owner of the tokens to transfer
signaturebytesThe signature to verify

permitWitnessTransferFrom

Transfers a token using a signed permit message

The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition

function permitWitnessTransferFrom(
    PermitTransferFrom memory permit,
    SignatureTransferDetails calldata transferDetails,
    address owner,
    bytes32 witness,
    string calldata witnessTypeString,
    bytes calldata signature
) external;

Parameters

NameTypeDescription
permitPermitTransferFromThe permit data signed over by the owner
transferDetailsSignatureTransferDetailsThe spender's requested transfer details for the permitted token
owneraddressThe owner of the tokens to transfer
witnessbytes32Extra data to include when checking the user signature
witnessTypeStringstringThe EIP-712 type definition for remaining string stub of the typehash
signaturebytesThe signature to verify

_permitTransferFrom

Transfers a token using a signed permit message.

function _permitTransferFrom(
    PermitTransferFrom memory permit,
    SignatureTransferDetails calldata transferDetails,
    address owner,
    bytes32 dataHash,
    bytes calldata signature
) private;

Parameters

NameTypeDescription
permitPermitTransferFromThe permit data signed over by the owner
transferDetailsSignatureTransferDetailsThe spender's requested transfer details for the permitted token
owneraddressThe owner of the tokens to transfer
dataHashbytes32The EIP-712 hash of permit data to include when checking signature
signaturebytesThe signature to verify

permitTransferFrom

Transfers a token using a signed permit message

Reverts if the requested amount is greater than the permitted signed amount

function permitTransferFrom(
    PermitBatchTransferFrom memory permit,
    SignatureTransferDetails[] calldata transferDetails,
    address owner,
    bytes calldata signature
) external;

Parameters

NameTypeDescription
permitPermitBatchTransferFromThe permit data signed over by the owner
transferDetailsSignatureTransferDetails[]The spender's requested transfer details for the permitted token
owneraddressThe owner of the tokens to transfer
signaturebytesThe signature to verify

permitWitnessTransferFrom

Transfers a token using a signed permit message

The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition

function permitWitnessTransferFrom(
    PermitBatchTransferFrom memory permit,
    SignatureTransferDetails[] calldata transferDetails,
    address owner,
    bytes32 witness,
    string calldata witnessTypeString,
    bytes calldata signature
) external;

Parameters

NameTypeDescription
permitPermitBatchTransferFromThe permit data signed over by the owner
transferDetailsSignatureTransferDetails[]The spender's requested transfer details for the permitted token
owneraddressThe owner of the tokens to transfer
witnessbytes32Extra data to include when checking the user signature
witnessTypeStringstringThe EIP-712 type definition for remaining string stub of the typehash
signaturebytesThe signature to verify

_permitTransferFrom

Transfers tokens using a signed permit messages

function _permitTransferFrom(
    PermitBatchTransferFrom memory permit,
    SignatureTransferDetails[] calldata transferDetails,
    address owner,
    bytes32 dataHash,
    bytes calldata signature
) private;

Parameters

NameTypeDescription
permitPermitBatchTransferFromThe permit data signed over by the owner
transferDetailsSignatureTransferDetails[]
owneraddressThe owner of the tokens to transfer
dataHashbytes32The EIP-712 hash of permit data to include when checking signature
signaturebytesThe signature to verify

invalidateUnorderedNonces

Invalidates the bits specified in mask for the bitmap at the word position

The wordPos is maxed at type(uint248).max

function invalidateUnorderedNonces(uint256 wordPos, uint256 mask) external;

Parameters

NameTypeDescription
wordPosuint256A number to index the nonceBitmap at
maskuint256A bitmap masked against msg.sender's current bitmap at the word position

bitmapPositions

Returns the index of the bitmap and the bit position within the bitmap. Used for unordered nonces

The first 248 bits of the nonce value is the index of the desired bitmap

The last 8 bits of the nonce value is the position of the bit in the bitmap

function bitmapPositions(uint256 nonce) private pure returns (uint256 wordPos, uint256 bitPos);

Parameters

NameTypeDescription
nonceuint256The nonce to get the associated word and bit positions

Returns

NameTypeDescription
wordPosuint256The word position or index into the nonceBitmap
bitPosuint256The bit position

_useUnorderedNonce

Checks whether a nonce is taken and sets the bit at the bit position in the bitmap at the word position

function _useUnorderedNonce(address from, uint256 nonce) internal;

Parameters

NameTypeDescription
fromaddressThe address to use the nonce at
nonceuint256The nonce to spend