Commit 719da58
committed
fix(blockchain): correct EAS schema UID derivation and harden event decoding
The EAS SchemaRegistry derives schema UIDs as
keccak256(abi.encodePacked(schema, resolver, revocable)). The previous
fallback in _ensure_schema_registered hashed only the schema string, which
produces a completely different UID than the one the on-chain contract
assigns. Any attestation using that fallback UID would fail verification
against the real schema, breaking the entire anchoring flow whenever log
parsing failed (for example, if a node reorders receipt logs or the first
log turns out to belong to a different contract).
This commit:
1. Adds BlockchainService.compute_schema_uid(schema, resolver, revocable),
a static method that mirrors SchemaRegistry._getUID exactly. The method
uses eth_abi.packed.encode_packed and Web3.keccak to produce the same
32-byte UID the on-chain registry would emit.
2. Rewrites _ensure_schema_registered to:
- Derive the canonical UID offline before spending any gas.
- Short-circuit via SchemaRegistry.getSchema(uid) when the schema is
already registered, avoiding redundant transactions.
- Scan every log (not just receipt.logs[0]) for a non-zero indexed uid
in topics[1] after registration.
- Fall back to the canonical UID (never keccak(schema) alone) if log
parsing returns nothing, since the canonical UID is provably equal to
the on-chain value by construction.
3. Replaces the brittle byte-slicing Attested event parser in
anchor_artifact with _extract_attestation_uid, which uses
contract.events.Attested().process_log(log) for ABI-correct decoding.
The helper also has a topic-signature fallback so it still works if
other contracts emit logs in the same transaction. Previously the code
assumed the first log was always Attested and that its data started
with the uid, which is not guaranteed by the EAS interface.
4. Adds Attested / Revoked / Registered event fragments to blockchain/abi.py
so web3.py can decode them, and pins canonical schema-UID placeholder
constants (ATTESTIX_SCHEMA_UID_BASE_SEPOLIA / _MAINNET) for the
follow-up registration SOP to populate.
Tests (tests/unit/test_blockchain.py) verify:
- compute_schema_uid matches keccak(encode_packed(...)) for the Attestix
schema and for a known EAS sample schema (vote).
- UID changes when resolver or revocable flag changes.
- Canonical UID differs from keccak(schema) alone (guards the regression).
- _extract_attestation_uid decodes a synthesized Attested log and ignores
unrelated logs in the same receipt.
20 tests pass (9 new + 11 existing); full unit suite 193 pass / 1 skip.
Refs: https://github.com/ethereum-attestation-service/eas-contracts/blob/master/contracts/SchemaRegistry.sol1 parent 691533d commit 719da58
3 files changed
Lines changed: 448 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
9 | 34 | | |
10 | 35 | | |
11 | 36 | | |
| |||
61 | 86 | | |
62 | 87 | | |
63 | 88 | | |
64 | | - | |
| 89 | + | |
| 90 | + | |
65 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
66 | 113 | | |
67 | 114 | | |
68 | 115 | | |
| |||
94 | 141 | | |
95 | 142 | | |
96 | 143 | | |
97 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
98 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
135 | 164 | | |
136 | 165 | | |
137 | 166 | | |
| |||
171 | 200 | | |
172 | 201 | | |
173 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
174 | 231 | | |
175 | 232 | | |
176 | 233 | | |
177 | 234 | | |
178 | 235 | | |
179 | | - | |
| 236 | + | |
180 | 237 | | |
181 | 238 | | |
182 | 239 | | |
| |||
189 | 246 | | |
190 | 247 | | |
191 | 248 | | |
192 | | - | |
193 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
194 | 255 | | |
195 | 256 | | |
196 | 257 | | |
197 | 258 | | |
198 | | - | |
| 259 | + | |
| 260 | + | |
199 | 261 | | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
207 | 276 | | |
208 | 277 | | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
213 | 281 | | |
214 | 282 | | |
215 | 283 | | |
| |||
221 | 289 | | |
222 | 290 | | |
223 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
224 | 368 | | |
225 | 369 | | |
226 | 370 | | |
| |||
311 | 455 | | |
312 | 456 | | |
313 | 457 | | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
328 | 471 | | |
329 | 472 | | |
330 | 473 | | |
| |||
0 commit comments