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

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
@@ -63,7 +63,7 @@ Per-platform ERC-4337 paymaster cloned from a shared implementation.
63
63
  Deploys `PlatformPaymaster` clones deterministically.
64
64
 
65
65
  - `deployPlatformPaymaster(platformAddress, dailyLimit, salt)` — clones the implementation and calls `initialize`
66
- - `computePaymasterAddress(salt)` — predict the clone address before deployment
66
+ - `computePaymasterAddress(deployer, platformAddress, salt)` — predict the clone address before deployment. The CREATE2 salt is `keccak256(abi.encode(deployer, platformAddress, salt))`, so another caller cannot take the predicted address.
67
67
  - `updateTdocDeployer(addr)` — update TDoc deployer (`onlyOwner`)
68
68
  - `updatePaymasterImplementation(addr)` — upgrade the implementation for future clones (`onlyOwner`)
69
69
 
@@ -8,7 +8,6 @@ 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;
12
11
 
13
12
  event PlatformOnboarded(
14
13
  address indexed platformAddress,
@@ -27,13 +26,6 @@ contract PlatformAccountFactory is Ownable {
27
26
  paymasterImplementation = _paymasterImplementation;
28
27
  }
29
28
 
30
- function setAttachedPaymaster(
31
- address platformAddress
32
- ) external view returns (address) {
33
- address paymaster = attachedPaymaster[platformAddress];
34
- return paymaster;
35
- }
36
-
37
29
  function updateTdocDeployer(address _tdocDeployer) external onlyOwner {
38
30
  require(_tdocDeployer != address(0), "Zero address");
39
31
  tdocDeployer = _tdocDeployer;
@@ -51,7 +43,12 @@ contract PlatformAccountFactory is Ownable {
51
43
  uint256 dailyLimit,
52
44
  bytes32 salt
53
45
  ) external returns (address paymaster) {
54
- paymaster = Clones.cloneDeterministic(paymasterImplementation, salt);
46
+ // Bind the CREATE2 salt to the caller and platform so a third party who
47
+ // only knows `salt` cannot deploy at the address this caller would get.
48
+ paymaster = Clones.cloneDeterministic(
49
+ paymasterImplementation,
50
+ _paymasterSalt(msg.sender, platformAddress, salt)
51
+ );
55
52
  PlatformPaymaster(payable(paymaster)).initialize(
56
53
  platformAddress,
57
54
  dailyLimit,
@@ -60,15 +57,26 @@ contract PlatformAccountFactory is Ownable {
60
57
  emit PlatformOnboarded(platformAddress, paymaster);
61
58
  }
62
59
 
63
- // Address is determined solely by implementation + salt (not by constructor args).
60
+ // Predict the clone address for a specific deployer and platform.
61
+ // `deployer` must be the account that will call deployPlatformPaymaster.
64
62
  function computePaymasterAddress(
63
+ address deployer,
64
+ address platformAddress,
65
65
  bytes32 salt
66
66
  ) external view returns (address) {
67
67
  return
68
68
  Clones.predictDeterministicAddress(
69
69
  paymasterImplementation,
70
- salt,
70
+ _paymasterSalt(deployer, platformAddress, salt),
71
71
  address(this)
72
72
  );
73
73
  }
74
+
75
+ function _paymasterSalt(
76
+ address deployer,
77
+ address platformAddress,
78
+ bytes32 salt
79
+ ) internal pure returns (bytes32) {
80
+ return keccak256(abi.encode(deployer, platformAddress, salt));
81
+ }
74
82
  }
@@ -36,7 +36,7 @@ interface IAccessControl {
36
36
  * Access control is enforced by the Storage contract itself:
37
37
  * require(msg.sender == beneficiary || msg.sender == holder)
38
38
  * so non-beneficiary/holder callers are rejected at execution time.
39
- * If the call reverts, _postOp skips the spend update.
39
+ * Reverted ops are still charged to dailySpend in _postOp (gas was paid).
40
40
  */
41
41
  contract PlatformPaymaster is BasePaymaster {
42
42
  bytes4 private constant EXECUTE_SEL =
@@ -70,6 +70,10 @@ contract PlatformPaymaster is BasePaymaster {
70
70
  mapping(address => uint256) public lastReset;
71
71
  uint256 public dailyLimit;
72
72
 
73
+ // Set once by initialize() (or the constructor for the implementation).
74
+ // Kept separate from owner() so renounceOwnership() cannot re-open initialize().
75
+ bool private _initialized;
76
+
73
77
  event RegistryAdded(address indexed registry);
74
78
  event RegistryRemoved(address indexed registry);
75
79
  event TitleEscrowLinked(
@@ -89,19 +93,22 @@ contract PlatformPaymaster is BasePaymaster {
89
93
  event UserOpRejected(address indexed user, string reason);
90
94
  event DailyLimitUpdated(uint256 newLimit);
91
95
 
92
- // Deployed once as the shared implementation; BasePaymaster sets owner = msg.sender.
93
- // That non-zero owner prevents initialize() from running on the implementation itself.
94
- constructor(IEntryPoint _entryPoint) BasePaymaster(_entryPoint) {}
96
+ // Deployed once as the shared implementation; lock it so initialize() can never run on it.
97
+ constructor(IEntryPoint _entryPoint) BasePaymaster(_entryPoint) {
98
+ _initialized = true;
99
+ }
95
100
 
96
101
  // Called by the factory immediately after cloneDeterministic().
97
- // A fresh clone has all-zero storage, so owner() == address(0) exactly once.
102
+ // Initialization state is tracked separately from ownership, so renounceOwnership()
103
+ // cannot make an initialized clone look fresh and re-open initialize().
98
104
  function initialize(
99
105
  address _owner,
100
106
  uint256 _dailyLimit,
101
107
  address _tdocDeployer
102
108
  ) external {
103
- require(owner() == address(0), "Already initialized");
109
+ require(!_initialized, "Already initialized");
104
110
  require(_owner != address(0), "Zero owner");
111
+ _initialized = true;
105
112
  _transferOwnership(_owner);
106
113
  dailyLimit = _dailyLimit;
107
114
  tdocDeployer = ITDocDeployer(_tdocDeployer);
@@ -170,6 +177,12 @@ contract PlatformPaymaster is BasePaymaster {
170
177
  bytes calldata remark
171
178
  ) external returns (address titleEscrow) {
172
179
  require(authorizedRegistries[registry], "registry not authorized");
180
+ require(
181
+ authorizedCallers[msg.sender] ||
182
+ userWhitelist[msg.sender] > 0 ||
183
+ msg.sender == owner(),
184
+ "caller not authorized"
185
+ );
173
186
 
174
187
  titleEscrow = ITradeTrustToken(registry).mint(
175
188
  beneficiary,
@@ -272,6 +285,10 @@ contract PlatformPaymaster is BasePaymaster {
272
285
  // Double-spend safe: EntryPoint sequential nonces allow only one
273
286
  // pending UserOp per sender in the mempool at a time.
274
287
  if (target == address(this)) {
288
+ if (innerData.length < 4) {
289
+ emit UserOpRejected(sender, "inner callData too short");
290
+ return ("", _packValidationData(true, 0, 0));
291
+ }
275
292
  bytes4 innerSel;
276
293
  assembly {
277
294
  innerSel := mload(add(innerData, 32))
@@ -283,7 +300,15 @@ contract PlatformPaymaster is BasePaymaster {
283
300
  emit UserOpRejected(sender, "not whitelisted");
284
301
  return ("", _packValidationData(true, 0, 0));
285
302
  }
286
- // credits consumed inside deployRegistry; flag as deployment to skip daily spend
303
+ if (address(tdocDeployer) == address(0)) {
304
+ emit UserOpRejected(sender, "TdocDeployer not set");
305
+ return ("", _packValidationData(true, 0, 0));
306
+ }
307
+ // Reverts on malformed ABI args, so only well-formed
308
+ // deployRegistry(address,string,string) payloads are sponsored.
309
+ _decodeDeployArgs(innerData);
310
+ // credits consumed inside deployRegistry; flag as deployment to skip daily spend.
311
+ // _postOp falls back to normal accounting if execution reverts.
287
312
  return (
288
313
  abi.encode(sender, maxCost, true),
289
314
  _packValidationData(false, 0, 0)
@@ -291,7 +316,18 @@ contract PlatformPaymaster is BasePaymaster {
291
316
  }
292
317
 
293
318
  if (innerSel == MINT_DOCUMENT_SEL) {
294
- // mintDocument: registry enforces MINTER_ROLE — no extra whitelist needed
319
+ if (
320
+ !authorizedCallers[sender] &&
321
+ userWhitelist[sender] == 0 &&
322
+ sender != owner()
323
+ ) {
324
+ emit UserOpRejected(sender, "caller not authorized");
325
+ return ("", _packValidationData(true, 0, 0));
326
+ }
327
+ if (dailyLimit > 0 && dailySpend[sender] + maxCost > dailyLimit) {
328
+ emit UserOpRejected(sender, "daily limit exceeded");
329
+ return ("", _packValidationData(true, 0, 0));
330
+ }
295
331
  return (
296
332
  abi.encode(sender, maxCost, false),
297
333
  _packValidationData(false, 0, 0)
@@ -319,18 +355,38 @@ contract PlatformPaymaster is BasePaymaster {
319
355
  (address, uint256, bool)
320
356
  );
321
357
 
322
- // Deployment ops are credit-gated; skip daily spend tracking for them
323
- if (!isDeployment) {
358
+ // Successful deployments are credit-gated; skip daily spend tracking for them.
359
+ // A reverted deployment rolls back the credit decrement inside deployRegistry,
360
+ // so charge it like a normal op and burn the credit here instead — otherwise a
361
+ // sender could replay failing deployments to drain the deposit for free.
362
+ if (!isDeployment || mode != PostOpMode.opSucceeded) {
324
363
  if (block.timestamp > lastReset[sender] + 1 days) {
325
364
  dailySpend[sender] = 0;
326
365
  lastReset[sender] = block.timestamp;
327
366
  }
328
367
  dailySpend[sender] += actualGasCost;
329
368
  }
369
+ if (isDeployment && mode == PostOpMode.opReverted) {
370
+ uint256 credits = userWhitelist[sender];
371
+ if (credits > 0) {
372
+ userWhitelist[sender] = credits - 1;
373
+ emit UserWhitelistUpdated(sender, credits - 1);
374
+ }
375
+ }
330
376
 
331
377
  emit UserOpSponsored(sender, actualGasCost);
332
378
  }
333
379
 
380
+ // Strips the 4-byte selector and ABI-decodes deployRegistry's arguments.
381
+ function _decodeDeployArgs(bytes memory innerData) private pure {
382
+ uint256 argsLength = innerData.length - 4;
383
+ bytes memory args = new bytes(argsLength);
384
+ assembly ("memory-safe") {
385
+ mcopy(add(args, 32), add(innerData, 36), argsLength)
386
+ }
387
+ abi.decode(args, (address, string, string));
388
+ }
389
+
334
390
  // v0.8 contracts on Etherspot EntryPoint — skip interface mismatch check
335
391
  function _validateEntryPointInterface(IEntryPoint) internal pure override {}
336
392
 
package/dist/index.d.mts CHANGED
@@ -323,19 +323,13 @@ declare const platformAccountFactoryAbi: readonly [{
323
323
  }, {
324
324
  readonly inputs: readonly [{
325
325
  readonly internalType: "address";
326
- readonly name: "";
326
+ readonly name: "deployer";
327
327
  readonly type: "address";
328
- }];
329
- readonly name: "attachedPaymaster";
330
- readonly outputs: readonly [{
328
+ }, {
331
329
  readonly internalType: "address";
332
- readonly name: "";
330
+ readonly name: "platformAddress";
333
331
  readonly type: "address";
334
- }];
335
- readonly stateMutability: "view";
336
- readonly type: "function";
337
- }, {
338
- readonly inputs: readonly [{
332
+ }, {
339
333
  readonly internalType: "bytes32";
340
334
  readonly name: "salt";
341
335
  readonly type: "bytes32";
@@ -396,20 +390,6 @@ declare const platformAccountFactoryAbi: readonly [{
396
390
  readonly outputs: readonly [];
397
391
  readonly stateMutability: "nonpayable";
398
392
  readonly type: "function";
399
- }, {
400
- readonly inputs: readonly [{
401
- readonly internalType: "address";
402
- readonly name: "platformAddress";
403
- readonly type: "address";
404
- }];
405
- readonly name: "setAttachedPaymaster";
406
- readonly outputs: readonly [{
407
- readonly internalType: "address";
408
- readonly name: "";
409
- readonly type: "address";
410
- }];
411
- readonly stateMutability: "view";
412
- readonly type: "function";
413
393
  }, {
414
394
  readonly inputs: readonly [];
415
395
  readonly name: "tdocDeployer";
@@ -1167,11 +1147,17 @@ declare namespace index$1 {
1167
1147
 
1168
1148
  declare const ChainId: {
1169
1149
  readonly Sepolia: 11155111;
1150
+ readonly Amoy: 80002;
1170
1151
  };
1171
1152
  /** Deployed contract addresses indexed by chainId */
1172
1153
  declare const contractAddress: {
1154
+ readonly PaymasterImplementation: {
1155
+ readonly 11155111: "0x5ca5652025ca77d13323ed4887b4cbee6098dd8f";
1156
+ readonly 80002: "0xf47d58D3adc642DaD23966698A7A60b8b34D72f8";
1157
+ };
1173
1158
  readonly PlatformAccountFactory: {
1174
- readonly 11155111: "0x5dcDf7fA6Ab8323F67FD66E89b6CeD4564f9F4Ff";
1159
+ readonly 11155111: "0x1fe801f6af6e9a6c76431db08b121a7de70bc895";
1160
+ readonly 80002: "0x2762abf6fa22314ebcab41dd4666836038d29341";
1175
1161
  };
1176
1162
  };
1177
1163
 
package/dist/index.d.ts CHANGED
@@ -323,19 +323,13 @@ declare const platformAccountFactoryAbi: readonly [{
323
323
  }, {
324
324
  readonly inputs: readonly [{
325
325
  readonly internalType: "address";
326
- readonly name: "";
326
+ readonly name: "deployer";
327
327
  readonly type: "address";
328
- }];
329
- readonly name: "attachedPaymaster";
330
- readonly outputs: readonly [{
328
+ }, {
331
329
  readonly internalType: "address";
332
- readonly name: "";
330
+ readonly name: "platformAddress";
333
331
  readonly type: "address";
334
- }];
335
- readonly stateMutability: "view";
336
- readonly type: "function";
337
- }, {
338
- readonly inputs: readonly [{
332
+ }, {
339
333
  readonly internalType: "bytes32";
340
334
  readonly name: "salt";
341
335
  readonly type: "bytes32";
@@ -396,20 +390,6 @@ declare const platformAccountFactoryAbi: readonly [{
396
390
  readonly outputs: readonly [];
397
391
  readonly stateMutability: "nonpayable";
398
392
  readonly type: "function";
399
- }, {
400
- readonly inputs: readonly [{
401
- readonly internalType: "address";
402
- readonly name: "platformAddress";
403
- readonly type: "address";
404
- }];
405
- readonly name: "setAttachedPaymaster";
406
- readonly outputs: readonly [{
407
- readonly internalType: "address";
408
- readonly name: "";
409
- readonly type: "address";
410
- }];
411
- readonly stateMutability: "view";
412
- readonly type: "function";
413
393
  }, {
414
394
  readonly inputs: readonly [];
415
395
  readonly name: "tdocDeployer";
@@ -1167,11 +1147,17 @@ declare namespace index$1 {
1167
1147
 
1168
1148
  declare const ChainId: {
1169
1149
  readonly Sepolia: 11155111;
1150
+ readonly Amoy: 80002;
1170
1151
  };
1171
1152
  /** Deployed contract addresses indexed by chainId */
1172
1153
  declare const contractAddress: {
1154
+ readonly PaymasterImplementation: {
1155
+ readonly 11155111: "0x5ca5652025ca77d13323ed4887b4cbee6098dd8f";
1156
+ readonly 80002: "0xf47d58D3adc642DaD23966698A7A60b8b34D72f8";
1157
+ };
1173
1158
  readonly PlatformAccountFactory: {
1174
- readonly 11155111: "0x5dcDf7fA6Ab8323F67FD66E89b6CeD4564f9F4Ff";
1159
+ readonly 11155111: "0x1fe801f6af6e9a6c76431db08b121a7de70bc895";
1160
+ readonly 80002: "0x2762abf6fa22314ebcab41dd4666836038d29341";
1175
1161
  };
1176
1162
  };
1177
1163
 
package/dist/index.js CHANGED
@@ -442,23 +442,14 @@ var platformAccountFactoryAbi = [
442
442
  "inputs": [
443
443
  {
444
444
  "internalType": "address",
445
- "name": "",
445
+ "name": "deployer",
446
446
  "type": "address"
447
- }
448
- ],
449
- "name": "attachedPaymaster",
450
- "outputs": [
447
+ },
451
448
  {
452
449
  "internalType": "address",
453
- "name": "",
450
+ "name": "platformAddress",
454
451
  "type": "address"
455
- }
456
- ],
457
- "stateMutability": "view",
458
- "type": "function"
459
- },
460
- {
461
- "inputs": [
452
+ },
462
453
  {
463
454
  "internalType": "bytes32",
464
455
  "name": "salt",
@@ -538,25 +529,6 @@ var platformAccountFactoryAbi = [
538
529
  "stateMutability": "nonpayable",
539
530
  "type": "function"
540
531
  },
541
- {
542
- "inputs": [
543
- {
544
- "internalType": "address",
545
- "name": "platformAddress",
546
- "type": "address"
547
- }
548
- ],
549
- "name": "setAttachedPaymaster",
550
- "outputs": [
551
- {
552
- "internalType": "address",
553
- "name": "",
554
- "type": "address"
555
- }
556
- ],
557
- "stateMutability": "view",
558
- "type": "function"
559
- },
560
532
  {
561
533
  "inputs": [],
562
534
  "name": "tdocDeployer",
@@ -1529,11 +1501,17 @@ __export(constants_exports, {
1529
1501
  contractAddress: () => contractAddress
1530
1502
  });
1531
1503
  var ChainId = {
1532
- Sepolia: 11155111
1504
+ Sepolia: 11155111,
1505
+ Amoy: 80002
1533
1506
  };
1534
1507
  var contractAddress = {
1508
+ PaymasterImplementation: {
1509
+ [ChainId.Sepolia]: "0x5ca5652025ca77d13323ed4887b4cbee6098dd8f",
1510
+ [ChainId.Amoy]: "0xf47d58D3adc642DaD23966698A7A60b8b34D72f8"
1511
+ },
1535
1512
  PlatformAccountFactory: {
1536
- [ChainId.Sepolia]: "0x5dcDf7fA6Ab8323F67FD66E89b6CeD4564f9F4Ff"
1513
+ [ChainId.Sepolia]: "0x1fe801f6af6e9a6c76431db08b121a7de70bc895",
1514
+ [ChainId.Amoy]: "0x2762abf6fa22314ebcab41dd4666836038d29341"
1537
1515
  }
1538
1516
  };
1539
1517
 
package/dist/index.mjs CHANGED
@@ -440,23 +440,14 @@ var platformAccountFactoryAbi = [
440
440
  "inputs": [
441
441
  {
442
442
  "internalType": "address",
443
- "name": "",
443
+ "name": "deployer",
444
444
  "type": "address"
445
- }
446
- ],
447
- "name": "attachedPaymaster",
448
- "outputs": [
445
+ },
449
446
  {
450
447
  "internalType": "address",
451
- "name": "",
448
+ "name": "platformAddress",
452
449
  "type": "address"
453
- }
454
- ],
455
- "stateMutability": "view",
456
- "type": "function"
457
- },
458
- {
459
- "inputs": [
450
+ },
460
451
  {
461
452
  "internalType": "bytes32",
462
453
  "name": "salt",
@@ -536,25 +527,6 @@ var platformAccountFactoryAbi = [
536
527
  "stateMutability": "nonpayable",
537
528
  "type": "function"
538
529
  },
539
- {
540
- "inputs": [
541
- {
542
- "internalType": "address",
543
- "name": "platformAddress",
544
- "type": "address"
545
- }
546
- ],
547
- "name": "setAttachedPaymaster",
548
- "outputs": [
549
- {
550
- "internalType": "address",
551
- "name": "",
552
- "type": "address"
553
- }
554
- ],
555
- "stateMutability": "view",
556
- "type": "function"
557
- },
558
530
  {
559
531
  "inputs": [],
560
532
  "name": "tdocDeployer",
@@ -1527,11 +1499,17 @@ __export(constants_exports, {
1527
1499
  contractAddress: () => contractAddress
1528
1500
  });
1529
1501
  var ChainId = {
1530
- Sepolia: 11155111
1502
+ Sepolia: 11155111,
1503
+ Amoy: 80002
1531
1504
  };
1532
1505
  var contractAddress = {
1506
+ PaymasterImplementation: {
1507
+ [ChainId.Sepolia]: "0x5ca5652025ca77d13323ed4887b4cbee6098dd8f",
1508
+ [ChainId.Amoy]: "0xf47d58D3adc642DaD23966698A7A60b8b34D72f8"
1509
+ },
1533
1510
  PlatformAccountFactory: {
1534
- [ChainId.Sepolia]: "0x5dcDf7fA6Ab8323F67FD66E89b6CeD4564f9F4Ff"
1511
+ [ChainId.Sepolia]: "0x1fe801f6af6e9a6c76431db08b121a7de70bc895",
1512
+ [ChainId.Amoy]: "0x2762abf6fa22314ebcab41dd4666836038d29341"
1535
1513
  }
1536
1514
  };
1537
1515
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustvc/eip7702",
3
- "version": "1.1.0-beta.1",
3
+ "version": "1.1.0-beta.3",
4
4
  "description": "EIP-7702 smart account, platform paymaster, and factory contracts for TrustVC",
5
5
  "author": "DexTech",
6
6
  "license": "MIT",