@trustvc/eip7702 1.1.0-beta.3 → 1.1.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -41,7 +41,7 @@ Per-platform ERC-4337 paymaster cloned from a shared implementation.
41
41
  | `tdocDeployer` | TDocDeployer contract that mints registry clones |
42
42
  | `authorizedRegistries` | Registries whose calls this paymaster will sponsor |
43
43
  | `authorizedTitleEscrows` | Title escrows whose calls this paymaster will sponsor |
44
- | `authorizedCallers` | Addresses (beneficiary/holder) allowed on Path A |
44
+ | `authorizedCallers` | Owner-managed addresses allowed to call authorized registries |
45
45
  | `userWhitelist` | Deployment credits per user (max 3) |
46
46
  | `documentsMinted` | Count of documents minted per caller |
47
47
  | `dailyLimit` | Max ETH sponsored per user per day |
@@ -50,11 +50,11 @@ Per-platform ERC-4337 paymaster cloned from a shared implementation.
50
50
 
51
51
  - `initialize(owner, dailyLimit, tdocDeployer)` — called once by the factory after clone; guarded by `owner() == address(0)`
52
52
  - `deployRegistry(impl, name, symbol)` — deploys a TradeTrust registry, consumes one credit, auto-authorizes it
53
- - `mintDocument(registry, beneficiary, holder, tokenId, remark)` — mints a document, auto-authorizes beneficiary + holder + title escrow
53
+ - `mintDocument(registry, beneficiary, holder, tokenId, remark)` — mints a document, auto-authorizes the title escrow. Escrow calls are sponsored only for the escrow's current holder/beneficiary (read live at validation), so sponsorship follows the document across transfers
54
54
  - `setUserWhitelist / removeUserFromWhitelist` — manage deployment credits (`onlyOwner`)
55
55
  - `addRegistry / removeRegistry` — manage authorized registries (`onlyOwner`)
56
56
  - `addTitleEscrow / removeTitleEscrow` — manage authorized title escrows (`onlyOwner`)
57
- - `addAuthorizedCaller / removeAuthorizedCaller` — manage Path A callers (`onlyOwner`)
57
+ - `addAuthorizedCaller / removeAuthorizedCaller` — manage extra registry callers; registry role holders (admin/minter/restorer/accepter) are sponsored without this (`onlyOwner`)
58
58
  - `setDailyLimit` — update daily spend cap (`onlyOwner`)
59
59
  - `getUserDailySpend(user)` — returns `(spent, limit, resetsAt)`
60
60
 
@@ -7,6 +7,7 @@ import {SignerEIP7702} from "@openzeppelin/contracts/utils/cryptography/signers/
7
7
  import {EIP7702Utils} from "@openzeppelin/contracts/account/utils/EIP7702Utils.sol";
8
8
  import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
9
9
  import {IEntryPoint} from "@openzeppelin/contracts/interfaces/draft-IERC4337.sol";
10
+ import {IERC7821} from "@openzeppelin/contracts/interfaces/draft-IERC7821.sol";
10
11
 
11
12
  /**
12
13
  * EIP-7702 smart account implementation using OpenZeppelin base contracts.
@@ -76,11 +77,11 @@ contract EIP7702Implementation is Account, SignerEIP7702, ERC7821, ERC165 {
76
77
 
77
78
  /**
78
79
  * @dev Advertise ERC-7821 (batch executor) and ERC-165 support.
79
- * The ERC-7821 interface ID 0x4e49c5c7 is the XOR of:
80
+ * The ERC-7821 interface ID (0x39922547) is derived from the imported interface:
80
81
  * execute(bytes32,bytes).selector ^ supportsExecutionMode(bytes32).selector
81
82
  */
82
83
  function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
83
- return interfaceId == 0x4e49c5c7 // ERC-7821 batch executor
84
+ return interfaceId == type(IERC7821).interfaceId // ERC-7821 batch executor
84
85
  || super.supportsInterface(interfaceId); // covers 0x01ffc9a7 (ERC-165)
85
86
  }
86
87
 
@@ -8,6 +8,7 @@ import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
8
8
  contract PlatformAccountFactory is Ownable {
9
9
  address public tdocDeployer;
10
10
  address public paymasterImplementation;
11
+ mapping(address => address) public attachedPaymaster;
11
12
 
12
13
  event PlatformOnboarded(
13
14
  address indexed platformAddress,
@@ -54,9 +55,17 @@ contract PlatformAccountFactory is Ownable {
54
55
  dailyLimit,
55
56
  tdocDeployer
56
57
  );
58
+ attachedPaymaster[platformAddress] = paymaster;
57
59
  emit PlatformOnboarded(platformAddress, paymaster);
58
60
  }
59
61
 
62
+ // Returns the paymaster currently attached to a platform (address(0) if none).
63
+ function getAttachedPaymaster(
64
+ address platformAddress
65
+ ) external view returns (address) {
66
+ return attachedPaymaster[platformAddress];
67
+ }
68
+
60
69
  // Predict the clone address for a specific deployer and platform.
61
70
  // `deployer` must be the account that will call deployPlatformPaymaster.
62
71
  function computePaymasterAddress(
@@ -23,19 +23,29 @@ interface ITradeTrustToken {
23
23
  interface IAccessControl {
24
24
  function grantRole(bytes32 role, address account) external;
25
25
  function renounceRole(bytes32 role, address callerConfirmation) external;
26
+ function hasRole(bytes32 role, address account) external view returns (bool);
27
+ }
28
+
29
+ interface ITitleEscrow {
30
+ function holder() external view returns (address);
31
+ function beneficiary() external view returns (address);
26
32
  }
27
33
 
28
34
  /**
29
35
  * PlatformPaymaster — validates by inspecting the target contract in callData.
30
36
  *
31
- * Validation strategy (no third-party storage reads → bundler compliant):
37
+ * Validation strategy (paymaster must be staked → bundler compliant):
32
38
  * 1. Decode userOp.callData → must be execute(address to, uint256, bytes)
33
- * 2. Check `to` is in authorizedRegistries (paymaster's own storage)
34
- * 3. Check daily spend (paymaster's own storage — always allowed)
39
+ * 2. Check `to` is in authorizedRegistries / authorizedTitleEscrows (paymaster's own storage)
40
+ * 3. Title escrow: sender is the escrow's *current* holder or beneficiary
41
+ * (read live from the escrow — requires the paymaster to be staked, ERC-7562 STO-033)
42
+ * 4. Registry: sender holds any registry role (admin/minter/restorer/accepter) or is an
43
+ * owner-added authorizedCaller (registry storage associated with sender)
44
+ * 5. mintDocument only: sender holds MINTER_ROLE on the registry
45
+ * 6. Check daily spend (paymaster's own storage)
35
46
  *
36
- * Access control is enforced by the Storage contract itself:
37
- * require(msg.sender == beneficiary || msg.sender == holder)
38
- * so non-beneficiary/holder callers are rejected at execution time.
47
+ * Escrow sponsorship follows the document: after a holder/beneficiary transfer the
48
+ * previous party is no longer sponsored and the new one is, with no owner action.
39
49
  * Reverted ops are still charged to dailySpend in _postOp (gas was paid).
40
50
  */
41
51
  contract PlatformPaymaster is BasePaymaster {
@@ -60,7 +70,7 @@ contract PlatformPaymaster is BasePaymaster {
60
70
  mapping(address => bool) public authorizedTitleEscrows;
61
71
  // remaining deployment credits per user; max 3 per user
62
72
  mapping(address => uint256) public userWhitelist;
63
- // Addresses permitted to call title escrow functions via this paymaster
73
+ // Owner-managed addresses permitted to call authorized registries via this paymaster
64
74
  mapping(address => bool) public authorizedCallers;
65
75
  // Count of documents minted per user
66
76
  mapping(address => uint256) public documentsMinted;
@@ -167,8 +177,10 @@ contract PlatformPaymaster is BasePaymaster {
167
177
  }
168
178
 
169
179
  // Mints a TradeTrust document, captures the TitleEscrow, and auto-authorizes it.
170
- // Paymaster must hold MINTER_ROLE on the registry.
171
- // Callable gaslessly by userWhitelist users (credits not consumed — only deployRegistry uses credits).
180
+ // Paymaster must hold MINTER_ROLE on the registry, and so must the caller
181
+ // (the deployer, or whoever they granted it to).
182
+ // Beneficiary/holder are not granted anything here: escrow sponsorship is checked
183
+ // against the escrow's live holder/beneficiary at validation time.
172
184
  function mintDocument(
173
185
  address registry,
174
186
  address beneficiary,
@@ -177,12 +189,13 @@ contract PlatformPaymaster is BasePaymaster {
177
189
  bytes calldata remark
178
190
  ) external returns (address titleEscrow) {
179
191
  require(authorizedRegistries[registry], "registry not authorized");
192
+ // The registry only sees the paymaster as minter, so check the real caller here
180
193
  require(
181
- authorizedCallers[msg.sender] ||
182
- userWhitelist[msg.sender] > 0 ||
183
- msg.sender == owner(),
184
- "caller not authorized"
194
+ IAccessControl(registry).hasRole(MINTER_ROLE, msg.sender),
195
+ "not registry minter"
185
196
  );
197
+ require(beneficiary != address(0), "invalid beneficiary");
198
+ require(holder != address(0), "invalid holder");
186
199
 
187
200
  titleEscrow = ITradeTrustToken(registry).mint(
188
201
  beneficiary,
@@ -190,10 +203,8 @@ contract PlatformPaymaster is BasePaymaster {
190
203
  tokenId,
191
204
  remark
192
205
  );
193
-
194
- // Auto-authorize beneficiary and holder to call title escrow functions
195
- authorizedCallers[beneficiary] = true;
196
- authorizedCallers[holder] = true;
206
+ // Don't rely on the registry: only authorize a deployed escrow (also rules out address(0))
207
+ require(titleEscrow.code.length > 0, "invalid title escrow");
197
208
 
198
209
  authorizedTitleEscrows[titleEscrow] = true;
199
210
  documentsMinted[msg.sender]++;
@@ -264,21 +275,29 @@ contract PlatformPaymaster is BasePaymaster {
264
275
  (address, uint256, bytes)
265
276
  );
266
277
 
267
- // Path A — calling an authorized registry or title escrow (regular sponsored op)
268
- // Only authorizedCallers or the platform owner may be sponsored here.
269
- if (authorizedRegistries[target] || authorizedTitleEscrows[target]) {
270
- if (!authorizedCallers[sender] && sender != owner()) {
271
- emit UserOpRejected(sender, "caller not authorized");
278
+ // Path A1 — calling an authorized title escrow.
279
+ // Only its current holder/beneficiary (or the platform owner) is sponsored,
280
+ // so a party that has transferred the document away can't keep using it.
281
+ if (authorizedTitleEscrows[target]) {
282
+ if (sender != owner() && !_isEscrowParty(target, sender)) {
283
+ emit UserOpRejected(sender, "not escrow holder/beneficiary");
272
284
  return ("", _packValidationData(true, 0, 0));
273
285
  }
274
- if (dailyLimit > 0 && dailySpend[sender] + maxCost > dailyLimit) {
275
- emit UserOpRejected(sender, "daily limit exceeded");
286
+ return _sponsorWithinDailyLimit(sender, maxCost);
287
+ }
288
+
289
+ // Path A2 — calling an authorized registry.
290
+ // Any registry role holder, owner-added callers, or the platform owner.
291
+ if (authorizedRegistries[target]) {
292
+ if (
293
+ sender != owner() &&
294
+ !authorizedCallers[sender] &&
295
+ !_hasRegistryRole(target, sender)
296
+ ) {
297
+ emit UserOpRejected(sender, "caller not authorized");
276
298
  return ("", _packValidationData(true, 0, 0));
277
299
  }
278
- return (
279
- abi.encode(sender, maxCost, false),
280
- _packValidationData(false, 0, 0)
281
- );
300
+ return _sponsorWithinDailyLimit(sender, maxCost);
282
301
  }
283
302
 
284
303
  // Path B — gasless paymaster call (deployRegistry or mintDocument)
@@ -316,22 +335,34 @@ contract PlatformPaymaster is BasePaymaster {
316
335
  }
317
336
 
318
337
  if (innerSel == MINT_DOCUMENT_SEL) {
319
- if (
320
- !authorizedCallers[sender] &&
321
- userWhitelist[sender] == 0 &&
322
- sender != owner()
323
- ) {
324
- emit UserOpRejected(sender, "caller not authorized");
338
+ // Mirror mintDocument's checks so non-minters can't get failing ops sponsored.
339
+ // hasRole reads _roles[role][sender] — storage associated with sender (ERC-7562).
340
+ // selector + registry + beneficiary + holder
341
+ if (innerData.length < 100) {
342
+ emit UserOpRejected(sender, "mint calldata too short");
325
343
  return ("", _packValidationData(true, 0, 0));
326
344
  }
327
- if (dailyLimit > 0 && dailySpend[sender] + maxCost > dailyLimit) {
328
- emit UserOpRejected(sender, "daily limit exceeded");
345
+ address registry;
346
+ address beneficiary;
347
+ address holder;
348
+ assembly {
349
+ registry := mload(add(innerData, 36))
350
+ beneficiary := mload(add(innerData, 68))
351
+ holder := mload(add(innerData, 100))
352
+ }
353
+ if (beneficiary == address(0) || holder == address(0)) {
354
+ emit UserOpRejected(sender, "invalid beneficiary/holder");
329
355
  return ("", _packValidationData(true, 0, 0));
330
356
  }
331
- return (
332
- abi.encode(sender, maxCost, false),
333
- _packValidationData(false, 0, 0)
334
- );
357
+ if (!authorizedRegistries[registry]) {
358
+ emit UserOpRejected(sender, "registry not authorized");
359
+ return ("", _packValidationData(true, 0, 0));
360
+ }
361
+ if (!IAccessControl(registry).hasRole(MINTER_ROLE, sender)) {
362
+ emit UserOpRejected(sender, "not registry minter");
363
+ return ("", _packValidationData(true, 0, 0));
364
+ }
365
+ return _sponsorWithinDailyLimit(sender, maxCost);
335
366
  }
336
367
 
337
368
  emit UserOpRejected(sender, "unauthorized paymaster call");
@@ -342,6 +373,33 @@ contract PlatformPaymaster is BasePaymaster {
342
373
  return ("", _packValidationData(true, 0, 0));
343
374
  }
344
375
 
376
+ // Approves a daily-limit-tracked op. If the sender is over today's limit, the op
377
+ // is approved with validAfter = window end, so it only runs after the window rolls
378
+ // over and _postOp resets the counter. block.timestamp is banned in validation
379
+ // (ERC-7562), so the EntryPoint enforces the time via validAfter.
380
+ function _sponsorWithinDailyLimit(
381
+ address sender,
382
+ uint256 maxCost
383
+ ) internal returns (bytes memory context, uint256 validationData) {
384
+ context = abi.encode(sender, maxCost, false);
385
+
386
+ if (dailyLimit > 0 && dailySpend[sender] + maxCost > dailyLimit) {
387
+ // Even a fresh window can't fit this op
388
+ if (maxCost > dailyLimit) {
389
+ emit UserOpRejected(sender, "maxCost exceeds daily limit");
390
+ return ("", _packValidationData(true, 0, 0));
391
+ }
392
+ // EntryPoint runs the op only when block.timestamp > validAfter, which is
393
+ // exactly when _postOp's reset condition becomes true
394
+ return (
395
+ context,
396
+ _packValidationData(false, 0, uint48(lastReset[sender] + 1 days))
397
+ );
398
+ }
399
+
400
+ return (context, _packValidationData(false, 0, 0));
401
+ }
402
+
345
403
  function _postOp(
346
404
  PostOpMode mode,
347
405
  bytes calldata context,
@@ -377,6 +435,42 @@ contract PlatformPaymaster is BasePaymaster {
377
435
  emit UserOpSponsored(sender, actualGasCost);
378
436
  }
379
437
 
438
+ // True if `account` is the escrow's current holder or beneficiary.
439
+ // An escrow that doesn't answer (e.g. a bad owner-added address) is treated as no match.
440
+ function _isEscrowParty(
441
+ address escrow,
442
+ address account
443
+ ) private view returns (bool) {
444
+ return
445
+ _readAddress(escrow, ITitleEscrow.holder.selector) == account ||
446
+ _readAddress(escrow, ITitleEscrow.beneficiary.selector) == account;
447
+ }
448
+
449
+ // Low-level so a target without code (or a reverting one) returns address(0)
450
+ // instead of reverting on ABI decode, which try/catch can't intercept.
451
+ function _readAddress(
452
+ address target,
453
+ bytes4 selector
454
+ ) private view returns (address result) {
455
+ (bool ok, bytes memory ret) = target.staticcall(
456
+ abi.encodeWithSelector(selector)
457
+ );
458
+ if (ok && ret.length >= 32) result = abi.decode(ret, (address));
459
+ }
460
+
461
+ // hasRole reads _roles[role][account] — storage associated with the sender (ERC-7562).
462
+ function _hasRegistryRole(
463
+ address registry,
464
+ address account
465
+ ) private view returns (bool) {
466
+ IAccessControl r = IAccessControl(registry);
467
+ return
468
+ r.hasRole(DEFAULT_ADMIN_ROLE, account) ||
469
+ r.hasRole(MINTER_ROLE, account) ||
470
+ r.hasRole(RESTORER_ROLE, account) ||
471
+ r.hasRole(ACCEPTER_ROLE, account);
472
+ }
473
+
380
474
  // Strips the 4-byte selector and ABI-decodes deployRegistry's arguments.
381
475
  function _decodeDeployArgs(bytes memory innerData) private pure {
382
476
  uint256 argsLength = innerData.length - 4;
package/dist/index.d.mts CHANGED
@@ -320,6 +320,20 @@ declare const platformAccountFactoryAbi: readonly [{
320
320
  }];
321
321
  readonly name: "TdocDeployerUpdated";
322
322
  readonly type: "event";
323
+ }, {
324
+ readonly inputs: readonly [{
325
+ readonly internalType: "address";
326
+ readonly name: "";
327
+ readonly type: "address";
328
+ }];
329
+ readonly name: "attachedPaymaster";
330
+ readonly outputs: readonly [{
331
+ readonly internalType: "address";
332
+ readonly name: "";
333
+ readonly type: "address";
334
+ }];
335
+ readonly stateMutability: "view";
336
+ readonly type: "function";
323
337
  }, {
324
338
  readonly inputs: readonly [{
325
339
  readonly internalType: "address";
@@ -364,6 +378,20 @@ declare const platformAccountFactoryAbi: readonly [{
364
378
  }];
365
379
  readonly stateMutability: "nonpayable";
366
380
  readonly type: "function";
381
+ }, {
382
+ readonly inputs: readonly [{
383
+ readonly internalType: "address";
384
+ readonly name: "platformAddress";
385
+ readonly type: "address";
386
+ }];
387
+ readonly name: "getAttachedPaymaster";
388
+ readonly outputs: readonly [{
389
+ readonly internalType: "address";
390
+ readonly name: "";
391
+ readonly type: "address";
392
+ }];
393
+ readonly stateMutability: "view";
394
+ readonly type: "function";
367
395
  }, {
368
396
  readonly inputs: readonly [];
369
397
  readonly name: "owner";
package/dist/index.d.ts CHANGED
@@ -320,6 +320,20 @@ declare const platformAccountFactoryAbi: readonly [{
320
320
  }];
321
321
  readonly name: "TdocDeployerUpdated";
322
322
  readonly type: "event";
323
+ }, {
324
+ readonly inputs: readonly [{
325
+ readonly internalType: "address";
326
+ readonly name: "";
327
+ readonly type: "address";
328
+ }];
329
+ readonly name: "attachedPaymaster";
330
+ readonly outputs: readonly [{
331
+ readonly internalType: "address";
332
+ readonly name: "";
333
+ readonly type: "address";
334
+ }];
335
+ readonly stateMutability: "view";
336
+ readonly type: "function";
323
337
  }, {
324
338
  readonly inputs: readonly [{
325
339
  readonly internalType: "address";
@@ -364,6 +378,20 @@ declare const platformAccountFactoryAbi: readonly [{
364
378
  }];
365
379
  readonly stateMutability: "nonpayable";
366
380
  readonly type: "function";
381
+ }, {
382
+ readonly inputs: readonly [{
383
+ readonly internalType: "address";
384
+ readonly name: "platformAddress";
385
+ readonly type: "address";
386
+ }];
387
+ readonly name: "getAttachedPaymaster";
388
+ readonly outputs: readonly [{
389
+ readonly internalType: "address";
390
+ readonly name: "";
391
+ readonly type: "address";
392
+ }];
393
+ readonly stateMutability: "view";
394
+ readonly type: "function";
367
395
  }, {
368
396
  readonly inputs: readonly [];
369
397
  readonly name: "owner";
package/dist/index.js CHANGED
@@ -438,6 +438,25 @@ var platformAccountFactoryAbi = [
438
438
  "name": "TdocDeployerUpdated",
439
439
  "type": "event"
440
440
  },
441
+ {
442
+ "inputs": [
443
+ {
444
+ "internalType": "address",
445
+ "name": "",
446
+ "type": "address"
447
+ }
448
+ ],
449
+ "name": "attachedPaymaster",
450
+ "outputs": [
451
+ {
452
+ "internalType": "address",
453
+ "name": "",
454
+ "type": "address"
455
+ }
456
+ ],
457
+ "stateMutability": "view",
458
+ "type": "function"
459
+ },
441
460
  {
442
461
  "inputs": [
443
462
  {
@@ -496,6 +515,25 @@ var platformAccountFactoryAbi = [
496
515
  "stateMutability": "nonpayable",
497
516
  "type": "function"
498
517
  },
518
+ {
519
+ "inputs": [
520
+ {
521
+ "internalType": "address",
522
+ "name": "platformAddress",
523
+ "type": "address"
524
+ }
525
+ ],
526
+ "name": "getAttachedPaymaster",
527
+ "outputs": [
528
+ {
529
+ "internalType": "address",
530
+ "name": "",
531
+ "type": "address"
532
+ }
533
+ ],
534
+ "stateMutability": "view",
535
+ "type": "function"
536
+ },
499
537
  {
500
538
  "inputs": [],
501
539
  "name": "owner",
package/dist/index.mjs CHANGED
@@ -436,6 +436,25 @@ var platformAccountFactoryAbi = [
436
436
  "name": "TdocDeployerUpdated",
437
437
  "type": "event"
438
438
  },
439
+ {
440
+ "inputs": [
441
+ {
442
+ "internalType": "address",
443
+ "name": "",
444
+ "type": "address"
445
+ }
446
+ ],
447
+ "name": "attachedPaymaster",
448
+ "outputs": [
449
+ {
450
+ "internalType": "address",
451
+ "name": "",
452
+ "type": "address"
453
+ }
454
+ ],
455
+ "stateMutability": "view",
456
+ "type": "function"
457
+ },
439
458
  {
440
459
  "inputs": [
441
460
  {
@@ -494,6 +513,25 @@ var platformAccountFactoryAbi = [
494
513
  "stateMutability": "nonpayable",
495
514
  "type": "function"
496
515
  },
516
+ {
517
+ "inputs": [
518
+ {
519
+ "internalType": "address",
520
+ "name": "platformAddress",
521
+ "type": "address"
522
+ }
523
+ ],
524
+ "name": "getAttachedPaymaster",
525
+ "outputs": [
526
+ {
527
+ "internalType": "address",
528
+ "name": "",
529
+ "type": "address"
530
+ }
531
+ ],
532
+ "stateMutability": "view",
533
+ "type": "function"
534
+ },
497
535
  {
498
536
  "inputs": [],
499
537
  "name": "owner",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustvc/eip7702",
3
- "version": "1.1.0-beta.3",
3
+ "version": "1.1.0-beta.5",
4
4
  "description": "EIP-7702 smart account, platform paymaster, and factory contracts for TrustVC",
5
5
  "author": "DexTech",
6
6
  "license": "MIT",