@agenticprimitives/contracts 1.0.0-alpha.5 → 1.0.0-alpha.50

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 (145) hide show
  1. package/AUDIT.md +119 -27
  2. package/README.md +47 -12
  3. package/deployments-base-sepolia.json +52 -1
  4. package/deployments-faithchain.json +103 -0
  5. package/deployments-hopechain.json +78 -0
  6. package/deployments-paymaster-anvil.json +1 -0
  7. package/deployments-registries-base-sepolia.json +1 -0
  8. package/deployments-registries-hopechain.json +1 -0
  9. package/dist/abi/AccountBootstrap.json +99 -0
  10. package/dist/abi/AgentAccount.json +461 -67
  11. package/dist/abi/AgentAccountFactory.json +309 -0
  12. package/dist/abi/AgentNameAttributeResolver.json +212 -0
  13. package/dist/abi/AgentNameRegistry.json +544 -0
  14. package/dist/abi/AgentNameUniversalResolver.json +222 -0
  15. package/dist/abi/AgentProfileResolver.json +236 -0
  16. package/dist/abi/AgentRegistryBase.json +1003 -0
  17. package/dist/abi/AgentRelationship.json +405 -0
  18. package/dist/abi/AgenticGovernance.json +155 -0
  19. package/dist/abi/AgreementRegistry.json +203 -5
  20. package/dist/abi/AllowedMethodsEnforcer.json +193 -0
  21. package/dist/abi/AllowedTargetsEnforcer.json +193 -0
  22. package/dist/abi/ApprovedHashRegistry.json +267 -2
  23. package/dist/abi/AttestationRegistry.json +242 -0
  24. package/dist/abi/AttributeStorage.json +24 -0
  25. package/dist/abi/CallDataHashEnforcer.json +193 -0
  26. package/dist/abi/CustodyPolicy.json +422 -55
  27. package/dist/abi/DelegationManager.json +292 -0
  28. package/dist/abi/DigestBindingEnforcer.json +541 -0
  29. package/dist/abi/Eip7702.json +13 -0
  30. package/dist/abi/EstateProjectionRegistry.json +599 -0
  31. package/dist/abi/Generation5Bridge.json +355 -0
  32. package/dist/abi/GeoFeatureRegistry.json +235 -0
  33. package/dist/abi/IAgentAccountFactoryView.json +26 -0
  34. package/dist/abi/IAgentAccountGovernanceTimelockView.json +15 -0
  35. package/dist/abi/IApprovedHashRegistryWrite.json +35 -0
  36. package/dist/abi/ICustodyEpochView.json +28 -0
  37. package/dist/abi/ICustodyPolicyAccountModuleView.json +31 -0
  38. package/dist/abi/ICustodyPolicyFactoryView.json +13 -0
  39. package/dist/abi/ICustodyPolicyPasskeyView.json +50 -0
  40. package/dist/abi/IDelegationManager.json +18 -0
  41. package/dist/abi/IGeneration4Reads.json +143 -0
  42. package/dist/abi/IGeneration5Account.json +33 -0
  43. package/dist/abi/IGeneration5Voucher.json +26 -0
  44. package/dist/abi/IMoveAccountView.json +57 -0
  45. package/dist/abi/IMoveCustodyView.json +169 -0
  46. package/dist/abi/IMoveFactoryView.json +41 -0
  47. package/dist/abi/IPaymentReceiptRegistry.json +50 -0
  48. package/dist/abi/IRedemptionContext.json +15 -0
  49. package/dist/abi/IRegistryMembershipPolicy.json +70 -0
  50. package/dist/abi/ITimelockVeto.json +93 -0
  51. package/dist/abi/ITreasurySpendPolicyAccountView.json +44 -0
  52. package/dist/abi/IUpgradeVoucherView.json +26 -0
  53. package/dist/abi/MockUSDC.json +621 -0
  54. package/dist/abi/OntologyTermRegistry.json +268 -0
  55. package/dist/abi/PayloadClassesEnforcer.json +310 -0
  56. package/dist/abi/PaymentEnforcer.json +639 -0
  57. package/dist/abi/PaymentEscrow.json +501 -0
  58. package/dist/abi/PaymentReceiptRegistry.json +388 -0
  59. package/dist/abi/PermissionlessSubregistry.json +353 -0
  60. package/dist/abi/PricedSubregistry.json +1141 -0
  61. package/dist/abi/QuorumEnforcer.json +209 -0
  62. package/dist/abi/ReceiptAnchorRegistry.json +346 -0
  63. package/dist/abi/RelationshipTypeRegistry.json +268 -0
  64. package/dist/abi/ShapeRegistry.json +268 -0
  65. package/dist/abi/SignatureVerifier.json +196 -0
  66. package/dist/abi/SkillDefinitionRegistry.json +235 -0
  67. package/dist/abi/SmartAgentPaymaster.json +445 -1
  68. package/dist/abi/StableProxyGoverned.json +190 -0
  69. package/dist/abi/StableProxyGovernedOneShot.json +172 -0
  70. package/dist/abi/TimestampEnforcer.json +193 -0
  71. package/dist/abi/TreasurySpendPolicy.json +667 -0
  72. package/dist/abi/UpgradeVoucher.json +328 -0
  73. package/dist/abi/ValueEnforcer.json +193 -0
  74. package/dist/abi/index.d.ts +35 -0
  75. package/dist/abi/index.js +35 -0
  76. package/dist/deployments/base-sepolia.d.ts +11 -0
  77. package/dist/deployments/base-sepolia.js +51 -28
  78. package/dist/deployments/faithchain.d.ts +77 -0
  79. package/dist/deployments/faithchain.js +107 -0
  80. package/dist/deployments/hopechain.d.ts +68 -0
  81. package/dist/deployments/hopechain.js +82 -0
  82. package/dist/deployments/index.d.ts +7 -2
  83. package/dist/deployments/index.js +15 -0
  84. package/dist/deployments/paymaster-anvil.d.ts +11 -0
  85. package/dist/deployments/paymaster-anvil.js +9 -0
  86. package/dist/deployments/registries-base-sepolia.d.ts +10 -0
  87. package/dist/deployments/registries-base-sepolia.js +8 -0
  88. package/dist/deployments/registries-hopechain.d.ts +10 -0
  89. package/dist/deployments/registries-hopechain.js +8 -0
  90. package/package.json +37 -7
  91. package/src/AccountBootstrap.sol +38 -0
  92. package/src/AgentAccount.sol +1091 -134
  93. package/src/AgentAccountFactory.sol +198 -21
  94. package/src/ApprovedHashRegistry.sol +134 -10
  95. package/src/IAgentAccount.sol +37 -0
  96. package/src/SmartAgentPaymaster.sol +275 -22
  97. package/src/UniversalSignatureValidator.sol +7 -0
  98. package/src/UpgradeVoucher.sol +87 -0
  99. package/src/agency/DelegationManager.sol +299 -76
  100. package/src/agency/ICaveatEnforcer.sol +10 -0
  101. package/src/agency/IDelegationManager.sol +37 -5
  102. package/src/agreement/AgreementRegistry.sol +105 -35
  103. package/src/attestation/AttestationRegistry.sol +220 -40
  104. package/src/custody/CustodyPolicy.sol +588 -70
  105. package/src/custody/TreasurySpendPolicy.sol +338 -0
  106. package/src/enforcers/AllowedMethodsEnforcer.sol +13 -2
  107. package/src/enforcers/AllowedTargetsEnforcer.sol +13 -2
  108. package/src/enforcers/CallDataHashEnforcer.sol +7 -1
  109. package/src/enforcers/DigestBindingEnforcer.sol +182 -0
  110. package/src/enforcers/PayloadClassesEnforcer.sol +36 -0
  111. package/src/enforcers/PaymentEnforcer.sol +291 -0
  112. package/src/enforcers/QuorumEnforcer.sol +24 -3
  113. package/src/enforcers/TimestampEnforcer.sol +7 -1
  114. package/src/enforcers/ValueEnforcer.sol +13 -2
  115. package/src/geo/GeoFeatureRegistry.sol +67 -22
  116. package/src/governance/AgenticGovernance.sol +187 -4
  117. package/src/governance/GovernanceManaged.sol +2 -0
  118. package/src/governance/StableProxyGoverned.sol +79 -0
  119. package/src/governance/StableProxyGovernedOneShot.sol +93 -0
  120. package/src/identity/AgentProfilePredicates.sol +23 -0
  121. package/src/identity/AgentProfileResolver.sol +22 -2
  122. package/src/libraries/Eip7702.sol +36 -0
  123. package/src/libraries/SignatureSlotRecovery.sol +28 -7
  124. package/src/libraries/SignatureVerifier.sol +52 -0
  125. package/src/libraries/WebAuthnLib.sol +16 -0
  126. package/src/migration/Generation5Bridge.sol +364 -0
  127. package/src/mocks/MockUSDC.sol +152 -0
  128. package/src/naming/AgentNameAttributeResolver.sol +29 -4
  129. package/src/naming/AgentNamePredicates.sol +89 -0
  130. package/src/naming/AgentNameRegistry.sol +324 -20
  131. package/src/naming/AgentNameUniversalResolver.sol +35 -2
  132. package/src/naming/PermissionlessSubregistry.sol +82 -25
  133. package/src/naming/PricedSubregistry.sol +293 -0
  134. package/src/ontology/AttributeStorage.sol +93 -80
  135. package/src/ontology/OntologyTermRegistry.sol +58 -2
  136. package/src/ontology/ShapeRegistry.sol +58 -2
  137. package/src/payments/PaymentEscrow.sol +187 -0
  138. package/src/payments/PaymentReceiptRegistry.sol +100 -0
  139. package/src/provenance/ReceiptAnchorRegistry.sol +67 -0
  140. package/src/registry/AgentRegistryBase.sol +372 -0
  141. package/src/registry/EstateProjectionRegistry.sol +177 -0
  142. package/src/registry/IRegistryMembershipPolicy.sol +30 -0
  143. package/src/relationships/AgentRelationship.sol +129 -8
  144. package/src/relationships/RelationshipTypeRegistry.sol +58 -2
  145. package/src/skills/SkillDefinitionRegistry.sol +61 -17
@@ -2,6 +2,9 @@
2
2
  pragma solidity ^0.8.28;
3
3
 
4
4
  import "@openzeppelin/contracts/interfaces/IERC1271.sol";
5
+ import {Eip7702} from "../libraries/Eip7702.sol";
6
+ import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
7
+ import "../governance/StableProxyGoverned.sol";
5
8
 
6
9
  /**
7
10
  * @title AttestationRegistry
@@ -17,18 +20,43 @@ import "@openzeppelin/contracts/interfaces/IERC1271.sol";
17
20
  * ─── Key invariants (AR-*) ───
18
21
  *
19
22
  * AR-01 deterministic UID = keccak256(subject, issuer, credentialType, credentialHash, refUID, salt)
20
- * AR-02 issuer signature verified via ERC-1271 against the named issuer SA
21
- * AR-03 schemaId MUST point to a registered ShapeRegistry shape (governance-gated)
22
- * AR-04 bilateral-consent verified via DelegationManager.verifyAuthorization
23
+ * AR-02 issuer signature verified (ERC-1271 for SAs, low-s ECDSA for EOAs) over a CANONICAL TYPED
24
+ * digest recomputed on-chain — ASSOCIATION_ATTESTATION_TYPEHASH (unilateral) /
25
+ * JOINT_ISSUER_TYPEHASH (joint), each binding the parties/subject + schema + credentialType +
26
+ * credentialHash + chainId + this contract (SC-2 / ATT-1). A bare credentialHash is never trusted.
27
+ * AR-03 schemaId is an OPAQUE tag stored on the attestation. This registry does NOT dereference
28
+ * ShapeRegistry on-chain; shape/governance validation of schemaId is an off-chain/consumer
29
+ * concern. (Earlier drafts claimed on-chain ShapeRegistry enforcement — that is not implemented
30
+ * here and consumers MUST NOT assume it.)
31
+ * AR-04 bilateral consent is VERIFIED on-chain by recomputing JOINT_CONSENT_TYPEHASH (party1, party2,
32
+ * agreementCommitment, credentialHash, chainId, this contract) and requiring BOTH parties'
33
+ * signatures over it (ERC-1271 / low-s ECDSA). This entrypoint uses the direct two-party-signature
34
+ * form; the DelegationManager.verifyAuthorization predicate path is spec 249's alternative (b),
35
+ * NOT this contract's direct joint path.
23
36
  * AR-05 holder-only revocation for unilateral; either-party for joint
24
37
  * AR-06 NO issuerRevoke(...) entrypoint — by static analysis
25
38
  * AR-07 epoch-bucket timestamps; raw block.timestamp never stored
26
39
  * AR-08 four indexed event topics (EAS-like)
27
- * AR-09 immutable + non-upgradeable; no admin
40
+ * AR-09 no admin. A direct deployment is immutable; spec 447 — behind a stable proxy, governance may replace the
41
+ * code (and nothing else). Its digests bind `address(this)` per call, so they name the proxy and survive a fix.
42
+ * AR-10 (spec 445 / REG-3, ledger ATT-2) revocation follows the attestation's CONTENT, not its salt:
43
+ * the content id is the UID without the salt, plus the schema — (subject, party2, issuer, schemaId,
44
+ * credentialType, credentialHash, refUID). Revoking any row revokes that content: it cannot be
45
+ * re-anchored under a new salt, and every sibling row already anchored reads as revoked. An issuer
46
+ * who wants to attest again issues a NEW credential (a different credentialHash).
47
+ * AR-11 (REG-8) the status-list pointer is inside the issuer digest (whoever anchors cannot choose it),
48
+ * and a unilateral attestation is anchored by its SUBJECT (it is the holder's public statement of
49
+ * a subject↔issuer link — nobody else may publish it).
28
50
  *
29
51
  * Spec 242 §9 + ADR-0023.
30
52
  */
31
- contract AttestationRegistry {
53
+ contract AttestationRegistry is StableProxyGoverned {
54
+ /// @notice Spec 447 — a DIRECT deployment, initialized here with no governance (its code is frozen, as
55
+ /// before). Behind a stable proxy, `initialize(governance_)` instead; the governance is then the only
56
+ /// upgrade authority. This contract has no admin of its own: governance can replace the code behind
57
+ /// the proxy and nothing else.
58
+ constructor() initializer {}
59
+
32
60
  // ─── Constants ──────────────────────────────────────────────────────
33
61
 
34
62
  uint64 public constant EPOCH_SECONDS = 3600;
@@ -44,12 +72,35 @@ contract AttestationRegistry {
44
72
  error InvalidParties();
45
73
  error InvalidPartyConsent();
46
74
  error EmptyCredentialHash();
75
+ /// @notice REG-3 — this content (subject/parties + issuer + schema + type + credential hash + ref)
76
+ /// was revoked; a new salt does not make it a new attestation.
77
+ error ContentRevoked(bytes32 contentId);
47
78
 
48
79
  /// @dev RW1-1 (ADR-0027) — the canonical consent payload each party signs to consent to a
49
80
  /// joint agreement. The contract RECOMPUTES this digest from calldata; a stored/supplied
50
81
  /// reference is not consent. Binds the consent to the exact parties + agreement + credential.
82
+ /// ATT-3 (audit 2026-06-10): also binds chainId + this registry, mirroring the issuer side
83
+ /// (ATT-1) and the association path (SC-2). Without it a party's consent signature could be
84
+ /// replayed on another chain or a redeployed registry (the attestation map is per-instance
85
+ /// storage, so a cross-instance replay anchors a fresh spoofed attestation).
51
86
  bytes32 internal constant JOINT_CONSENT_TYPEHASH = keccak256(
52
- "JointAgreementConsent(address party1,address party2,bytes32 agreementCommitment,bytes32 credentialHash)"
87
+ "JointAgreementConsent(address party1,address party2,bytes32 agreementCommitment,bytes32 credentialHash,uint256 chainId,address verifyingContract)"
88
+ );
89
+
90
+ /// @dev ATT-1 (audit 2026-06-10): the SC-2 bug class lived on in the JOINT issuer signature — it was
91
+ /// verified over a bare `credentialHash`, so a known issuer signature could be reused to anchor a
92
+ /// spoofed issuer-backed joint attestation with different parties/schema. The issuer now signs a
93
+ /// digest binding parties + schema + credential type + commitment + chain + this contract.
94
+ bytes32 internal constant JOINT_ISSUER_TYPEHASH = keccak256(
95
+ "JointAgreementIssuerAttestation(address party1,address party2,address issuer,bytes32 schemaId,bytes32 credentialType,bytes32 credentialHash,bytes32 agreementCommitment,bytes32 offchainCredentialStatusList,uint256 chainId,address verifyingContract)"
96
+ );
97
+
98
+ /// @dev SC-2 (audit 2026-06-09): the issuer attestation digest binds the SUBJECT (and schema /
99
+ /// credential type / chain / this contract) — not just `credentialHash`. Previously the issuer
100
+ /// signed only the credentialHash, so anyone who learned that public hash could anchor it on
101
+ /// chain against a DIFFERENT subject. Recomputed on-chain; the TS side derives the same constant.
102
+ bytes32 internal constant ASSOCIATION_ATTESTATION_TYPEHASH = keccak256(
103
+ "AssociationAttestation(address subject,address issuer,bytes32 schemaId,bytes32 credentialType,bytes32 credentialHash,bytes32 offchainCredentialStatusList,uint256 chainId,address verifyingContract)"
53
104
  );
54
105
 
55
106
  // ─── Storage ────────────────────────────────────────────────────────
@@ -72,6 +123,9 @@ contract AttestationRegistry {
72
123
 
73
124
  mapping(bytes32 => Attestation) private _attestations;
74
125
 
126
+ /// @dev AR-10 / REG-3: contentId => the epoch bucket its content was revoked in (0 = live).
127
+ mapping(bytes32 => uint64) private _contentRevokedAt;
128
+
75
129
  // ─── Requests ───────────────────────────────────────────────────────
76
130
 
77
131
  struct AssociationAttestationRequest {
@@ -137,12 +191,37 @@ contract AttestationRegistry {
137
191
  /// @notice Unilateral attestation by a holder against an issued credential.
138
192
  function assertAssociation(AssociationAttestationRequest calldata req) external returns (bytes32) {
139
193
  if (req.credentialHash == bytes32(0)) revert EmptyCredentialHash();
140
-
141
- // AR-02: verify issuer signature over credentialHash
142
- if (!_isValidSignatureBool(req.issuer, req.credentialHash, req.issuerSignature)) {
194
+ // AR-11 / REG-8: the holder anchors its own association. Anyone holding the issuer's signature
195
+ // could previously publish the subject↔issuer link (and pick the status-list pointer).
196
+ Eip7702.refuseDelegatedEOA(msg.sender); // spec 448 §0 (EIP-7702)
197
+ if (msg.sender != req.subject) revert NotSubject();
198
+
199
+ // SC-2: RECOMPUTE the issuer-attestation digest binding the SUBJECT (+ schema / type / chain /
200
+ // this contract) and verify the issuer signed THAT. A known credentialHash can no longer be
201
+ // anchored against an attacker-chosen subject.
202
+ bytes32 issuerDigest = keccak256(
203
+ abi.encode(
204
+ ASSOCIATION_ATTESTATION_TYPEHASH,
205
+ req.subject,
206
+ req.issuer,
207
+ req.schemaId,
208
+ req.credentialType,
209
+ req.credentialHash,
210
+ req.offchainCredentialStatusList, // REG-8: the issuer's revocation channel is the issuer's to name
211
+ block.chainid,
212
+ address(this)
213
+ )
214
+ );
215
+ if (!_isValidSignatureBool(req.issuer, issuerDigest, req.issuerSignature)) {
143
216
  revert InvalidIssuerSignature();
144
217
  }
145
218
 
219
+ // AR-10 / REG-3: revoked content stays revoked under any salt.
220
+ {
221
+ bytes32 cid = _contentId(req.subject, address(0), req.issuer, req.schemaId, req.credentialType, req.credentialHash, bytes32(0));
222
+ if (_contentRevokedAt[cid] != 0) revert ContentRevoked(cid);
223
+ }
224
+
146
225
  bytes32 uid = _computeUid(
147
226
  req.subject,
148
227
  address(0),
@@ -192,17 +271,57 @@ contract AttestationRegistry {
192
271
  if (req.party1 == address(0) || req.party2 == address(0)) revert InvalidParties();
193
272
  if (req.party1 == req.party2) revert InvalidParties();
194
273
 
195
- if (!_isValidSignatureBool(req.issuer, req.credentialHash, req.issuerSignature)) {
274
+ // ATT-1 (audit 2026-06-10): the issuer signs a FULL typed digest binding the parties, schema,
275
+ // credential type/hash, the agreement commitment (refUID), chain, and this registry — not a bare
276
+ // `credentialHash`. A leaked/observed issuer signature can no longer be replayed to anchor an
277
+ // issuer-backed joint attestation for different parties/schema/chain.
278
+ bytes32 issuerDigest = keccak256(
279
+ abi.encode(
280
+ JOINT_ISSUER_TYPEHASH,
281
+ req.party1,
282
+ req.party2,
283
+ req.issuer,
284
+ req.schemaId,
285
+ req.credentialType,
286
+ req.credentialHash,
287
+ req.refUID,
288
+ req.offchainCredentialStatusList, // REG-8
289
+ block.chainid,
290
+ address(this)
291
+ )
292
+ );
293
+ if (!_isValidSignatureBool(req.issuer, issuerDigest, req.issuerSignature)) {
196
294
  revert InvalidIssuerSignature();
197
295
  }
198
296
 
199
297
  // VERIFY bilateral consent: recompute the digest, require both parties' signatures over it.
298
+ // ATT-3: chainId + address(this) bound (anti cross-chain / redeployed-registry replay).
200
299
  bytes32 consentDigest = keccak256(
201
- abi.encode(JOINT_CONSENT_TYPEHASH, req.party1, req.party2, req.refUID, req.credentialHash)
300
+ abi.encode(
301
+ JOINT_CONSENT_TYPEHASH,
302
+ req.party1,
303
+ req.party2,
304
+ req.refUID,
305
+ req.credentialHash,
306
+ block.chainid,
307
+ address(this)
308
+ )
202
309
  );
203
310
  if (!_isValidSignatureBool(req.party1, consentDigest, req.party1Signature)) revert InvalidPartyConsent();
204
311
  if (!_isValidSignatureBool(req.party2, consentDigest, req.party2Signature)) revert InvalidPartyConsent();
205
312
 
313
+ // AR-10 / REG-3: "either party may revoke" is durable — the consent signatures are public
314
+ // calldata, and without this anyone could re-anchor the revoked agreement under a new salt.
315
+ {
316
+ bytes32 cid = _contentId(req.party1, req.party2, req.issuer, req.schemaId, req.credentialType, req.credentialHash, req.refUID);
317
+ if (_contentRevokedAt[cid] != 0) revert ContentRevoked(cid);
318
+ // Audit 2026-12-02 C4-4: the content id above includes the issuer, the schema and the credential type —
319
+ // three fields the consent signatures do NOT cover and a re-anchorer chooses. A party's revocation
320
+ // therefore also follows exactly what the two parties signed.
321
+ cid = _jointConsentKey(req.party1, req.party2, req.refUID, req.credentialHash);
322
+ if (_contentRevokedAt[cid] != 0) revert ContentRevoked(cid);
323
+ }
324
+
206
325
  bytes32 uid = _computeUid(
207
326
  req.party1,
208
327
  req.party2,
@@ -241,9 +360,7 @@ contract AttestationRegistry {
241
360
  if (a.uid == bytes32(0)) revert AttestationNotFound();
242
361
  if (a.party2 != address(0)) revert NotSubject(); // joint — wrong entrypoint
243
362
  if (msg.sender != a.subject) revert NotSubject();
244
- if (a.revocationEpochBucket != 0) revert AlreadyRevoked();
245
-
246
- a.revocationEpochBucket = uint64(block.timestamp) / EPOCH_SECONDS;
363
+ _revoke(a);
247
364
  emit Revoked(msg.sender, a.credentialType, uid, reasonHash);
248
365
  }
249
366
 
@@ -253,9 +370,7 @@ contract AttestationRegistry {
253
370
  if (a.uid == bytes32(0)) revert AttestationNotFound();
254
371
  if (a.party2 == address(0)) revert NotParty(); // unilateral — wrong entrypoint
255
372
  if (msg.sender != a.subject && msg.sender != a.party2) revert NotParty();
256
- if (a.revocationEpochBucket != 0) revert AlreadyRevoked();
257
-
258
- a.revocationEpochBucket = uint64(block.timestamp) / EPOCH_SECONDS;
373
+ _revoke(a);
259
374
  emit Revoked(msg.sender, a.credentialType, uid, reasonHash);
260
375
  }
261
376
 
@@ -263,16 +378,78 @@ contract AttestationRegistry {
263
378
  function getAttestation(bytes32 uid) external view returns (Attestation memory) {
264
379
  Attestation memory a = _attestations[uid];
265
380
  if (a.uid == bytes32(0)) revert AttestationNotFound();
381
+ // AR-10: a sibling row (same content, another salt) reads as revoked from the moment the content was.
382
+ if (a.revocationEpochBucket == 0) {
383
+ a.revocationEpochBucket = _contentRevokedAt[
384
+ _contentId(a.subject, a.party2, a.issuer, a.schemaId, a.credentialType, a.credentialHash, a.refUID)
385
+ ];
386
+ }
266
387
  return a;
267
388
  }
268
389
 
269
- /// @notice Convenience — `!revoked` view.
390
+ /// @notice Convenience — `!revoked` view. False when the row OR its content was revoked (AR-10).
270
391
  function isValid(bytes32 uid) external view returns (bool) {
271
- return _attestations[uid].uid != bytes32(0) && _attestations[uid].revocationEpochBucket == 0;
392
+ Attestation storage a = _attestations[uid];
393
+ if (a.uid == bytes32(0) || a.revocationEpochBucket != 0) return false;
394
+ return _contentRevokedAt[_contentIdOf(a)] == 0;
395
+ }
396
+
397
+ /// @notice The salt-independent content id of an anchored attestation (AR-10).
398
+ function contentIdOf(bytes32 uid) external view returns (bytes32) {
399
+ Attestation storage a = _attestations[uid];
400
+ if (a.uid == bytes32(0)) revert AttestationNotFound();
401
+ return _contentIdOf(a);
402
+ }
403
+
404
+ /// @notice Was this content revoked? `contentId` = keccak256(abi.encode(subject, party2, issuer,
405
+ /// schemaId, credentialType, credentialHash, refUID)) — computable without an anchored row.
406
+ function isContentRevoked(bytes32 contentId) external view returns (bool) {
407
+ return _contentRevokedAt[contentId] != 0;
272
408
  }
273
409
 
274
410
  // ─── Internal ───────────────────────────────────────────────────────
275
411
 
412
+ function _revoke(Attestation storage a) internal {
413
+ bytes32 cid = _contentIdOf(a);
414
+ if (a.revocationEpochBucket != 0 || _contentRevokedAt[cid] != 0) revert AlreadyRevoked();
415
+ uint64 bucket = uint64(block.timestamp) / EPOCH_SECONDS;
416
+ // A revocation in epoch bucket 0 is impossible off a fresh dev chain; keep the sentinel honest.
417
+ if (bucket == 0) bucket = 1;
418
+ a.revocationEpochBucket = bucket;
419
+ _contentRevokedAt[cid] = bucket;
420
+ // C4-4: a joint agreement is revoked for what its parties consented to, whoever anchors it next.
421
+ if (a.party2 != address(0)) {
422
+ _contentRevokedAt[_jointConsentKey(a.subject, a.party2, a.refUID, a.credentialHash)] = bucket;
423
+ }
424
+ }
425
+
426
+ /// @dev Key of "the two parties' consent to (refUID, credentialHash) was withdrawn", kept in
427
+ /// `_contentRevokedAt` beside the content ids. The leading tag keeps the two key spaces apart (a content
428
+ /// id is the hash of seven words, this of five, the first of them the tag).
429
+ function _jointConsentKey(address party1, address party2, bytes32 refUID, bytes32 credentialHash)
430
+ internal
431
+ pure
432
+ returns (bytes32)
433
+ {
434
+ return keccak256(abi.encode(keccak256("agenticprimitives.joint-consent-revoked"), party1, party2, refUID, credentialHash));
435
+ }
436
+
437
+ function _contentIdOf(Attestation storage a) internal view returns (bytes32) {
438
+ return _contentId(a.subject, a.party2, a.issuer, a.schemaId, a.credentialType, a.credentialHash, a.refUID);
439
+ }
440
+
441
+ function _contentId(
442
+ address subject,
443
+ address party2,
444
+ address issuer,
445
+ bytes32 schemaId,
446
+ bytes32 credentialType,
447
+ bytes32 credentialHash,
448
+ bytes32 refUID
449
+ ) internal pure returns (bytes32) {
450
+ return keccak256(abi.encode(subject, party2, issuer, schemaId, credentialType, credentialHash, refUID));
451
+ }
452
+
276
453
  function _computeUid(
277
454
  address subject,
278
455
  address party2,
@@ -288,33 +465,36 @@ contract AttestationRegistry {
288
465
  );
289
466
  }
290
467
 
291
- /// @dev ERC-1271-first signature verification (smart accounts), with EOA fallback.
468
+ /// @dev ERC-1271 for contract signers, low-s ECDSA for EOAs. REG-16 / spec 448 §0 (EIP-7702): a delegated
469
+ /// EOA (`0xef0100 ‖ delegate`) is an EOA here — ECDSA only. Its attached code is never asked, because
470
+ /// whoever obtained one authorization signature from the key chose that code. One mechanism per kind
471
+ /// of signer (ADR-0013).
292
472
  function _isValidSignatureBool(
293
473
  address signer,
294
474
  bytes32 digest,
295
475
  bytes memory signature
296
476
  ) internal view returns (bool) {
297
- if (signer.code.length > 0) {
298
- try IERC1271(signer).isValidSignature(digest, signature) returns (bytes4 result) {
299
- return result == IERC1271.isValidSignature.selector;
300
- } catch {
301
- return false;
302
- }
303
- }
304
- // EOA fallback via eth-signed message hash + ecrecover
477
+ if (signer.code.length > 0 && !Eip7702.isDelegatedEOA(signer)) return _erc1271Ok(signer, digest, signature);
478
+ // P2-2 (audit 2026-06-10): OpenZeppelin ECDSA.tryRecover rejects high-s (malleable) signatures and
479
+ // malformed lengths. The error value is checked explicitly: on any error `recovered` is zero and
480
+ // is NOT compared (a zero `signer` can therefore never match).
305
481
  bytes32 ethHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", digest));
306
- if (signature.length != 65) return false;
307
- bytes32 r;
308
- bytes32 s;
309
- uint8 v;
310
- // solhint-disable-next-line no-inline-assembly
311
- assembly {
312
- r := mload(add(signature, 0x20))
313
- s := mload(add(signature, 0x40))
314
- v := byte(0, mload(add(signature, 0x60)))
315
- }
316
- if (v < 27) v += 27;
317
- address recovered = ecrecover(ethHash, v, r, s);
482
+ // The third return value is the error ARGUMENT (the offending length / s); the error KIND is checked.
483
+ // slither-disable-next-line unused-return
484
+ (address recovered, ECDSA.RecoverError err, ) = ECDSA.tryRecover(ethHash, signature);
485
+ if (err != ECDSA.RecoverError.NoError) return false;
318
486
  return recovered != address(0) && recovered == signer;
319
487
  }
488
+
489
+ /// @dev ERC-1271 by raw staticcall: a signer that reverts, returns nothing, or returns fewer than 32
490
+ /// bytes is "not valid" — it cannot make this registry's call revert while decoding its answer.
491
+ function _erc1271Ok(address signer, bytes32 digest, bytes memory signature) private view returns (bool) {
492
+ (bool ok, bytes memory ret) =
493
+ signer.staticcall(abi.encodeWithSelector(IERC1271.isValidSignature.selector, digest, signature));
494
+ if (!ok || ret.length < 32) return false;
495
+ return bytes32(ret) == bytes32(IERC1271.isValidSignature.selector);
496
+ }
497
+
498
+ /// @dev Spec 447 — storage gap: the contract may sit behind a stable proxy; layout gated by `check:storage-layouts`.
499
+ uint256[48] private __gap;
320
500
  }