ByteString

Git Source

Attach library functions to Signature

State Variables

SIGNATURE_LENGTH

non-compact ECDSA signatures are enforced as of OZ 4.7.3 Signature payload memory layout [000 .. 032) r bytes32 32 bytes [032 .. 064) s bytes32 32 bytes [064 .. 065) v uint8 1 byte

uint256 internal constant SIGNATURE_LENGTH = 65;

OFFSET_R

uint256 private constant OFFSET_R = 0;

OFFSET_S

uint256 private constant OFFSET_S = 32;

OFFSET_V

uint256 private constant OFFSET_V = 64;

SELECTOR_LENGTH

Calldata memory layout [000 .. 004) selector bytes4 4 bytes Optional: N function arguments [004 .. 036) arg1 bytes32 32 bytes .. [AAA .. END) argN bytes32 32 bytes

uint256 internal constant SELECTOR_LENGTH = 4;

OFFSET_SELECTOR

uint256 private constant OFFSET_SELECTOR = 0;

OFFSET_ARGUMENTS

uint256 private constant OFFSET_ARGUMENTS = SELECTOR_LENGTH;

Functions

formatSignature

Constructs the signature payload from the given values.

Using ByteString.formatSignature({r: r, s: s, v: v}) will make sure that params are given in the right order.

function formatSignature(bytes32 r, bytes32 s, uint8 v) internal pure returns (bytes memory);

castToSignature

Returns a Signature view over for the given payload.

Will revert if the payload is not a signature.

function castToSignature(bytes memory payload) internal pure returns (Signature);

castToSignature

Casts a memory view to a Signature view.

Will revert if the memory view is not over a signature.

function castToSignature(MemView memView) internal pure returns (Signature);

isSignature

Checks that a byte string is a signature

function isSignature(MemView memView) internal pure returns (bool);

unwrap

Convenience shortcut for unwrapping a view.

function unwrap(Signature signature) internal pure returns (MemView);

toRSV

Unpacks signature payload into (r, s, v) parameters.

Make sure to verify signature length with isSignature() beforehand.

function toRSV(Signature signature) internal pure returns (bytes32 r, bytes32 s, uint8 v);

addPrefix

Constructs the calldata with the modified arguments: the existing arguments are prepended with the arguments from the prefix.

*Given:

  • calldata = abi.encodeWithSelector(foo.selector, d, e);
  • prefix = abi.encode(a, b, c);
  • a, b, c are arguments of static type (i.e. not dynamically sized ones) Then:
  • Function will return abi.encodeWithSelector(foo.selector, a, c, c, d, e)
  • Returned calldata will trigger foo(a, b, c, d, e) when used for a contract call. Note: for clarification as to what types are considered static, see https://docs.soliditylang.org/en/latest/abi-spec.html#formal-specification-of-the-encoding*
function addPrefix(CallData callData, bytes memory prefix) internal view returns (bytes memory);

Parameters

NameTypeDescription
callDataCallDataCalldata that needs to be modified
prefixbytesABI-encoded arguments to use as the first arguments in the new calldata

Returns

NameTypeDescription
<none>bytesModified calldata having prefix as the first arguments.

castToCallData

Returns a CallData view over for the given payload.

Will revert if the memory view is not over a calldata.

function castToCallData(bytes memory payload) internal pure returns (CallData);

castToCallData

Casts a memory view to a CallData view.

Will revert if the memory view is not over a calldata.

function castToCallData(MemView memView) internal pure returns (CallData);

isCallData

Checks that a byte string is a valid calldata, i.e. a function selector, followed by arbitrary amount of arguments.

function isCallData(MemView memView) internal pure returns (bool);

unwrap

Convenience shortcut for unwrapping a view.

function unwrap(CallData callData) internal pure returns (MemView);

leaf

Returns callData's hash: a leaf to be inserted in the "Message mini-Merkle tree".

function leaf(CallData callData) internal pure returns (bytes32);

argumentWords

Returns amount of memory words (32 byte chunks) the function arguments occupy in the calldata.

This might differ from amount of arguments supplied, if any of the arguments occupies more than one memory slot. It is true, however, that argument part of the payload occupies exactly N words, even for dynamic types like bytes

function argumentWords(CallData callData) internal pure returns (uint256);

callSelector

Returns selector for the provided calldata.

function callSelector(CallData callData) internal pure returns (bytes4);

arguments

Returns abi encoded arguments for the provided calldata.

function arguments(CallData callData) internal pure returns (MemView);

_fullWords

Checks if length is full amount of memory words (32 bytes).

function _fullWords(uint256 length) internal pure returns (bool);