ERC6900ValidationLib
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
| Name | Type | Description |
|---|---|---|
| userOp | PackedUserOperation | |
| userOpHash | bytes32 | |
| missingAccountFunds | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| validationData | uint256 |
_validateUserOp
function _validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash) private returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| userOp | PackedUserOperation | |
| userOpHash | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
_doUserOpValidation
function _doUserOpValidation(
ModuleEntity vf,
ValidationStorage storage v,
PackedUserOperation calldata userOpCd,
bytes calldata signature,
bytes32 userOpHash
) private returns (uint256 validationRes);Parameters
| Name | Type | Description |
|---|---|---|
| vf | ModuleEntity | |
| v | ValidationStorage | |
| userOpCd | PackedUserOperation | |
| signature | bytes | |
| userOpHash | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| validationRes | uint256 |
_execUserOpValidation
function _execUserOpValidation(
ModuleEntity vf,
ValidationStorage storage v,
PackedUserOperation memory userOp,
bytes32 userOpHash
) private returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| vf | ModuleEntity | |
| v | ValidationStorage | |
| userOp | PackedUserOperation | |
| userOpHash | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| a | uint256 | |
| b | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| res | uint256 |
_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
| Name | Type | Description |
|---|---|---|
| pre | uint256 | |
| mainRes | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| res | uint256 |
_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
| Name | Type | Description |
|---|---|---|
| missingAccountFunds | uint256 |
_moduleEntityOf
function _moduleEntityOf(bytes calldata sig) private pure returns (ModuleEntity me);Parameters
| Name | Type | Description |
|---|---|---|
| sig | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| me | ModuleEntity |
_selectorOf
function _selectorOf(bytes calldata data) private pure returns (bytes4 s);Parameters
| Name | Type | Description |
|---|---|---|
| data | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| s | bytes4 |