Skip to content
Lattice

ERC6900ValidationLib

Git Source

Title: ERC6900ValidationLib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from ERC-6900 reference implementation (https://github.com/erc6900/reference-implementation)

The ERC-6900 ERC-4337 userOp validation path: decodes the validation ModuleEntity from the userOp signature prefix, checks applicability (reusing the executor's gate), runs pre-userOp-validation hooks (sparse-segmented), gates on the isUserOpValidation flag, calls the validation module's validateUserOp, coalesces the results, and pays the EntryPoint prefund.

Re-implemented FRESH from the ERC-6900 reference (erc6900/reference-implementation @ 65892c2). The validating ModuleEntity + global flag come from userOp.signature[0:24] / [24] (NOT the nonce — the reference never reads it); [25:] is the sparse-segment blob distributing per-hook signatures. The EntryPoint is the one shared with the ERC-4337 facet (ERC4337ValidationLib — the executor's bypass reads the same slot). Validation-associated EXECUTION hooks (which need the executeUserOp wrapper at execution time) are not yet supported and are rejected (RequireUserOperationContext) rather than silently skipped.

Functions

validateUserOp

ERC-4337 account validation for the ERC-6900 account. Only the configured EntryPoint may call.

function validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash, uint256 missingAccountFunds)
        internal
        returns (uint256 validationData);

Parameters

NameTypeDescription
userOpPackedUserOperation
userOpHashbytes32
missingAccountFundsuint256

Returns

NameTypeDescription
validationDatauint256

_validateUserOp

function _validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash) private returns (uint256);

Parameters

NameTypeDescription
userOpPackedUserOperation
userOpHashbytes32

Returns

NameTypeDescription
<none>uint256

_doUserOpValidation

function _doUserOpValidation(
        ModuleEntity vf,
        ValidationStorage storage v,
        PackedUserOperation calldata userOpCd,
        bytes calldata signature,
        bytes32 userOpHash
    ) private returns (uint256 validationRes);

Parameters

NameTypeDescription
vfModuleEntity
vValidationStorage
userOpCdPackedUserOperation
signaturebytes
userOpHashbytes32

Returns

NameTypeDescription
validationResuint256

_execUserOpValidation

function _execUserOpValidation(
        ModuleEntity vf,
        ValidationStorage storage v,
        PackedUserOperation memory userOp,
        bytes32 userOpHash
    ) private returns (uint256);

Parameters

NameTypeDescription
vfModuleEntity
vValidationStorage
userOpPackedUserOperation
userOpHashbytes32

Returns

NameTypeDescription
<none>uint256

_coalescePreValidation

Intersect two pre-validation results: validUntil = MIN (0 ⇒ no-expiry sentinel), validAfter = MAX, authorizer = OR (safe: each is 0 or 1, enforced by the UnexpectedAggregator guard).

function _coalescePreValidation(uint256 a, uint256 b) private pure returns (uint256 res);

Parameters

NameTypeDescription
auint256
buint256

Returns

NameTypeDescription
resuint256

_coalesceValidation

Combine the coalesced hook result with the validation-function result. Time ranges intersect as in _coalescePreValidation; authorizer is asymmetric — a failing hook (authorizer 1) vetoes, otherwise the validation function's authorizer (which MAY be a real aggregator) passes through.

function _coalesceValidation(uint256 pre, uint256 mainRes) private pure returns (uint256 res);

Parameters

NameTypeDescription
preuint256
mainResuint256

Returns

NameTypeDescription
resuint256

_payPrefund

Pays the EntryPoint (msg.sender) its prefund; result ignored (the EntryPoint validates its own balance change, and reverting here would block validation).

function _payPrefund(uint256 missingAccountFunds) private;

Parameters

NameTypeDescription
missingAccountFundsuint256

_moduleEntityOf

function _moduleEntityOf(bytes calldata sig) private pure returns (ModuleEntity me);

Parameters

NameTypeDescription
sigbytes

Returns

NameTypeDescription
meModuleEntity

_selectorOf

function _selectorOf(bytes calldata data) private pure returns (bytes4 s);

Parameters

NameTypeDescription
databytes

Returns

NameTypeDescription
sbytes4