Commit cadec3f
authored
Verify SHA-256 of contract code matches contract hash when fetching (#2465)
### What
Add SHA-256 integrity verification to `get_remote_wasm_from_hash` in
`utils::rpc`. After fetching Wasm bytecode, compute
`sha256(returned_bytes)` and compare it to the requested hash. Return a
clear error with both the expected and computed hashes if they don't
match. Add unit tests for matching and mismatched hashes.
### Why
The CLI fetched WASM bytecode from RPC servers without verifying the
returned bytes matched the requested hash. While most data is trusted
from the connected RPC, it's good defensive approach if the CLI verifies
the contract code because it gets cached against the hash for future use
locally.
Close #24631 parent b36124d commit cadec3f
1 file changed
+56
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
305 | 324 | | |
| 325 | + | |
306 | 326 | | |
307 | 327 | | |
308 | 328 | | |
| |||
324 | 344 | | |
325 | 345 | | |
326 | 346 | | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
327 | 379 | | |
0 commit comments