@feelyourprotocol/statemanager 8141.0.0
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.
- package/LICENSE +373 -0
- package/README.md +331 -0
- package/dist/cjs/cache/account.d.ts +85 -0
- package/dist/cjs/cache/account.d.ts.map +1 -0
- package/dist/cjs/cache/account.js +252 -0
- package/dist/cjs/cache/account.js.map +1 -0
- package/dist/cjs/cache/cache.d.ts +23 -0
- package/dist/cjs/cache/cache.d.ts.map +1 -0
- package/dist/cjs/cache/cache.js +31 -0
- package/dist/cjs/cache/cache.js.map +1 -0
- package/dist/cjs/cache/caches.d.ts +19 -0
- package/dist/cjs/cache/caches.d.ts.map +1 -0
- package/dist/cjs/cache/caches.js +107 -0
- package/dist/cjs/cache/caches.js.map +1 -0
- package/dist/cjs/cache/code.d.ts +87 -0
- package/dist/cjs/cache/code.d.ts.map +1 -0
- package/dist/cjs/cache/code.js +258 -0
- package/dist/cjs/cache/code.js.map +1 -0
- package/dist/cjs/cache/index.d.ts +7 -0
- package/dist/cjs/cache/index.d.ts.map +1 -0
- package/dist/cjs/cache/index.js +23 -0
- package/dist/cjs/cache/index.js.map +1 -0
- package/dist/cjs/cache/originalStorageCache.d.ts +21 -0
- package/dist/cjs/cache/originalStorageCache.d.ts.map +1 -0
- package/dist/cjs/cache/originalStorageCache.js +52 -0
- package/dist/cjs/cache/originalStorageCache.js.map +1 -0
- package/dist/cjs/cache/storage.d.ts +101 -0
- package/dist/cjs/cache/storage.d.ts.map +1 -0
- package/dist/cjs/cache/storage.js +337 -0
- package/dist/cjs/cache/storage.js.map +1 -0
- package/dist/cjs/cache/types.d.ts +36 -0
- package/dist/cjs/cache/types.d.ts.map +1 -0
- package/dist/cjs/cache/types.js +8 -0
- package/dist/cjs/cache/types.js.map +1 -0
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +24 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/merkleStateManager.d.ts +260 -0
- package/dist/cjs/merkleStateManager.d.ts.map +1 -0
- package/dist/cjs/merkleStateManager.js +616 -0
- package/dist/cjs/merkleStateManager.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/proof/index.d.ts +3 -0
- package/dist/cjs/proof/index.d.ts.map +1 -0
- package/dist/cjs/proof/index.js +19 -0
- package/dist/cjs/proof/index.js.map +1 -0
- package/dist/cjs/proof/merkle.d.ts +40 -0
- package/dist/cjs/proof/merkle.d.ts.map +1 -0
- package/dist/cjs/proof/merkle.js +182 -0
- package/dist/cjs/proof/merkle.js.map +1 -0
- package/dist/cjs/proof/rpc.d.ts +10 -0
- package/dist/cjs/proof/rpc.d.ts.map +1 -0
- package/dist/cjs/proof/rpc.js +20 -0
- package/dist/cjs/proof/rpc.js.map +1 -0
- package/dist/cjs/rpcStateManager.d.ts +162 -0
- package/dist/cjs/rpcStateManager.d.ts.map +1 -0
- package/dist/cjs/rpcStateManager.js +313 -0
- package/dist/cjs/rpcStateManager.js.map +1 -0
- package/dist/cjs/simpleStateManager.d.ts +54 -0
- package/dist/cjs/simpleStateManager.d.ts.map +1 -0
- package/dist/cjs/simpleStateManager.js +125 -0
- package/dist/cjs/simpleStateManager.js.map +1 -0
- package/dist/cjs/statefulBinaryTreeStateManager.d.ts +69 -0
- package/dist/cjs/statefulBinaryTreeStateManager.d.ts.map +1 -0
- package/dist/cjs/statefulBinaryTreeStateManager.js +576 -0
- package/dist/cjs/statefulBinaryTreeStateManager.js.map +1 -0
- package/dist/cjs/types.d.ts +92 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/util.d.ts +4 -0
- package/dist/cjs/util.d.ts.map +1 -0
- package/dist/cjs/util.js +21 -0
- package/dist/cjs/util.js.map +1 -0
- package/dist/esm/cache/account.d.ts +85 -0
- package/dist/esm/cache/account.d.ts.map +1 -0
- package/dist/esm/cache/account.js +248 -0
- package/dist/esm/cache/account.js.map +1 -0
- package/dist/esm/cache/cache.d.ts +23 -0
- package/dist/esm/cache/cache.d.ts.map +1 -0
- package/dist/esm/cache/cache.js +27 -0
- package/dist/esm/cache/cache.js.map +1 -0
- package/dist/esm/cache/caches.d.ts +19 -0
- package/dist/esm/cache/caches.d.ts.map +1 -0
- package/dist/esm/cache/caches.js +103 -0
- package/dist/esm/cache/caches.js.map +1 -0
- package/dist/esm/cache/code.d.ts +87 -0
- package/dist/esm/cache/code.d.ts.map +1 -0
- package/dist/esm/cache/code.js +254 -0
- package/dist/esm/cache/code.js.map +1 -0
- package/dist/esm/cache/index.d.ts +7 -0
- package/dist/esm/cache/index.d.ts.map +1 -0
- package/dist/esm/cache/index.js +7 -0
- package/dist/esm/cache/index.js.map +1 -0
- package/dist/esm/cache/originalStorageCache.d.ts +21 -0
- package/dist/esm/cache/originalStorageCache.d.ts.map +1 -0
- package/dist/esm/cache/originalStorageCache.js +48 -0
- package/dist/esm/cache/originalStorageCache.js.map +1 -0
- package/dist/esm/cache/storage.d.ts +101 -0
- package/dist/esm/cache/storage.d.ts.map +1 -0
- package/dist/esm/cache/storage.js +333 -0
- package/dist/esm/cache/storage.js.map +1 -0
- package/dist/esm/cache/types.d.ts +36 -0
- package/dist/esm/cache/types.d.ts.map +1 -0
- package/dist/esm/cache/types.js +5 -0
- package/dist/esm/cache/types.js.map +1 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/merkleStateManager.d.ts +260 -0
- package/dist/esm/merkleStateManager.d.ts.map +1 -0
- package/dist/esm/merkleStateManager.js +612 -0
- package/dist/esm/merkleStateManager.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/proof/index.d.ts +3 -0
- package/dist/esm/proof/index.d.ts.map +1 -0
- package/dist/esm/proof/index.js +3 -0
- package/dist/esm/proof/index.js.map +1 -0
- package/dist/esm/proof/merkle.d.ts +40 -0
- package/dist/esm/proof/merkle.d.ts.map +1 -0
- package/dist/esm/proof/merkle.js +175 -0
- package/dist/esm/proof/merkle.js.map +1 -0
- package/dist/esm/proof/rpc.d.ts +10 -0
- package/dist/esm/proof/rpc.d.ts.map +1 -0
- package/dist/esm/proof/rpc.js +17 -0
- package/dist/esm/proof/rpc.js.map +1 -0
- package/dist/esm/rpcStateManager.d.ts +162 -0
- package/dist/esm/rpcStateManager.d.ts.map +1 -0
- package/dist/esm/rpcStateManager.js +308 -0
- package/dist/esm/rpcStateManager.js.map +1 -0
- package/dist/esm/simpleStateManager.d.ts +54 -0
- package/dist/esm/simpleStateManager.d.ts.map +1 -0
- package/dist/esm/simpleStateManager.js +121 -0
- package/dist/esm/simpleStateManager.js.map +1 -0
- package/dist/esm/statefulBinaryTreeStateManager.d.ts +69 -0
- package/dist/esm/statefulBinaryTreeStateManager.d.ts.map +1 -0
- package/dist/esm/statefulBinaryTreeStateManager.js +572 -0
- package/dist/esm/statefulBinaryTreeStateManager.js.map +1 -0
- package/dist/esm/types.d.ts +92 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/util.d.ts +4 -0
- package/dist/esm/util.d.ts.map +1 -0
- package/dist/esm/util.js +18 -0
- package/dist/esm/util.js.map +1 -0
- package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.prod.esm.tsbuildinfo +1 -0
- package/package.json +74 -0
- package/src/cache/account.ts +277 -0
- package/src/cache/cache.ts +35 -0
- package/src/cache/caches.ts +125 -0
- package/src/cache/code.ts +277 -0
- package/src/cache/index.ts +6 -0
- package/src/cache/originalStorageCache.ts +57 -0
- package/src/cache/storage.ts +369 -0
- package/src/cache/types.ts +38 -0
- package/src/index.ts +7 -0
- package/src/merkleStateManager.ts +737 -0
- package/src/proof/index.ts +2 -0
- package/src/proof/merkle.ts +264 -0
- package/src/proof/rpc.ts +24 -0
- package/src/rpcStateManager.ts +381 -0
- package/src/simpleStateManager.ts +154 -0
- package/src/statefulBinaryTreeStateManager.ts +789 -0
- package/src/types.ts +103 -0
- package/src/util.ts +28 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./merkle.js"), exports);
|
|
18
|
+
__exportStar(require("./rpc.js"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/proof/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,2CAAwB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { MerkleStateManager } from '../merkleStateManager.ts';
|
|
2
|
+
import type { Proof, StorageProof } from '@feelyourprotocol/common';
|
|
3
|
+
import type { Address, PrefixedHexString } from '@feelyourprotocol/util';
|
|
4
|
+
import type { MerkleStateManagerOpts } from '../index.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Get an EIP-1186 proof
|
|
7
|
+
* @param address address to get proof of
|
|
8
|
+
* @param storageSlots storage slots to get proof of
|
|
9
|
+
*/
|
|
10
|
+
export declare function getMerkleStateProof(sm: MerkleStateManager, address: Address, storageSlots?: Uint8Array[]): Promise<Proof>;
|
|
11
|
+
/**
|
|
12
|
+
* Adds a storage proof to the state manager
|
|
13
|
+
* @param storageProof The storage proof
|
|
14
|
+
* @param storageHash The root hash of the storage trie
|
|
15
|
+
* @param address The address
|
|
16
|
+
* @param safe Whether or not to verify if the reported roots match the current storage root
|
|
17
|
+
*/
|
|
18
|
+
export declare function addMerkleStateStorageProof(sm: MerkleStateManager, storageProof: StorageProof[], storageHash: PrefixedHexString, address: Address, safe?: boolean): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Create a StateManager and initialize this with proof(s) gotten previously from getProof
|
|
21
|
+
* This generates a (partial) StateManager where one can retrieve all items from the proof
|
|
22
|
+
* @param proof Either a proof retrieved from `getProof`, or an array of those proofs
|
|
23
|
+
* @param safe Whether or not to verify that the roots of the proof items match the reported roots
|
|
24
|
+
* @param opts a dictionary of StateManager opts
|
|
25
|
+
* @returns A new MerkleStateManager with elements from the given proof included in its backing state trie
|
|
26
|
+
*/
|
|
27
|
+
export declare function fromMerkleStateProof(proof: Proof | Proof[], safe?: boolean, opts?: MerkleStateManagerOpts): Promise<MerkleStateManager>;
|
|
28
|
+
/**
|
|
29
|
+
* Add proof(s) into an already existing trie
|
|
30
|
+
* @param proof The proof(s) retrieved from `getProof`
|
|
31
|
+
* @param verifyRoot verify that all proof root nodes match statemanager's stateroot - should be
|
|
32
|
+
* set to `false` when constructing a state manager where the underlying trie has proof nodes from different state roots
|
|
33
|
+
*/
|
|
34
|
+
export declare function addMerkleStateProofData(sm: MerkleStateManager, proof: Proof | Proof[], safe?: boolean): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Verify an EIP-1186 proof. Throws if proof is invalid, otherwise returns true.
|
|
37
|
+
* @param proof the proof to prove
|
|
38
|
+
*/
|
|
39
|
+
export declare function verifyMerkleStateProof(sm: MerkleStateManager, proof: Proof): Promise<boolean>;
|
|
40
|
+
//# sourceMappingURL=merkle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merkle.d.ts","sourceRoot":"","sources":["../../../src/proof/merkle.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAE7D,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAClE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEzD;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,kBAAkB,EACtB,OAAO,EAAE,OAAO,EAChB,YAAY,GAAE,UAAU,EAAO,GAC9B,OAAO,CAAC,KAAK,CAAC,CA0ChB;AAED;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAC9C,EAAE,EAAE,kBAAkB,EACtB,YAAY,EAAE,YAAY,EAAE,EAC5B,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,OAAO,EAChB,IAAI,GAAE,OAAe,iBAWtB;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE,EACtB,IAAI,GAAE,OAAe,EACrB,IAAI,GAAE,sBAA2B,GAChC,OAAO,CAAC,kBAAkB,CAAC,CA8B7B;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE,EACtB,IAAI,GAAE,OAAe,iBAoBtB;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,KAAK,GACX,OAAO,CAAC,OAAO,CAAC,CA0ElB"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMerkleStateProof = getMerkleStateProof;
|
|
4
|
+
exports.addMerkleStateStorageProof = addMerkleStateStorageProof;
|
|
5
|
+
exports.fromMerkleStateProof = fromMerkleStateProof;
|
|
6
|
+
exports.addMerkleStateProofData = addMerkleStateProofData;
|
|
7
|
+
exports.verifyMerkleStateProof = verifyMerkleStateProof;
|
|
8
|
+
const mpt_1 = require("@feelyourprotocol/mpt");
|
|
9
|
+
const rlp_1 = require("@feelyourprotocol/rlp");
|
|
10
|
+
const util_1 = require("@feelyourprotocol/util");
|
|
11
|
+
const merkleStateManager_ts_1 = require("../merkleStateManager.js");
|
|
12
|
+
/**
|
|
13
|
+
* Get an EIP-1186 proof
|
|
14
|
+
* @param address address to get proof of
|
|
15
|
+
* @param storageSlots storage slots to get proof of
|
|
16
|
+
*/
|
|
17
|
+
async function getMerkleStateProof(sm, address, storageSlots = []) {
|
|
18
|
+
await sm['flush']();
|
|
19
|
+
const account = await sm.getAccount(address);
|
|
20
|
+
if (!account) {
|
|
21
|
+
const returnValue = {
|
|
22
|
+
address: address.toString(),
|
|
23
|
+
balance: '0x0',
|
|
24
|
+
codeHash: util_1.KECCAK256_NULL_S,
|
|
25
|
+
nonce: '0x0',
|
|
26
|
+
storageHash: util_1.KECCAK256_RLP_S,
|
|
27
|
+
accountProof: (await (0, mpt_1.createMerkleProof)(sm['_trie'], address.bytes)).map((p) => (0, util_1.bytesToHex)(p)),
|
|
28
|
+
storageProof: [],
|
|
29
|
+
};
|
|
30
|
+
return returnValue;
|
|
31
|
+
}
|
|
32
|
+
const accountProof = (await (0, mpt_1.createMerkleProof)(sm['_trie'], address.bytes)).map((p) => (0, util_1.bytesToHex)(p));
|
|
33
|
+
const storageProof = [];
|
|
34
|
+
const storageTrie = sm['_getStorageTrie'](address, account);
|
|
35
|
+
for (const storageKey of storageSlots) {
|
|
36
|
+
const proof = (await (0, mpt_1.createMerkleProof)(storageTrie, storageKey)).map((p) => (0, util_1.bytesToHex)(p));
|
|
37
|
+
const value = (0, util_1.bytesToHex)(await sm.getStorage(address, storageKey));
|
|
38
|
+
const proofItem = {
|
|
39
|
+
key: (0, util_1.bytesToHex)(storageKey),
|
|
40
|
+
value: value === '0x' ? '0x0' : value, // Return '0x' values as '0x0' since this is a JSON RPC response
|
|
41
|
+
proof,
|
|
42
|
+
};
|
|
43
|
+
storageProof.push(proofItem);
|
|
44
|
+
}
|
|
45
|
+
const returnValue = {
|
|
46
|
+
address: address.toString(),
|
|
47
|
+
balance: (0, util_1.bigIntToHex)(account.balance),
|
|
48
|
+
codeHash: (0, util_1.bytesToHex)(account.codeHash),
|
|
49
|
+
nonce: (0, util_1.bigIntToHex)(account.nonce),
|
|
50
|
+
storageHash: (0, util_1.bytesToHex)(account.storageRoot),
|
|
51
|
+
accountProof,
|
|
52
|
+
storageProof,
|
|
53
|
+
};
|
|
54
|
+
return returnValue;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Adds a storage proof to the state manager
|
|
58
|
+
* @param storageProof The storage proof
|
|
59
|
+
* @param storageHash The root hash of the storage trie
|
|
60
|
+
* @param address The address
|
|
61
|
+
* @param safe Whether or not to verify if the reported roots match the current storage root
|
|
62
|
+
*/
|
|
63
|
+
async function addMerkleStateStorageProof(sm, storageProof, storageHash, address, safe = false) {
|
|
64
|
+
const trie = sm['_getStorageTrie'](address);
|
|
65
|
+
trie.root((0, util_1.hexToBytes)(storageHash));
|
|
66
|
+
for (let i = 0; i < storageProof.length; i++) {
|
|
67
|
+
await (0, mpt_1.updateMPTFromMerkleProof)(trie, storageProof[i].proof.map((e) => (0, util_1.hexToBytes)(e)), safe);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create a StateManager and initialize this with proof(s) gotten previously from getProof
|
|
72
|
+
* This generates a (partial) StateManager where one can retrieve all items from the proof
|
|
73
|
+
* @param proof Either a proof retrieved from `getProof`, or an array of those proofs
|
|
74
|
+
* @param safe Whether or not to verify that the roots of the proof items match the reported roots
|
|
75
|
+
* @param opts a dictionary of StateManager opts
|
|
76
|
+
* @returns A new MerkleStateManager with elements from the given proof included in its backing state trie
|
|
77
|
+
*/
|
|
78
|
+
async function fromMerkleStateProof(proof, safe = false, opts = {}) {
|
|
79
|
+
if (Array.isArray(proof)) {
|
|
80
|
+
if (proof.length === 0) {
|
|
81
|
+
return new merkleStateManager_ts_1.MerkleStateManager(opts);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const trie = opts.trie ??
|
|
85
|
+
(await (0, mpt_1.createMPTFromProof)(proof[0].accountProof.map((e) => (0, util_1.hexToBytes)(e)), { useKeyHashing: true }));
|
|
86
|
+
const sm = new merkleStateManager_ts_1.MerkleStateManager({ ...opts, trie });
|
|
87
|
+
const address = (0, util_1.createAddressFromString)(proof[0].address);
|
|
88
|
+
await addMerkleStateStorageProof(sm, proof[0].storageProof, proof[0].storageHash, address, safe);
|
|
89
|
+
for (let i = 1; i < proof.length; i++) {
|
|
90
|
+
const proofItem = proof[i];
|
|
91
|
+
await addMerkleStateProofData(sm, proofItem, true);
|
|
92
|
+
}
|
|
93
|
+
await sm.flush(); // TODO verify if this is necessary
|
|
94
|
+
return sm;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
return fromMerkleStateProof([proof], safe, opts);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Add proof(s) into an already existing trie
|
|
103
|
+
* @param proof The proof(s) retrieved from `getProof`
|
|
104
|
+
* @param verifyRoot verify that all proof root nodes match statemanager's stateroot - should be
|
|
105
|
+
* set to `false` when constructing a state manager where the underlying trie has proof nodes from different state roots
|
|
106
|
+
*/
|
|
107
|
+
async function addMerkleStateProofData(sm, proof, safe = false) {
|
|
108
|
+
if (Array.isArray(proof)) {
|
|
109
|
+
for (let i = 0; i < proof.length; i++) {
|
|
110
|
+
await (0, mpt_1.updateMPTFromMerkleProof)(sm['_trie'], proof[i].accountProof.map((e) => (0, util_1.hexToBytes)(e)), safe);
|
|
111
|
+
await addMerkleStateStorageProof(sm, proof[i].storageProof, proof[i].storageHash, (0, util_1.createAddressFromString)(proof[i].address), safe);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
await addMerkleStateProofData(sm, [proof], safe);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Verify an EIP-1186 proof. Throws if proof is invalid, otherwise returns true.
|
|
120
|
+
* @param proof the proof to prove
|
|
121
|
+
*/
|
|
122
|
+
async function verifyMerkleStateProof(sm, proof) {
|
|
123
|
+
const key = (0, util_1.hexToBytes)(proof.address);
|
|
124
|
+
const accountProof = proof.accountProof.map((rlpString) => (0, util_1.hexToBytes)(rlpString));
|
|
125
|
+
// This returns the account if the proof is valid.
|
|
126
|
+
// Verify that it matches the reported account.
|
|
127
|
+
const value = await (0, mpt_1.verifyMerkleProof)(key, accountProof, {
|
|
128
|
+
useKeyHashing: true,
|
|
129
|
+
});
|
|
130
|
+
if (value === null) {
|
|
131
|
+
// Verify that the account is empty in the proof.
|
|
132
|
+
const emptyBytes = new Uint8Array(0);
|
|
133
|
+
const notEmptyErrorMsg = 'Invalid proof provided: account is not empty';
|
|
134
|
+
const nonce = (0, util_1.unpadBytes)((0, util_1.hexToBytes)(proof.nonce));
|
|
135
|
+
if (!(0, util_1.equalsBytes)(nonce, emptyBytes)) {
|
|
136
|
+
throw (0, util_1.EthereumJSErrorWithoutCode)(`${notEmptyErrorMsg} (nonce is not zero)`);
|
|
137
|
+
}
|
|
138
|
+
const balance = (0, util_1.unpadBytes)((0, util_1.hexToBytes)(proof.balance));
|
|
139
|
+
if (!(0, util_1.equalsBytes)(balance, emptyBytes)) {
|
|
140
|
+
throw (0, util_1.EthereumJSErrorWithoutCode)(`${notEmptyErrorMsg} (balance is not zero)`);
|
|
141
|
+
}
|
|
142
|
+
const storageHash = (0, util_1.hexToBytes)(proof.storageHash);
|
|
143
|
+
if (!(0, util_1.equalsBytes)(storageHash, util_1.KECCAK256_RLP)) {
|
|
144
|
+
throw (0, util_1.EthereumJSErrorWithoutCode)(`${notEmptyErrorMsg} (storageHash does not equal KECCAK256_RLP)`);
|
|
145
|
+
}
|
|
146
|
+
const codeHash = (0, util_1.hexToBytes)(proof.codeHash);
|
|
147
|
+
if (!(0, util_1.equalsBytes)(codeHash, util_1.KECCAK256_NULL)) {
|
|
148
|
+
throw (0, util_1.EthereumJSErrorWithoutCode)(`${notEmptyErrorMsg} (codeHash does not equal KECCAK256_NULL)`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
const account = (0, util_1.createAccountFromRLP)(value);
|
|
153
|
+
const { nonce, balance, storageRoot, codeHash } = account;
|
|
154
|
+
const invalidErrorMsg = 'Invalid proof provided:';
|
|
155
|
+
if (nonce !== BigInt(proof.nonce)) {
|
|
156
|
+
throw (0, util_1.EthereumJSErrorWithoutCode)(`${invalidErrorMsg} nonce does not match`);
|
|
157
|
+
}
|
|
158
|
+
if (balance !== BigInt(proof.balance)) {
|
|
159
|
+
throw (0, util_1.EthereumJSErrorWithoutCode)(`${invalidErrorMsg} balance does not match`);
|
|
160
|
+
}
|
|
161
|
+
if (!(0, util_1.equalsBytes)(storageRoot, (0, util_1.hexToBytes)(proof.storageHash))) {
|
|
162
|
+
throw (0, util_1.EthereumJSErrorWithoutCode)(`${invalidErrorMsg} storageHash does not match`);
|
|
163
|
+
}
|
|
164
|
+
if (!(0, util_1.equalsBytes)(codeHash, (0, util_1.hexToBytes)(proof.codeHash))) {
|
|
165
|
+
throw (0, util_1.EthereumJSErrorWithoutCode)(`${invalidErrorMsg} codeHash does not match`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
for (const stProof of proof.storageProof) {
|
|
169
|
+
const storageProof = stProof.proof.map((value) => (0, util_1.hexToBytes)(value));
|
|
170
|
+
const storageValue = (0, util_1.setLengthLeft)((0, util_1.hexToBytes)(stProof.value), 32);
|
|
171
|
+
const storageKey = (0, util_1.hexToBytes)(stProof.key);
|
|
172
|
+
const proofValue = await (0, mpt_1.verifyMerkleProof)(storageKey, storageProof, {
|
|
173
|
+
useKeyHashing: true,
|
|
174
|
+
});
|
|
175
|
+
const reportedValue = (0, util_1.setLengthLeft)(rlp_1.RLP.decode(proofValue ?? new Uint8Array(0)), 32);
|
|
176
|
+
if (!(0, util_1.equalsBytes)(reportedValue, storageValue)) {
|
|
177
|
+
throw (0, util_1.EthereumJSErrorWithoutCode)(`Reported trie value does not match storage, key: ${stProof.key}, reported: ${(0, util_1.bytesToHex)(reportedValue)}, actual: ${(0, util_1.bytesToHex)(storageValue)}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=merkle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merkle.js","sourceRoot":"","sources":["../../../src/proof/merkle.ts"],"names":[],"mappings":";;AAkCA,kDA8CC;AASD,gEAgBC;AAUD,oDAkCC;AAQD,0DAuBC;AAMD,wDA6EC;AAvQD,yCAKwB;AACxB,yCAAqC;AACrC,2CAcyB;AAEzB,oEAA6D;AAM7D;;;;GAIG;AACI,KAAK,UAAU,mBAAmB,CACvC,EAAsB,EACtB,OAAgB,EAChB,eAA6B,EAAE;IAE/B,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,CAAA;IACnB,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;IAC5C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,WAAW,GAAU;YACzB,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE;YAC3B,OAAO,EAAE,KAAK;Y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AAI,UAAU,CAAC,CAAC,CAAC,CAAe,EACzD,EAAE,CACH,CAAA;QACD,IAAI,CAAC,IAAA,kBAAW,EAAC,aAAa,EAAE,YAAY,CAAC,EAAE,CAAC;YAC9C,MAAM,IAAA,iCAA0B,EAC9B,oDAAoD,OAAO,CAAC,GAAG,eAAe,IAAA,iBAAU,EACtF,aAAa,CACd,aAAa,IAAA,iBAAU,EAAC,YAAY,CAAC,EAAE,CACzC,CAAA;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Address } from '@feelyourprotocol/util';
|
|
2
|
+
import type { Proof, RPCStateManager } from '../index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Get an EIP-1186 proof from the provider
|
|
5
|
+
* @param address address to get proof of
|
|
6
|
+
* @param storageSlots storage slots to get proof of
|
|
7
|
+
* @returns an EIP-1186 formatted proof
|
|
8
|
+
*/
|
|
9
|
+
export declare function getRPCStateProof(sm: RPCStateManager, address: Address, storageSlots?: Uint8Array[]): Promise<Proof>;
|
|
10
|
+
//# sourceMappingURL=rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../../../src/proof/rpc.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAEzD;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,EAAE,EAAE,eAAe,EACnB,OAAO,EAAE,OAAO,EAChB,YAAY,GAAE,UAAU,EAAO,GAC9B,OAAO,CAAC,KAAK,CAAC,CAQhB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRPCStateProof = getRPCStateProof;
|
|
4
|
+
const util_1 = require("@feelyourprotocol/util");
|
|
5
|
+
/**
|
|
6
|
+
* Get an EIP-1186 proof from the provider
|
|
7
|
+
* @param address address to get proof of
|
|
8
|
+
* @param storageSlots storage slots to get proof of
|
|
9
|
+
* @returns an EIP-1186 formatted proof
|
|
10
|
+
*/
|
|
11
|
+
async function getRPCStateProof(sm, address, storageSlots = []) {
|
|
12
|
+
if (sm['DEBUG'])
|
|
13
|
+
sm['_debug'](`retrieving proof from provider for ${address.toString()}`);
|
|
14
|
+
const proof = await (0, util_1.fetchFromProvider)(sm['_provider'], {
|
|
15
|
+
method: 'eth_getProof',
|
|
16
|
+
params: [address.toString(), storageSlots.map(util_1.bytesToHex), sm['_blockTag']],
|
|
17
|
+
});
|
|
18
|
+
return proof;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=rpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../src/proof/rpc.ts"],"names":[],"mappings":";;AAWA,4CAYC;AAvBD,2CAAgE;AAKhE;;;;;GAKG;AACI,KAAK,UAAU,gBAAgB,CACpC,EAAmB,EACnB,OAAgB,EAChB,eAA6B,EAAE;IAE/B,IAAI,EAAE,CAAC,OAAO,CAAC;QAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,sCAAsC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IACzF,MAAM,KAAK,GAAG,MAAM,IAAA,wBAAiB,EAAC,EAAE,CAAC,WAAW,CAAC,EAAE;QACrD,MAAM,EAAE,cAAc;QACtB,MAAM,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,YAAY,CAAC,GAAG,CAAC,iBAAU,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC;KAC5E,CAAC,CAAA;IAEF,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { Common } from '@feelyourprotocol/common';
|
|
2
|
+
import { Account } from '@feelyourprotocol/util';
|
|
3
|
+
import { Caches, OriginalStorageCache } from './cache/index.ts';
|
|
4
|
+
import type { AccountFields, StateManagerInterface, StorageDump } from '@feelyourprotocol/common';
|
|
5
|
+
import type { Address } from '@feelyourprotocol/util';
|
|
6
|
+
import type { Debugger } from 'debug';
|
|
7
|
+
import type { RPCStateManagerOpts } from './index.ts';
|
|
8
|
+
export declare class RPCStateManager implements StateManagerInterface {
|
|
9
|
+
protected _provider: string;
|
|
10
|
+
protected _caches: Caches;
|
|
11
|
+
protected _blockTag: string;
|
|
12
|
+
originalStorageCache: OriginalStorageCache;
|
|
13
|
+
protected _debug: Debugger;
|
|
14
|
+
protected DEBUG: boolean;
|
|
15
|
+
private keccakFunction;
|
|
16
|
+
readonly common: Common;
|
|
17
|
+
constructor(opts: RPCStateManagerOpts);
|
|
18
|
+
/**
|
|
19
|
+
* Note that the returned statemanager will share the same JSONRPCProvider as the original
|
|
20
|
+
*
|
|
21
|
+
* @returns RPCStateManager
|
|
22
|
+
*/
|
|
23
|
+
shallowCopy(): RPCStateManager;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the new block tag used when querying the provider and clears the
|
|
26
|
+
* internal cache.
|
|
27
|
+
* @param blockTag - the new block tag to use when querying the provider
|
|
28
|
+
*/
|
|
29
|
+
setBlockTag(blockTag: bigint | 'earliest'): void;
|
|
30
|
+
/**
|
|
31
|
+
* Clears the internal cache so all accounts, contract code, and storage slots will
|
|
32
|
+
* initially be retrieved from the provider
|
|
33
|
+
*/
|
|
34
|
+
clearCaches(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Gets the code corresponding to the provided `address`.
|
|
37
|
+
* @param address - Address to get the `code` for
|
|
38
|
+
* @returns {Promise<Uint8Array>} - Resolves with the code corresponding to the provided address.
|
|
39
|
+
* Returns an empty `Uint8Array` if the account has no associated code.
|
|
40
|
+
*/
|
|
41
|
+
getCode(address: Address): Promise<Uint8Array>;
|
|
42
|
+
getCodeSize(address: Address): Promise<number>;
|
|
43
|
+
/**
|
|
44
|
+
* Adds `value` to the state trie as code, and sets `codeHash` on the account
|
|
45
|
+
* corresponding to `address` to reference this.
|
|
46
|
+
* @param address - Address of the `account` to add the `code` for
|
|
47
|
+
* @param value - The value of the `code`
|
|
48
|
+
*/
|
|
49
|
+
putCode(address: Address, value: Uint8Array): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Gets the storage value associated with the provided `address` and `key`. This method returns
|
|
52
|
+
* the shortest representation of the stored value.
|
|
53
|
+
* @param address - Address of the account to get the storage for
|
|
54
|
+
* @param key - Key in the account's storage to get the value for. Must be 32 bytes long.
|
|
55
|
+
* @returns {Uint8Array} - The storage value for the account
|
|
56
|
+
* corresponding to the provided address at the provided key.
|
|
57
|
+
* If this does not exist an empty `Uint8Array` is returned.
|
|
58
|
+
*/
|
|
59
|
+
getStorage(address: Address, key: Uint8Array): Promise<Uint8Array>;
|
|
60
|
+
/**
|
|
61
|
+
* Adds value to the cache for the `account`
|
|
62
|
+
* corresponding to `address` at the provided `key`.
|
|
63
|
+
* @param address - Address to set a storage value for
|
|
64
|
+
* @param key - Key to set the value at. Must be 32 bytes long.
|
|
65
|
+
* @param value - Value to set at `key` for account corresponding to `address`.
|
|
66
|
+
* Cannot be more than 32 bytes. Leading zeros are stripped.
|
|
67
|
+
* If it is empty or filled with zeros, deletes the value.
|
|
68
|
+
*/
|
|
69
|
+
putStorage(address: Address, key: Uint8Array, value: Uint8Array): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Clears all storage entries for the account corresponding to `address`.
|
|
72
|
+
* @param address - Address to clear the storage of
|
|
73
|
+
*/
|
|
74
|
+
clearStorage(address: Address): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Dumps the RLP-encoded storage values for an `account` specified by `address`.
|
|
77
|
+
* @param address - The address of the `account` to return storage for
|
|
78
|
+
* @returns {Promise<StorageDump>} - The state of the account as an `Object` map.
|
|
79
|
+
* Keys are the storage keys, values are the storage values as strings.
|
|
80
|
+
* Both are represented as `0x` prefixed hex strings.
|
|
81
|
+
*/
|
|
82
|
+
dumpStorage(address: Address): Promise<StorageDump>;
|
|
83
|
+
/**
|
|
84
|
+
* Gets the account associated with `address` or `undefined` if account does not exist
|
|
85
|
+
* @param address - Address of the `account` to get
|
|
86
|
+
*/
|
|
87
|
+
getAccount(address: Address): Promise<Account | undefined>;
|
|
88
|
+
/**
|
|
89
|
+
* Retrieves an account from the provider and stores in the local trie
|
|
90
|
+
* @param address Address of account to be retrieved from provider
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
getAccountFromProvider(address: Address): Promise<Account>;
|
|
94
|
+
/**
|
|
95
|
+
* Saves an account into state under the provided `address`.
|
|
96
|
+
* @param address - Address under which to store `account`
|
|
97
|
+
* @param account - The account to store
|
|
98
|
+
*/
|
|
99
|
+
putAccount(address: Address, account: Account | undefined): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Gets the account associated with `address`, modifies the given account
|
|
102
|
+
* fields, then saves the account into state. Account fields can include
|
|
103
|
+
* `nonce`, `balance`, `storageRoot`, and `codeHash`.
|
|
104
|
+
* @param address - Address of the account to modify
|
|
105
|
+
* @param accountFields - Object containing account fields and values to modify
|
|
106
|
+
*/
|
|
107
|
+
modifyAccountFields(address: Address, accountFields: AccountFields): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Deletes an account from state under the provided `address`.
|
|
110
|
+
* @param address - Address of the account which should be deleted
|
|
111
|
+
*/
|
|
112
|
+
deleteAccount(address: Address): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Returns the applied key for a given address
|
|
115
|
+
* Used for saving preimages
|
|
116
|
+
* @param address - The address to return the applied key
|
|
117
|
+
* @returns {Uint8Array} - The applied key (e.g. hashed address)
|
|
118
|
+
*/
|
|
119
|
+
getAppliedKey(address: Uint8Array): Uint8Array;
|
|
120
|
+
/**
|
|
121
|
+
* Checkpoints the current state of the StateManager instance.
|
|
122
|
+
* State changes that follow can then be committed by calling
|
|
123
|
+
* `commit` or `reverted` by calling rollback.
|
|
124
|
+
*/
|
|
125
|
+
checkpoint(): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Commits the current change-set to the instance since the
|
|
128
|
+
* last call to checkpoint.
|
|
129
|
+
*
|
|
130
|
+
* Partial implementation, called from the subclass.
|
|
131
|
+
*/
|
|
132
|
+
commit(): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Reverts the current change-set to the instance since the
|
|
135
|
+
* last call to checkpoint.
|
|
136
|
+
*
|
|
137
|
+
* Partial implementation , called from the subclass.
|
|
138
|
+
*/
|
|
139
|
+
revert(): Promise<void>;
|
|
140
|
+
flush(): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* @deprecated This method is not used by the RPC State Manager and is a stub required by the State Manager interface
|
|
143
|
+
*/
|
|
144
|
+
getStateRoot: () => Promise<Uint8Array<ArrayBuffer>>;
|
|
145
|
+
/**
|
|
146
|
+
* @deprecated This method is not used by the RPC State Manager and is a stub required by the State Manager interface
|
|
147
|
+
*/
|
|
148
|
+
setStateRoot: (_root: Uint8Array) => Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* @deprecated This method is not used by the RPC State Manager and is a stub required by the State Manager interface
|
|
151
|
+
*/
|
|
152
|
+
hasStateRoot: () => never;
|
|
153
|
+
}
|
|
154
|
+
export declare class RPCBlockChain {
|
|
155
|
+
readonly provider: string;
|
|
156
|
+
constructor(provider: string);
|
|
157
|
+
getBlock(blockId: number): Promise<{
|
|
158
|
+
hash: () => Uint8Array<ArrayBufferLike>;
|
|
159
|
+
}>;
|
|
160
|
+
shallowCopy(): this;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=rpcStateManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpcStateManager.d.ts","sourceRoot":"","sources":["../../src/rpcStateManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EA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