forked from ensdomains/evmgateway
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathEthVerifierHooks.sol
More file actions
executable file
·51 lines (47 loc) · 1.83 KB
/
Copy pathEthVerifierHooks.sol
File metadata and controls
executable file
·51 lines (47 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IVerifierHooks, NOT_A_CONTRACT, NULL_CODE_HASH} from '../IVerifierHooks.sol';
import {SecureMerkleTrie} from './SecureMerkleTrie.sol';
import {RLPReader, RLPReaderExt} from '../RLPReaderExt.sol';
bytes32 constant EMPTY_STORAGE_HASH = keccak256(hex'80'); // see: src/eth/types.ts
contract EthVerifierHooks is IVerifierHooks {
function verifyAccountState(
bytes32 stateRoot,
address target,
bytes memory proof
) external pure returns (bytes32 storageRoot) {
(bool exists, bytes memory value) = SecureMerkleTrie.get(
abi.encodePacked(target),
abi.decode(proof, (bytes[])),
stateRoot
);
if (!exists) return NOT_A_CONTRACT;
RLPReader.RLPItem[] memory v = RLPReader.readList(value);
// accountState structure:
// standard: [nonce, balance, storageRoot, codeHash]
// blast: [nonce, flags, fixed, shares, remainder, storageRoot, codeHash]
// generalization: index from the end
bytes32 codeHash = RLPReaderExt.strictBytes32FromRLP(v[v.length - 1]);
return
codeHash == NULL_CODE_HASH
? NOT_A_CONTRACT
: RLPReaderExt.strictBytes32FromRLP(v[v.length - 2]);
}
function verifyStorageValue(
bytes32 storageRoot,
address /* target */,
uint256 slot,
bytes memory proof
) external pure returns (bytes32) {
if (storageRoot == EMPTY_STORAGE_HASH) return bytes32(0);
(bool exists, bytes memory v) = SecureMerkleTrie.get(
abi.encodePacked(slot),
abi.decode(proof, (bytes[])),
storageRoot
);
return
exists
? RLPReaderExt.bytes32FromRLP(RLPReader.readBytes(v))
: bytes32(0);
}
}