EIP712Coordinator
Git Source (opens in a new tab)
Inherits: EIP712 (opens in a new tab), Coordinator
Coordinator enhanced with ability to created subscriptions via off-chain EIP-712 signature
Allows creating a subscription on behalf of a contract via delegatee EOA signature
Allows nodes to atomically create subscriptions and deliver compute responses
State Variables
EIP712_VERSION
EIP-712 signing domain major version
string public constant EIP712_VERSION = "1";
EIP712_NAME
EIP-712 signing domain name
string public constant EIP712_NAME = "InfernetCoordinator";
DELEGATEE_OVERHEAD_CACHED_WEI
Gas overhead in wei to retrieve cached subscriptionId for existing delegatee-created subscription
A uint16 is sufficient but increases control plane costs. While we can pack this and the subsequent uint24 in contract storage to save data plane costs, we prioritize control plane and instead simply use a uint256
uint256 public constant DELEGATEE_OVERHEAD_CACHED_WEI = 600 wei;
DELEGATEE_OVERHEAD_CREATE_WEI
Gas overhead in wei to create a new subscription via delegatee signature
Make note that this does not account for gas costs of dynamic inputs (containerId, inputs), just base overhead
Can fit within uint24, see comment for DELEGATEE_OVERHEAD_CACHED_WEI
for details
uint256 public constant DELEGATEE_OVERHEAD_CREATE_WEI = 91_200 wei;
EIP712_SUBSCRIPTION_TYPEHASH
EIP-712 struct(Subscription) typeHash
bytes32 private constant EIP712_SUBSCRIPTION_TYPEHASH = keccak256(
"Subscription(address owner,uint32 activeAt,uint32 period,uint32 frequency,uint16 redundancy,uint48 maxGasPrice,uint32 maxGasLimit,string containerId,bytes inputs)"
);
EIP712_DELEGATE_SUBSCRIPTION_TYPEHASH
EIP-712 struct(DelegateSubscription) typeHash
struct(DelegateSubscription) == { uint32 nonce, uint32 expiry, Subscription sub }
The nonce
represents the nonce of the subscribing contract (sub-owner); prevents signature replay
The expiry
is when the delegated subscription signature expires and can no longer be used
bytes32 private constant EIP712_DELEGATE_SUBSCRIPTION_TYPEHASH = keccak256(
"DelegateSubscription(uint32 nonce,uint32 expiry,Subscription sub)Subscription(address owner,uint32 activeAt,uint32 period,uint32 frequency,uint16 redundancy,uint48 maxGasPrice,uint32 maxGasLimit,string containerId,bytes inputs)"
);
maxSubscriberNonce
Subscribing contract => maximum seen nonce
The nonce is a uint32 size(4.2B) which would take > 100 years of incrementing nonce per second to overflow
mapping(address => uint32) public maxSubscriberNonce;
delegateCreatedIds
hash(subscribing contract, nonce) => subscriptionId
Allows lookup between a delegated subscription creation (unique(subscriber, nonce)) and subscriptionId
mapping(bytes32 => uint32) public delegateCreatedIds;
Functions
_domainNameAndVersion
Overrides Solady.EIP712._domainNameAndVersion to return EIP712-compatible domain name, version
function _domainNameAndVersion() internal pure override returns (string memory, string memory);
_domainNameAndVersionMayChange
Overrides Solady.EIP712._domainNameAndVersionMayChange to always return false since the domain params are not updateable
function _domainNameAndVersionMayChange() internal pure override returns (bool);
createSubscriptionDelegatee
Allows a delegatee to create a subscription on behalf of a subscribing contract (sub.owner)
Unlike Coordinator.createSubscription()
, offers maximum flexibility to set subscription parameters
function createSubscriptionDelegatee(
uint32 nonce,
uint32 expiry,
Subscription calldata sub,
uint8 v,
bytes32 r,
bytes32 s
) public returns (uint32, bool);
Parameters
Name | Type | Description |
---|---|---|
nonce | uint32 | subscribing contract nonce (included in signature) |
expiry | uint32 | delegated subscription signature expiry (included in signature) |
sub | Subscription | subscription to create |
v | uint8 | ECDSA recovery id |
r | bytes32 | ECDSA signature output (r) |
s | bytes32 | ECDSA signature output (s) |
Returns
Name | Type | Description |
---|---|---|
<none> | uint32 | subscriptionId (if subscription exists, returns existing ID, else returns new ID) |
<none> | bool | exists (true if returning existing subscription, else false) |
deliverComputeDelegatee
Allows active nodes to (1) atomically create or collect subscription via signed EIP-712 message, (2) deliver container compute responses for created or collected subscription
function deliverComputeDelegatee(
uint32 nonce,
uint32 expiry,
Subscription calldata sub,
uint8 v,
bytes32 r,
bytes32 s,
uint32 deliveryInterval,
bytes calldata input,
bytes calldata output,
bytes calldata proof
) external onlyActiveNode;
Parameters
Name | Type | Description |
---|---|---|
nonce | uint32 | subscribing contract nonce (included in signature) |
expiry | uint32 | delegated subscription signature expiry (included in signature) |
sub | Subscription | subscription to create |
v | uint8 | ECDSA recovery id |
r | bytes32 | ECDSA signature output (r) |
s | bytes32 | ECDSA signature output (s) |
deliveryInterval | uint32 | subscription interval |
input | bytes | optional off-chain input recorded by Infernet node (empty, hashed input, processed input, or both) |
output | bytes | optional off-chain container output (empty, hashed output, processed output, both, or fallback: all encodeable data) |
proof | bytes | optional container execution proof (or arbitrary metadata) |
Errors
SignerMismatch
Thrown by createSubscriptionDelegatee()
if subscription signature does not match contract delegatee
4-byte signature: 0x10c74b03
error SignerMismatch();
SignatureExpired
Thrown by createSubscriptionDelegatee()
if signature for delegated subscription has expired
4-byte signature: 0x0819bdcd
error SignatureExpired();