AllowanceCalldata

Git Source

Author: Flydexo - @Flydex0

Library in charge of verifying that the calldata is valid corresponding the the allowed calldata conditions.

Functions

isAllowedCalldata

isAllowedCalldata - checks the calldata is valid corresponding the the allowed calldata conditions.

To check the msg.value field, the first arg of data must be equal to msg.value and the first arg of allowed calldata must set rules for the value

function isAllowedCalldata(bytes memory allowed, bytes memory data, uint256 value) internal view returns (bool isOk);

Parameters

NameTypeDescription
allowedbytesThe RLP encoded Allowed calldata
databytesThe RLP encodedx calldata
valueuint256The msg.value

Returns

NameTypeDescription
isOkboolIn case of success returns true, otherwise fails or reverts

RLPtoABI

RLPToABI - Transform the RLP encoded calldata into ABI

the RLP calldata must already be ABI compatible when all arguments are concatenated

If you have n arguments to verify (including value)

You need to have n arguments in the RLP calldata

And when concatenated, the arguments must be ABI compatible

So if you have 1 argument to check (ignore value for the example)

it must be RLP.encode([abi.encode(argument)])

function RLPtoABI(bytes memory data) internal pure returns (bytes memory abiEncoded);

Parameters

NameTypeDescription
databytesthe RLP encoded calldata

Returns

NameTypeDescription
abiEncodedbytesThe result ABI encoded, is valid calldata

_validateArguments

_validateArguments - Core function of the AllowanceCalldata library, checks if arguments respect the allowedArguments conditions

isOr is used to do the minimum checks

in case of AND = a single false result breaks

in case of OR = a single true result breaks

function _validateArguments(
    RLPReader.RLPItem[] memory allowedArguments,
    RLPReader.RLPItem[] memory arguments,
    bool isOr
) internal view returns (bool canPass);

Parameters

NameTypeDescription
allowedArgumentsRLPReader.RLPItem[]The allowed arguments
argumentsRLPReader.RLPItem[]The arguments
isOrboolIs the current loop in a or condition

_unsafe_inc

optimized incrementation

function _unsafe_inc(uint256 i) private pure returns (uint256);

_fillArray

_fillArray - Creates a new array filled with the same item

function _fillArray(RLPReader.RLPItem[] memory arguments, uint256 index, uint256 length)
    internal
    pure
    returns (RLPReader.RLPItem[] memory newArguments);

Parameters

NameTypeDescription
argumentsRLPReader.RLPItem[]Array of arguments to take the item from
indexuint256The index of the item to fill with
lengthuint256The length of the new filled array