@agenticprimitives/contracts 1.0.0-alpha.46 → 1.0.0-alpha.48

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.
Files changed (82) hide show
  1. package/AUDIT.md +60 -26
  2. package/deployments-base-sepolia.json +2 -0
  3. package/deployments-faithchain.json +94 -66
  4. package/deployments-hopechain.json +71 -50
  5. package/dist/abi/AgentAccount.json +175 -0
  6. package/dist/abi/AgentAccountFactory.json +47 -0
  7. package/dist/abi/AgentNameAttributeResolver.json +24 -0
  8. package/dist/abi/AgentNameRegistry.json +369 -0
  9. package/dist/abi/AgentNameUniversalResolver.json +34 -0
  10. package/dist/abi/AgentProfileResolver.json +48 -0
  11. package/dist/abi/AgentRegistryBase.json +158 -0
  12. package/dist/abi/AgentRelationship.json +212 -0
  13. package/dist/abi/AgreementRegistry.json +10 -0
  14. package/dist/abi/AttestationRegistry.json +49 -0
  15. package/dist/abi/AttributeStorage.json +24 -0
  16. package/dist/abi/CustodyPolicy.json +184 -0
  17. package/dist/abi/DelegationManager.json +96 -0
  18. package/dist/abi/DigestBindingEnforcer.json +103 -1
  19. package/dist/abi/EstateProjectionRegistry.json +137 -24
  20. package/dist/abi/GeoFeatureRegistry.json +42 -0
  21. package/dist/abi/IAgentAccountFactoryView.json +13 -0
  22. package/dist/abi/IAgentAccountGovernanceTimelockView.json +15 -0
  23. package/dist/abi/ICustodyPolicyFactoryView.json +13 -0
  24. package/dist/abi/ICustodyPolicyPasskeyView.json +50 -0
  25. package/dist/abi/IRedemptionContext.json +15 -0
  26. package/dist/abi/ITreasurySpendPolicyAccountView.json +44 -0
  27. package/dist/abi/IUpgradeVoucherView.json +26 -0
  28. package/dist/abi/OntologyTermRegistry.json +57 -0
  29. package/dist/abi/PaymentEnforcer.json +10 -0
  30. package/dist/abi/PermissionlessSubregistry.json +165 -0
  31. package/dist/abi/PricedSubregistry.json +57 -0
  32. package/dist/abi/RelationshipTypeRegistry.json +57 -0
  33. package/dist/abi/ShapeRegistry.json +57 -0
  34. package/dist/abi/SkillDefinitionRegistry.json +42 -0
  35. package/dist/abi/TreasurySpendPolicy.json +106 -1
  36. package/dist/abi/UpgradeVoucher.json +176 -0
  37. package/dist/abi/index.d.ts +6 -0
  38. package/dist/abi/index.js +6 -0
  39. package/dist/deployments/base-sepolia.d.ts +2 -0
  40. package/dist/deployments/base-sepolia.js +4 -0
  41. package/dist/deployments/faithchain.d.ts +35 -13
  42. package/dist/deployments/faithchain.js +95 -67
  43. package/dist/deployments/hopechain.d.ts +20 -5
  44. package/dist/deployments/hopechain.js +72 -51
  45. package/package.json +1 -1
  46. package/src/AgentAccount.sol +531 -92
  47. package/src/AgentAccountFactory.sol +28 -2
  48. package/src/IAgentAccount.sol +14 -0
  49. package/src/SmartAgentPaymaster.sol +30 -3
  50. package/src/UpgradeVoucher.sol +74 -0
  51. package/src/agency/DelegationManager.sol +177 -52
  52. package/src/agency/ICaveatEnforcer.sol +10 -0
  53. package/src/agency/IDelegationManager.sol +6 -5
  54. package/src/agreement/AgreementRegistry.sol +61 -17
  55. package/src/attestation/AttestationRegistry.sol +115 -22
  56. package/src/custody/CustodyPolicy.sol +393 -47
  57. package/src/custody/TreasurySpendPolicy.sol +192 -29
  58. package/src/enforcers/AllowedMethodsEnforcer.sol +6 -1
  59. package/src/enforcers/AllowedTargetsEnforcer.sol +6 -1
  60. package/src/enforcers/DigestBindingEnforcer.sol +91 -19
  61. package/src/enforcers/PaymentEnforcer.sol +32 -1
  62. package/src/enforcers/QuorumEnforcer.sol +1 -1
  63. package/src/enforcers/ValueEnforcer.sol +6 -1
  64. package/src/geo/GeoFeatureRegistry.sol +25 -1
  65. package/src/governance/AgenticGovernance.sol +16 -0
  66. package/src/identity/AgentProfileResolver.sol +11 -0
  67. package/src/naming/AgentNameAttributeResolver.sol +17 -2
  68. package/src/naming/AgentNamePredicates.sol +1 -1
  69. package/src/naming/AgentNameRegistry.sol +205 -10
  70. package/src/naming/AgentNameUniversalResolver.sol +26 -0
  71. package/src/naming/PermissionlessSubregistry.sol +69 -23
  72. package/src/naming/PricedSubregistry.sol +28 -0
  73. package/src/ontology/AttributeStorage.sol +93 -80
  74. package/src/ontology/OntologyTermRegistry.sol +28 -0
  75. package/src/ontology/ShapeRegistry.sol +28 -0
  76. package/src/payments/PaymentEscrow.sol +23 -15
  77. package/src/payments/PaymentReceiptRegistry.sol +11 -3
  78. package/src/registry/AgentRegistryBase.sol +39 -0
  79. package/src/registry/EstateProjectionRegistry.sol +94 -40
  80. package/src/relationships/AgentRelationship.sol +112 -7
  81. package/src/relationships/RelationshipTypeRegistry.sol +28 -0
  82. package/src/skills/SkillDefinitionRegistry.sol +25 -1
@@ -29,6 +29,11 @@ import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
29
29
  * AR-10 isAssertableCommitment view gateway for AttestationRegistry
30
30
  * AR-11 party SA addresses NEVER appear in register() calldata
31
31
  * AR-12 single on-chain row per agreement (D-37)
32
+ * AR-13 (spec 445 / REG-1) the commitment COMMITS TO ITS ISSUER: `issuerCommitment` must equal
33
+ * keccak256(abi.encodePacked(issuer)), so nobody can register a commitment they merely saw under
34
+ * an issuer (or, through the issuer signature, a schema) of their own. The row key stays the
35
+ * commitment — one row per agreement, read API unchanged.
36
+ * AR-14 (REG-7) nullifiers are scoped to the agreement: an unrelated agreement cannot burn one.
32
37
  */
33
38
  contract AgreementRegistry {
34
39
  // ─── Constants ──────────────────────────────────────────────────────
@@ -72,6 +77,9 @@ contract AgreementRegistry {
72
77
  error NullifierUsed();
73
78
  error CommitmentMismatch();
74
79
  error SignerNotParty();
80
+ /// @notice REG-1 — `issuerCommitment` is not the commitment of `issuer`: the caller is trying to
81
+ /// register an agreement under an issuer the agreement does not name.
82
+ error IssuerNotBound();
75
83
 
76
84
  // ─── Storage ────────────────────────────────────────────────────────
77
85
 
@@ -87,8 +95,10 @@ contract AgreementRegistry {
87
95
  /// @dev key = agreementCommitment hash
88
96
  mapping(bytes32 => AgreementRow) private _rows;
89
97
 
90
- /// @dev AR-08: nullifier set for replay protection on status transitions.
91
- mapping(bytes32 => bool) private _nullifiers;
98
+ /// @dev AR-08 / AR-14 (REG-7): nullifier set for replay protection on status transitions, PER
99
+ /// AGREEMENT — agreementCommitment => nullifier => used. A global set let anyone with an
100
+ /// agreement of their own burn the nullifier of a pending transition they saw.
101
+ mapping(bytes32 => mapping(bytes32 => bool)) private _nullifiers;
92
102
 
93
103
  // ─── Requests ───────────────────────────────────────────────────────
94
104
 
@@ -161,6 +171,14 @@ contract AgreementRegistry {
161
171
  );
162
172
  if (recomputed != p.agreementCommitment) revert CommitmentMismatch();
163
173
 
174
+ // AR-13 / REG-1 — the commitment names its issuer. `issuerCommitment` is one of the hashed
175
+ // components above, so requiring it to be the commitment of `p.issuer` makes the row's issuer a
176
+ // function of the commitment itself: a party who only SAW the commitment (mempool, an insider)
177
+ // cannot register it under its own issuer — and the issuer signature below binds the schema, so
178
+ // not under its own schema either. `issuer` is already public in this calldata, so nothing new
179
+ // is revealed (the SDK has always derived issuerCommitment this way).
180
+ if (p.issuerCommitment != keccak256(abi.encodePacked(p.issuer))) revert IssuerNotBound();
181
+
164
182
  if (_rows[p.agreementCommitment].agreementCommitment != bytes32(0)) {
165
183
  revert AlreadyRegistered();
166
184
  }
@@ -222,13 +240,15 @@ contract AgreementRegistry {
222
240
  ) {
223
241
  revert InvalidStatus();
224
242
  }
243
+ // REG-7: DISPUTED → DISPUTED is not a transition (it only emitted an event and spent a nullifier).
244
+ if (p.toStatus == row.status) revert InvalidStatus();
225
245
  // DISPUTED → COMPLETED / REVOKED needs bilateral.
226
246
  // ACTIVE → DISPUTED: either-party allowed.
227
247
  // ACTIVE → COMPLETED / REVOKED: bilateral.
228
248
 
229
249
  // AR-08 — replay protection
230
- if (_nullifiers[p.nullifier]) revert NullifierUsed();
231
- _nullifiers[p.nullifier] = true;
250
+ if (_nullifiers[p.agreementCommitment][p.nullifier]) revert NullifierUsed();
251
+ _nullifiers[p.agreementCommitment][p.nullifier] = true;
232
252
 
233
253
  // RW1-2 (ADR-0027): PROVE the signers are the agreement's parties. Recompute the agreement
234
254
  // commitment from the REVEALED parties + components (register's exact formula) and require it
@@ -291,6 +311,8 @@ contract AgreementRegistry {
291
311
  address /* actor */
292
312
  ) external view returns (bool ok, string memory reason) {
293
313
  AgreementRow memory row = _rows[agreementCommitment];
314
+ // Zero-default existence check (a registered row always stores its non-zero commitment) — benign.
315
+ // slither-disable-next-line incorrect-equality
294
316
  if (row.agreementCommitment == bytes32(0)) return (false, "not-registered");
295
317
  return (true, "");
296
318
  }
@@ -298,34 +320,56 @@ contract AgreementRegistry {
298
320
  /// @notice Get the on-chain row.
299
321
  function getRecord(bytes32 agreementCommitment) external view returns (AgreementRow memory) {
300
322
  AgreementRow memory row = _rows[agreementCommitment];
323
+ // Zero-default existence check — benign.
324
+ // slither-disable-next-line incorrect-equality
301
325
  if (row.agreementCommitment == bytes32(0)) revert NotRegistered();
302
326
  return row;
303
327
  }
304
328
 
305
- /// @notice Has a nullifier been consumed?
306
- function isNullifierUsed(bytes32 n) external view returns (bool) {
307
- return _nullifiers[n];
329
+ /// @notice Has a nullifier been consumed for this agreement? (REG-7: nullifiers are per agreement.)
330
+ function isNullifierUsed(bytes32 agreementCommitment, bytes32 n) external view returns (bool) {
331
+ return _nullifiers[agreementCommitment][n];
308
332
  }
309
333
 
310
334
  // ─── Internal ───────────────────────────────────────────────────────
311
335
 
336
+ /// @dev ERC-1271 for contract signers, low-s ECDSA for EOAs. REG-16: an EIP-7702-delegated EOA has
337
+ /// 23 bytes of code (`0xef0100 ‖ delegate`) and is still controlled by its key, so for THAT shape
338
+ /// only, a failed ERC-1271 check is followed by ECDSA — both are the account's own authority.
339
+ /// Any other contract signer is ERC-1271 only (ADR-0013: no weaker second path).
312
340
  function _isValidSignatureBool(
313
341
  address signer,
314
342
  bytes32 digest,
315
343
  bytes memory signature
316
344
  ) internal view returns (bool) {
317
- if (signer.code.length > 0) {
318
- try IERC1271(signer).isValidSignature(digest, signature) returns (bytes4 result) {
319
- return result == IERC1271.isValidSignature.selector;
320
- } catch {
321
- return false;
322
- }
345
+ uint256 codeLen = signer.code.length;
346
+ if (codeLen > 0) {
347
+ if (_erc1271Ok(signer, digest, signature)) return true;
348
+ if (!_isDelegatedEoa(signer, codeLen)) return false;
323
349
  }
324
- // P2-2 (audit 2026-06-10): route EOA recovery through OpenZeppelin ECDSA.tryRecover instead of
325
- // raw ecrecover — it rejects high-s (malleable) signatures and malformed lengths, matching the
326
- // DelegationManager idiom so every signature-verifying contract shares one low-s-safe path.
350
+ // P2-2 (audit 2026-06-10): OpenZeppelin ECDSA.tryRecover rejects high-s (malleable) signatures and
351
+ // malformed lengths. The error value is checked explicitly: on any error `recovered` is zero and
352
+ // is NOT compared (a zero `signer` can therefore never match).
327
353
  bytes32 ethHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", digest));
354
+ // The third return value is the error ARGUMENT (the offending length / s); the error KIND is checked.
355
+ // slither-disable-next-line unused-return
328
356
  (address recovered, ECDSA.RecoverError err, ) = ECDSA.tryRecover(ethHash, signature);
329
- return err == ECDSA.RecoverError.NoError && recovered == signer;
357
+ if (err != ECDSA.RecoverError.NoError) return false;
358
+ return recovered != address(0) && recovered == signer;
359
+ }
360
+
361
+ /// @dev ERC-1271 by raw staticcall: a signer that reverts, returns nothing, or returns fewer than 32
362
+ /// bytes is "not valid" — it cannot make this registry's call revert while decoding its answer.
363
+ function _erc1271Ok(address signer, bytes32 digest, bytes memory signature) private view returns (bool) {
364
+ (bool ok, bytes memory ret) =
365
+ signer.staticcall(abi.encodeWithSelector(IERC1271.isValidSignature.selector, digest, signature));
366
+ if (!ok || ret.length < 32) return false;
367
+ return bytes32(ret) == bytes32(IERC1271.isValidSignature.selector);
368
+ }
369
+
370
+ function _isDelegatedEoa(address a, uint256 codeLen) private view returns (bool) {
371
+ if (codeLen != 23) return false;
372
+ bytes memory c = a.code;
373
+ return c[0] == 0xef && c[1] == 0x01 && c[2] == 0x00;
330
374
  }
331
375
  }
@@ -36,6 +36,14 @@ import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
36
36
  * AR-07 epoch-bucket timestamps; raw block.timestamp never stored
37
37
  * AR-08 four indexed event topics (EAS-like)
38
38
  * AR-09 immutable + non-upgradeable; no admin
39
+ * AR-10 (spec 445 / REG-3, ledger ATT-2) revocation follows the attestation's CONTENT, not its salt:
40
+ * the content id is the UID without the salt, plus the schema — (subject, party2, issuer, schemaId,
41
+ * credentialType, credentialHash, refUID). Revoking any row revokes that content: it cannot be
42
+ * re-anchored under a new salt, and every sibling row already anchored reads as revoked. An issuer
43
+ * who wants to attest again issues a NEW credential (a different credentialHash).
44
+ * AR-11 (REG-8) the status-list pointer is inside the issuer digest (whoever anchors cannot choose it),
45
+ * and a unilateral attestation is anchored by its SUBJECT (it is the holder's public statement of
46
+ * a subject↔issuer link — nobody else may publish it).
39
47
  *
40
48
  * Spec 242 §9 + ADR-0023.
41
49
  */
@@ -55,6 +63,9 @@ contract AttestationRegistry {
55
63
  error InvalidParties();
56
64
  error InvalidPartyConsent();
57
65
  error EmptyCredentialHash();
66
+ /// @notice REG-3 — this content (subject/parties + issuer + schema + type + credential hash + ref)
67
+ /// was revoked; a new salt does not make it a new attestation.
68
+ error ContentRevoked(bytes32 contentId);
58
69
 
59
70
  /// @dev RW1-1 (ADR-0027) — the canonical consent payload each party signs to consent to a
60
71
  /// joint agreement. The contract RECOMPUTES this digest from calldata; a stored/supplied
@@ -72,7 +83,7 @@ contract AttestationRegistry {
72
83
  /// spoofed issuer-backed joint attestation with different parties/schema. The issuer now signs a
73
84
  /// digest binding parties + schema + credential type + commitment + chain + this contract.
74
85
  bytes32 internal constant JOINT_ISSUER_TYPEHASH = keccak256(
75
- "JointAgreementIssuerAttestation(address party1,address party2,address issuer,bytes32 schemaId,bytes32 credentialType,bytes32 credentialHash,bytes32 agreementCommitment,uint256 chainId,address verifyingContract)"
86
+ "JointAgreementIssuerAttestation(address party1,address party2,address issuer,bytes32 schemaId,bytes32 credentialType,bytes32 credentialHash,bytes32 agreementCommitment,bytes32 offchainCredentialStatusList,uint256 chainId,address verifyingContract)"
76
87
  );
77
88
 
78
89
  /// @dev SC-2 (audit 2026-06-09): the issuer attestation digest binds the SUBJECT (and schema /
@@ -80,7 +91,7 @@ contract AttestationRegistry {
80
91
  /// signed only the credentialHash, so anyone who learned that public hash could anchor it on
81
92
  /// chain against a DIFFERENT subject. Recomputed on-chain; the TS side derives the same constant.
82
93
  bytes32 internal constant ASSOCIATION_ATTESTATION_TYPEHASH = keccak256(
83
- "AssociationAttestation(address subject,address issuer,bytes32 schemaId,bytes32 credentialType,bytes32 credentialHash,uint256 chainId,address verifyingContract)"
94
+ "AssociationAttestation(address subject,address issuer,bytes32 schemaId,bytes32 credentialType,bytes32 credentialHash,bytes32 offchainCredentialStatusList,uint256 chainId,address verifyingContract)"
84
95
  );
85
96
 
86
97
  // ─── Storage ────────────────────────────────────────────────────────
@@ -103,6 +114,9 @@ contract AttestationRegistry {
103
114
 
104
115
  mapping(bytes32 => Attestation) private _attestations;
105
116
 
117
+ /// @dev AR-10 / REG-3: contentId => the epoch bucket its content was revoked in (0 = live).
118
+ mapping(bytes32 => uint64) private _contentRevokedAt;
119
+
106
120
  // ─── Requests ───────────────────────────────────────────────────────
107
121
 
108
122
  struct AssociationAttestationRequest {
@@ -168,6 +182,9 @@ contract AttestationRegistry {
168
182
  /// @notice Unilateral attestation by a holder against an issued credential.
169
183
  function assertAssociation(AssociationAttestationRequest calldata req) external returns (bytes32) {
170
184
  if (req.credentialHash == bytes32(0)) revert EmptyCredentialHash();
185
+ // AR-11 / REG-8: the holder anchors its own association. Anyone holding the issuer's signature
186
+ // could previously publish the subject↔issuer link (and pick the status-list pointer).
187
+ if (msg.sender != req.subject) revert NotSubject();
171
188
 
172
189
  // SC-2: RECOMPUTE the issuer-attestation digest binding the SUBJECT (+ schema / type / chain /
173
190
  // this contract) and verify the issuer signed THAT. A known credentialHash can no longer be
@@ -180,6 +197,7 @@ contract AttestationRegistry {
180
197
  req.schemaId,
181
198
  req.credentialType,
182
199
  req.credentialHash,
200
+ req.offchainCredentialStatusList, // REG-8: the issuer's revocation channel is the issuer's to name
183
201
  block.chainid,
184
202
  address(this)
185
203
  )
@@ -188,6 +206,12 @@ contract AttestationRegistry {
188
206
  revert InvalidIssuerSignature();
189
207
  }
190
208
 
209
+ // AR-10 / REG-3: revoked content stays revoked under any salt.
210
+ {
211
+ bytes32 cid = _contentId(req.subject, address(0), req.issuer, req.schemaId, req.credentialType, req.credentialHash, bytes32(0));
212
+ if (_contentRevokedAt[cid] != 0) revert ContentRevoked(cid);
213
+ }
214
+
191
215
  bytes32 uid = _computeUid(
192
216
  req.subject,
193
217
  address(0),
@@ -251,6 +275,7 @@ contract AttestationRegistry {
251
275
  req.credentialType,
252
276
  req.credentialHash,
253
277
  req.refUID,
278
+ req.offchainCredentialStatusList, // REG-8
254
279
  block.chainid,
255
280
  address(this)
256
281
  )
@@ -275,6 +300,13 @@ contract AttestationRegistry {
275
300
  if (!_isValidSignatureBool(req.party1, consentDigest, req.party1Signature)) revert InvalidPartyConsent();
276
301
  if (!_isValidSignatureBool(req.party2, consentDigest, req.party2Signature)) revert InvalidPartyConsent();
277
302
 
303
+ // AR-10 / REG-3: "either party may revoke" is durable — the consent signatures are public
304
+ // calldata, and without this anyone could re-anchor the revoked agreement under a new salt.
305
+ {
306
+ bytes32 cid = _contentId(req.party1, req.party2, req.issuer, req.schemaId, req.credentialType, req.credentialHash, req.refUID);
307
+ if (_contentRevokedAt[cid] != 0) revert ContentRevoked(cid);
308
+ }
309
+
278
310
  bytes32 uid = _computeUid(
279
311
  req.party1,
280
312
  req.party2,
@@ -313,9 +345,7 @@ contract AttestationRegistry {
313
345
  if (a.uid == bytes32(0)) revert AttestationNotFound();
314
346
  if (a.party2 != address(0)) revert NotSubject(); // joint — wrong entrypoint
315
347
  if (msg.sender != a.subject) revert NotSubject();
316
- if (a.revocationEpochBucket != 0) revert AlreadyRevoked();
317
-
318
- a.revocationEpochBucket = uint64(block.timestamp) / EPOCH_SECONDS;
348
+ _revoke(a);
319
349
  emit Revoked(msg.sender, a.credentialType, uid, reasonHash);
320
350
  }
321
351
 
@@ -325,9 +355,7 @@ contract AttestationRegistry {
325
355
  if (a.uid == bytes32(0)) revert AttestationNotFound();
326
356
  if (a.party2 == address(0)) revert NotParty(); // unilateral — wrong entrypoint
327
357
  if (msg.sender != a.subject && msg.sender != a.party2) revert NotParty();
328
- if (a.revocationEpochBucket != 0) revert AlreadyRevoked();
329
-
330
- a.revocationEpochBucket = uint64(block.timestamp) / EPOCH_SECONDS;
358
+ _revoke(a);
331
359
  emit Revoked(msg.sender, a.credentialType, uid, reasonHash);
332
360
  }
333
361
 
@@ -335,16 +363,63 @@ contract AttestationRegistry {
335
363
  function getAttestation(bytes32 uid) external view returns (Attestation memory) {
336
364
  Attestation memory a = _attestations[uid];
337
365
  if (a.uid == bytes32(0)) revert AttestationNotFound();
366
+ // AR-10: a sibling row (same content, another salt) reads as revoked from the moment the content was.
367
+ if (a.revocationEpochBucket == 0) {
368
+ a.revocationEpochBucket = _contentRevokedAt[
369
+ _contentId(a.subject, a.party2, a.issuer, a.schemaId, a.credentialType, a.credentialHash, a.refUID)
370
+ ];
371
+ }
338
372
  return a;
339
373
  }
340
374
 
341
- /// @notice Convenience — `!revoked` view.
375
+ /// @notice Convenience — `!revoked` view. False when the row OR its content was revoked (AR-10).
342
376
  function isValid(bytes32 uid) external view returns (bool) {
343
- return _attestations[uid].uid != bytes32(0) && _attestations[uid].revocationEpochBucket == 0;
377
+ Attestation storage a = _attestations[uid];
378
+ if (a.uid == bytes32(0) || a.revocationEpochBucket != 0) return false;
379
+ return _contentRevokedAt[_contentIdOf(a)] == 0;
380
+ }
381
+
382
+ /// @notice The salt-independent content id of an anchored attestation (AR-10).
383
+ function contentIdOf(bytes32 uid) external view returns (bytes32) {
384
+ Attestation storage a = _attestations[uid];
385
+ if (a.uid == bytes32(0)) revert AttestationNotFound();
386
+ return _contentIdOf(a);
387
+ }
388
+
389
+ /// @notice Was this content revoked? `contentId` = keccak256(abi.encode(subject, party2, issuer,
390
+ /// schemaId, credentialType, credentialHash, refUID)) — computable without an anchored row.
391
+ function isContentRevoked(bytes32 contentId) external view returns (bool) {
392
+ return _contentRevokedAt[contentId] != 0;
344
393
  }
345
394
 
346
395
  // ─── Internal ───────────────────────────────────────────────────────
347
396
 
397
+ function _revoke(Attestation storage a) internal {
398
+ bytes32 cid = _contentIdOf(a);
399
+ if (a.revocationEpochBucket != 0 || _contentRevokedAt[cid] != 0) revert AlreadyRevoked();
400
+ uint64 bucket = uint64(block.timestamp) / EPOCH_SECONDS;
401
+ // A revocation in epoch bucket 0 is impossible off a fresh dev chain; keep the sentinel honest.
402
+ if (bucket == 0) bucket = 1;
403
+ a.revocationEpochBucket = bucket;
404
+ _contentRevokedAt[cid] = bucket;
405
+ }
406
+
407
+ function _contentIdOf(Attestation storage a) internal view returns (bytes32) {
408
+ return _contentId(a.subject, a.party2, a.issuer, a.schemaId, a.credentialType, a.credentialHash, a.refUID);
409
+ }
410
+
411
+ function _contentId(
412
+ address subject,
413
+ address party2,
414
+ address issuer,
415
+ bytes32 schemaId,
416
+ bytes32 credentialType,
417
+ bytes32 credentialHash,
418
+ bytes32 refUID
419
+ ) internal pure returns (bytes32) {
420
+ return keccak256(abi.encode(subject, party2, issuer, schemaId, credentialType, credentialHash, refUID));
421
+ }
422
+
348
423
  function _computeUid(
349
424
  address subject,
350
425
  address party2,
@@ -360,25 +435,43 @@ contract AttestationRegistry {
360
435
  );
361
436
  }
362
437
 
363
- /// @dev ERC-1271-first signature verification (smart accounts), with EOA fallback.
438
+ /// @dev ERC-1271 for contract signers, low-s ECDSA for EOAs. REG-16: an EIP-7702-delegated EOA has
439
+ /// 23 bytes of code (`0xef0100 ‖ delegate`) and is still controlled by its key, so for THAT shape
440
+ /// only, a failed ERC-1271 check is followed by ECDSA — both are the account's own authority.
441
+ /// Any other contract signer is ERC-1271 only (ADR-0013: no weaker second path).
364
442
  function _isValidSignatureBool(
365
443
  address signer,
366
444
  bytes32 digest,
367
445
  bytes memory signature
368
446
  ) internal view returns (bool) {
369
- if (signer.code.length > 0) {
370
- try IERC1271(signer).isValidSignature(digest, signature) returns (bytes4 result) {
371
- return result == IERC1271.isValidSignature.selector;
372
- } catch {
373
- return false;
374
- }
447
+ uint256 codeLen = signer.code.length;
448
+ if (codeLen > 0) {
449
+ if (_erc1271Ok(signer, digest, signature)) return true;
450
+ if (!_isDelegatedEoa(signer, codeLen)) return false;
375
451
  }
376
- // EOA fallback via eth-signed message hash + malleability-safe ECDSA.
377
- // P2-2 (audit 2026-06-10): route EOA recovery through OpenZeppelin ECDSA.tryRecover instead of
378
- // raw ecrecover — it rejects high-s (malleable) signatures and malformed lengths, matching the
379
- // DelegationManager idiom so every signature-verifying contract shares one low-s-safe path.
452
+ // P2-2 (audit 2026-06-10): OpenZeppelin ECDSA.tryRecover rejects high-s (malleable) signatures and
453
+ // malformed lengths. The error value is checked explicitly: on any error `recovered` is zero and
454
+ // is NOT compared (a zero `signer` can therefore never match).
380
455
  bytes32 ethHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", digest));
456
+ // The third return value is the error ARGUMENT (the offending length / s); the error KIND is checked.
457
+ // slither-disable-next-line unused-return
381
458
  (address recovered, ECDSA.RecoverError err, ) = ECDSA.tryRecover(ethHash, signature);
382
- return err == ECDSA.RecoverError.NoError && recovered == signer;
459
+ if (err != ECDSA.RecoverError.NoError) return false;
460
+ return recovered != address(0) && recovered == signer;
461
+ }
462
+
463
+ /// @dev ERC-1271 by raw staticcall: a signer that reverts, returns nothing, or returns fewer than 32
464
+ /// bytes is "not valid" — it cannot make this registry's call revert while decoding its answer.
465
+ function _erc1271Ok(address signer, bytes32 digest, bytes memory signature) private view returns (bool) {
466
+ (bool ok, bytes memory ret) =
467
+ signer.staticcall(abi.encodeWithSelector(IERC1271.isValidSignature.selector, digest, signature));
468
+ if (!ok || ret.length < 32) return false;
469
+ return bytes32(ret) == bytes32(IERC1271.isValidSignature.selector);
470
+ }
471
+
472
+ function _isDelegatedEoa(address a, uint256 codeLen) private view returns (bool) {
473
+ if (codeLen != 23) return false;
474
+ bytes memory c = a.code;
475
+ return c[0] == 0xef && c[1] == 0x01 && c[2] == 0x00;
383
476
  }
384
477
  }