@aztec/simulator 0.0.1-commit.f1df4d2 → 0.0.1-commit.f2ce05ee

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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWNjb3VudF9wcm9vZl9mZXRjaGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvcHVibGljL2F2bS9maXh0dXJlcy9hY2NvdW50X3Byb29mX2ZldGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account_proof_fetcher.d.ts","sourceRoot":"","sources":["../../../../src/public/avm/fixtures/account_proof_fetcher.ts"],"names":[],"mappings":""}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Fetches an account proof from the Ethereum mainnet and saves it as account_proof.json.
3
+ * This script is not using any Aztec library code, so it's easily portable.
4
+ */ import fs from 'fs';
5
+ import { dirname, join } from 'path';
6
+ import { fileURLToPath } from 'url';
7
+ import { createPublicClient, fromRlp, hexToBytes, http } from 'viem';
8
+ import { mainnet } from 'viem/chains';
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
10
+ const RPC_URL = process.env.RPC_URL;
11
+ const ADDRESS = process.env.ADDRESS || '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
12
+ const BLOCK_TAG = process.env.BLOCK_NUMBER ? BigInt(process.env.BLOCK_NUMBER) : 'latest';
13
+ const MAX_ACCOUNT_PATH = 15;
14
+ function padTo(arr, len) {
15
+ return [
16
+ ...arr,
17
+ ...Array(len - arr.length).fill(0)
18
+ ].slice(0, len);
19
+ }
20
+ function toBytes(hex) {
21
+ return Array.from(hexToBytes(hex));
22
+ }
23
+ function bytesToU64s(bytes) {
24
+ const paddedBytes = padTo(bytes, 32);
25
+ return Array.from({
26
+ length: 4
27
+ }, (_, i)=>{
28
+ let val = 0n;
29
+ for(let j = 0; j < 8; j++){
30
+ val += BigInt(paddedBytes[i * 8 + j]) << BigInt(j * 8);
31
+ }
32
+ return val.toString();
33
+ });
34
+ }
35
+ function toBytesAndLen(val) {
36
+ if (val === 0n || val === 0) {
37
+ return {
38
+ bytes: [
39
+ 0
40
+ ],
41
+ length: 0
42
+ };
43
+ }
44
+ let hex = val.toString(16);
45
+ if (hex.length % 2) {
46
+ hex = '0' + hex;
47
+ }
48
+ const bytes = toBytes(`0x${hex}`);
49
+ return {
50
+ bytes,
51
+ length: bytes.length
52
+ };
53
+ }
54
+ function parseNode(rlp) {
55
+ // Should be safe when working with branches and extensions without embedded children.
56
+ const decoded = fromRlp(rlp);
57
+ const node = {
58
+ rows: Array(16).fill(0).map(()=>Array(32).fill(0)),
59
+ row_exist: Array(16).fill(false),
60
+ node_type: 0
61
+ };
62
+ if (decoded.length === 17) {
63
+ for(let i = 0; i < 16; i++){
64
+ if (decoded[i] !== '0x') {
65
+ node.row_exist[i] = true;
66
+ node.rows[i] = padTo(toBytes(decoded[i]), 32);
67
+ }
68
+ }
69
+ } else if (decoded.length === 2) {
70
+ const keyBytes = toBytes(decoded[0]);
71
+ const prefix = keyBytes[0];
72
+ if (prefix >> 4 >= 2) {
73
+ throw new Error('Unsupported: leaf node in proof path');
74
+ }
75
+ node.node_type = 1;
76
+ // Extension header format expected by the noir code: check out storage_proof types.nr.
77
+ node.rows[0][0] = prefix >> 4;
78
+ node.rows[0][8] = prefix & 0x0f;
79
+ node.rows[0][16] = keyBytes.length - 1;
80
+ for(let i = 1; i < keyBytes.length && i < 32; i++){
81
+ node.rows[1][i - 1] = keyBytes[i];
82
+ }
83
+ node.rows[2] = padTo(toBytes(decoded[1]), 32);
84
+ node.row_exist[0] = node.row_exist[1] = node.row_exist[2] = true;
85
+ }
86
+ return node;
87
+ }
88
+ function parseProof(proof, maxLen) {
89
+ const nodes = proof.slice(0, -1).slice(0, maxLen).map(parseNode);
90
+ while(nodes.length < maxLen){
91
+ nodes.push({
92
+ rows: Array(16).fill(0).map(()=>Array(32).fill(0)),
93
+ row_exist: Array(16).fill(false),
94
+ node_type: 0
95
+ });
96
+ }
97
+ return nodes;
98
+ }
99
+ function nodeToLibFormat(node) {
100
+ return {
101
+ rows: node.rows.map(bytesToU64s),
102
+ row_exist: node.row_exist,
103
+ node_type: String(node.node_type)
104
+ };
105
+ }
106
+ async function main() {
107
+ if (!RPC_URL) {
108
+ throw new Error('RPC_URL is not set');
109
+ }
110
+ console.log(`Fetching account proof for ${ADDRESS}`);
111
+ const client = createPublicClient({
112
+ chain: mainnet,
113
+ transport: http(RPC_URL)
114
+ });
115
+ const [blockNumber, proof, block] = await Promise.all([
116
+ client.getBlockNumber(),
117
+ client.getProof({
118
+ address: ADDRESS,
119
+ storageKeys: [],
120
+ blockNumber: BLOCK_TAG === 'latest' ? undefined : BLOCK_TAG
121
+ }),
122
+ client.getBlock({
123
+ blockNumber: BLOCK_TAG === 'latest' ? undefined : BLOCK_TAG
124
+ })
125
+ ]);
126
+ console.log(`Block: ${blockNumber}, Account nodes: ${proof.accountProof.length}`);
127
+ // The -1 is because the last node in the proof is the leaf, which is excluded from path verification.
128
+ const accountPathLen = proof.accountProof.length - 1;
129
+ if (accountPathLen > MAX_ACCOUNT_PATH) {
130
+ throw new Error(`Account proof path length ${accountPathLen} exceeds MAX_ACCOUNT_PATH ${MAX_ACCOUNT_PATH}. Increase the limit.`);
131
+ }
132
+ const nonce = toBytesAndLen(proof.nonce);
133
+ const balance = toBytesAndLen(proof.balance);
134
+ const data = {
135
+ block_number: String(blockNumber),
136
+ node_length: String(accountPathLen),
137
+ root: bytesToU64s(toBytes(block.stateRoot)),
138
+ nodes: parseProof(proof.accountProof, MAX_ACCOUNT_PATH).map(nodeToLibFormat),
139
+ account: {
140
+ address: toBytes(ADDRESS).map(String),
141
+ balance: padTo(balance.bytes, 32).map(String),
142
+ balance_length: String(balance.length),
143
+ code_hash: bytesToU64s(toBytes(proof.codeHash)),
144
+ nonce: padTo(nonce.bytes, 8).map(String),
145
+ nonce_length: String(nonce.length),
146
+ storage_hash: bytesToU64s(toBytes(proof.storageHash))
147
+ }
148
+ };
149
+ fs.writeFileSync(join(__dirname, 'account_proof.json'), JSON.stringify(data, null, 2));
150
+ console.log('account_proof.json generated');
151
+ }
152
+ main().catch(console.error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/simulator",
3
- "version": "0.0.1-commit.f1df4d2",
3
+ "version": "0.0.1-commit.f2ce05ee",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./server": "./dest/server.js",
@@ -64,26 +64,26 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "@aztec/constants": "0.0.1-commit.f1df4d2",
68
- "@aztec/foundation": "0.0.1-commit.f1df4d2",
69
- "@aztec/native": "0.0.1-commit.f1df4d2",
70
- "@aztec/noir-acvm_js": "0.0.1-commit.f1df4d2",
71
- "@aztec/noir-noirc_abi": "0.0.1-commit.f1df4d2",
72
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.f1df4d2",
73
- "@aztec/noir-types": "0.0.1-commit.f1df4d2",
74
- "@aztec/protocol-contracts": "0.0.1-commit.f1df4d2",
75
- "@aztec/stdlib": "0.0.1-commit.f1df4d2",
76
- "@aztec/telemetry-client": "0.0.1-commit.f1df4d2",
77
- "@aztec/world-state": "0.0.1-commit.f1df4d2",
67
+ "@aztec/constants": "0.0.1-commit.f2ce05ee",
68
+ "@aztec/foundation": "0.0.1-commit.f2ce05ee",
69
+ "@aztec/native": "0.0.1-commit.f2ce05ee",
70
+ "@aztec/noir-acvm_js": "0.0.1-commit.f2ce05ee",
71
+ "@aztec/noir-noirc_abi": "0.0.1-commit.f2ce05ee",
72
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.f2ce05ee",
73
+ "@aztec/noir-types": "0.0.1-commit.f2ce05ee",
74
+ "@aztec/protocol-contracts": "0.0.1-commit.f2ce05ee",
75
+ "@aztec/stdlib": "0.0.1-commit.f2ce05ee",
76
+ "@aztec/telemetry-client": "0.0.1-commit.f2ce05ee",
77
+ "@aztec/world-state": "0.0.1-commit.f2ce05ee",
78
78
  "lodash.clonedeep": "^4.5.0",
79
79
  "lodash.merge": "^4.6.2",
80
80
  "tslib": "^2.4.0"
81
81
  },
82
82
  "devDependencies": {
83
- "@aztec/kv-store": "0.0.1-commit.f1df4d2",
84
- "@aztec/merkle-tree": "0.0.1-commit.f1df4d2",
85
- "@aztec/noir-contracts.js": "0.0.1-commit.f1df4d2",
86
- "@aztec/noir-test-contracts.js": "0.0.1-commit.f1df4d2",
83
+ "@aztec/kv-store": "0.0.1-commit.f2ce05ee",
84
+ "@aztec/merkle-tree": "0.0.1-commit.f2ce05ee",
85
+ "@aztec/noir-contracts.js": "0.0.1-commit.f2ce05ee",
86
+ "@aztec/noir-test-contracts.js": "0.0.1-commit.f2ce05ee",
87
87
  "@jest/globals": "^30.0.0",
88
88
  "@types/jest": "^30.0.0",
89
89
  "@types/lodash.clonedeep": "^4.5.7",
@@ -0,0 +1,553 @@
1
+ {
2
+ "block_number": "24418689",
3
+ "node_length": "8",
4
+ "root": ["3685275329843603409", "17123419335373118581", "12835569427201316256", "13118379603816886709"],
5
+ "nodes": [
6
+ {
7
+ "rows": [
8
+ ["17054737604302004813", "6343715242554980695", "3833544233644425244", "15186680674377266239"],
9
+ ["1635861909532405566", "16462813701881863044", "10907999239800910347", "17964045345716427472"],
10
+ ["16922471333806880424", "11140201993938792441", "18279827319183235723", "13534698484584713056"],
11
+ ["11543713089220670042", "16881309127510986480", "4575321585638465639", "432385591391991201"],
12
+ ["17958726588825782322", "14384081168638251158", "1949734170430941864", "5207601570581416063"],
13
+ ["3704231604163049653", "3652987828955664969", "6325630326431205448", "9809873920262704737"],
14
+ ["11726817364432447262", "7790555554413528790", "1843628731650628366", "10148456167627872760"],
15
+ ["11467453508720262035", "17910230935426137656", "7511960635727323184", "12223590669454882455"],
16
+ ["8807082324071955912", "10162618927686301991", "12247869052307819189", "4533588926475541182"],
17
+ ["4759339698673524287", "8924723029732094625", "18181141808337378779", "16770360101211645862"],
18
+ ["16452597211968562023", "12853561862471979162", "4404441075009874064", "5027071185712184489"],
19
+ ["3744302548762336937", "15170145848078573764", "4871801172353387469", "10944459454682304611"],
20
+ ["12074055357051491570", "13777719101158602680", "14689759619666065122", "14391272672485519311"],
21
+ ["355665576668816872", "6941682059631116427", "6444518921940741124", "18290737145547488064"],
22
+ ["2875687389811918300", "1838822801336817711", "2479265333569869743", "15302105693473178154"],
23
+ ["12258829111945332629", "17816544774237354707", "16951549456489373725", "7588732716844682269"]
24
+ ],
25
+ "row_exist": [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true],
26
+ "node_type": "0"
27
+ },
28
+ {
29
+ "rows": [
30
+ ["12890469524344373671", "10284682682950133121", "16651011501473289645", "14889428872400142084"],
31
+ ["14716023944454817383", "6950811938270697355", "137623289319779211", "16884824870768735330"],
32
+ ["9247060171173880318", "2805976436082880901", "3454689515469978223", "11558755514853302561"],
33
+ ["3081537144398707502", "8025639129090653710", "18224042105188488519", "991361068445703764"],
34
+ ["17030736070977073133", "3460892221442338897", "2936342361768481286", "2792204730852366305"],
35
+ ["1128983063027061128", "1082543382332045948", "11210960522762322166", "1102410245488238175"],
36
+ ["13482891990781491251", "13823726067227556141", "5257712505367651518", "8491145933736731591"],
37
+ ["17728505638595121470", "7528552357025773091", "16847448152762926180", "5197371825339472865"],
38
+ ["8417488723848098840", "15508569359952333603", "15425848184361544938", "15108670249883880550"],
39
+ ["9566037169011371740", "10870790338089350782", "9675911681778956493", "10941985636369557721"],
40
+ ["18274379689463263916", "11887479721607472330", "7022201283216160674", "12576458900650644703"],
41
+ ["5661070317438858874", "6267728228688249871", "13353983556726286205", "3469532935747999599"],
42
+ ["9092275655438116627", "16566149893579045141", "4290849788413599771", "8725926317437204128"],
43
+ ["2500812921158300160", "14494682707529472826", "6021861193884461036", "11764021305049265510"],
44
+ ["1411703346360387753", "15160145734451868917", "8420223655401834613", "1241750363367990355"],
45
+ ["3484944451005592940", "4820967716927662118", "17829351042866845694", "5700011742920025958"]
46
+ ],
47
+ "row_exist": [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true],
48
+ "node_type": "0"
49
+ },
50
+ {
51
+ "rows": [
52
+ ["485352833935564971", "15563077702162583994", "5278940371622949346", "8137873112484873741"],
53
+ ["14803657496399303237", "2024635952215425466", "13451493526019815780", "8553195521053891642"],
54
+ ["13710087507160501271", "1699512272745816974", "9081569119400237467", "4819107513009276910"],
55
+ ["13253240690113961700", "7608001796836637893", "1350868719315900588", "5265600065548609776"],
56
+ ["7954924741465116363", "7745545748820888623", "6629874989123331979", "14365512543591922374"],
57
+ ["3340539549963314181", "7751464670789064414", "12780938239776021088", "4814534776661882784"],
58
+ ["220070541943854002", "4766350502015473737", "5461887152688264313", "12261197532094996224"],
59
+ ["12306543688352658069", "1629258227088050083", "7383780836553750490", "2545460613293306773"],
60
+ ["526026735457121535", "11349236110661100300", "1433276245513430458", "16769260851287949848"],
61
+ ["2609049314339143664", "16398350759940875296", "478717881284683296", "8768255998053718161"],
62
+ ["12240893756225075370", "8839012684515578389", "5992876690280937508", "8719970475708990900"],
63
+ ["7018399513333734938", "7614281463070899089", "16499663931060540798", "10166892213359231109"],
64
+ ["17610074833709121464", "10940591748431001979", "13642494512972493768", "1330296385021771242"],
65
+ ["3317198431775238894", "8682902284599858659", "6764338424274596703", "13817781537997872895"],
66
+ ["5538199751224267739", "10608228216876086723", "10147714569389968724", "10461516397553588353"],
67
+ ["3032101091948040950", "4053163650006634163", "17096694335021154511", "13743482765735572083"]
68
+ ],
69
+ "row_exist": [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true],
70
+ "node_type": "0"
71
+ },
72
+ {
73
+ "rows": [
74
+ ["1569137047052850146", "17670332500871673869", "11659462622597238604", "16311515203891465769"],
75
+ ["10278020159241294127", "2838332115345072795", "7506560487671301963", "777059029610346996"],
76
+ ["4468171491356384160", "13111771227682554689", "13753897988677511240", "5122340393103402005"],
77
+ ["308720649918850437", "12899194011402901335", "1228567641250000393", "9360936624605467499"],
78
+ ["15061597910157296832", "1334811981360659757", "10254932572650264756", "4320844791789337551"],
79
+ ["15982273164611698567", "3251168309498054995", "11506499084770739765", "7339569333465321782"],
80
+ ["10555682338952947353", "13954922589741558686", "5415225450171615741", "4176496196957394284"],
81
+ ["6600764052262947757", "15948551459317520834", "8059947160301703964", "1897417144380333876"],
82
+ ["2570228887625463234", "10147500222956330905", "4616287077297040361", "6937827664069762592"],
83
+ ["8089809411241093610", "1863317711204189108", "2708437229029652460", "7820859402624796976"],
84
+ ["9660656345977176608", "4172240964743149626", "8269947526284500125", "7680224521748799067"],
85
+ ["5736944723927035620", "6031101628801742203", "7211351670619274448", "9100121413249416405"],
86
+ ["8135211118583764413", "15059667651934057305", "1578928866096362327", "3519950446893792155"],
87
+ ["12290426792846766860", "9815786704342851453", "14268670659249231336", "5457242269017816821"],
88
+ ["12593857100783390143", "8733484966270460319", "5863027028826871620", "16286373767433096138"],
89
+ ["14693115320205534943", "11936532649648537545", "4086044087939443339", "2936764583953751733"]
90
+ ],
91
+ "row_exist": [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true],
92
+ "node_type": "0"
93
+ },
94
+ {
95
+ "rows": [
96
+ ["5871338457786118315", "7758471153775418127", "5400042299181994420", "2799947815365707034"],
97
+ ["10287162861063803201", "10327855546772552950", "12647682732562316700", "14373753595715945094"],
98
+ ["4761295407620854411", "2863766529541388450", "17545097512548033218", "1277268097130292830"],
99
+ ["3140373094932510838", "13661185401131814928", "495728499073099710", "259444734705108287"],
100
+ ["14116329330821953686", "15405518596390200946", "2316095127042025845", "15019538064710454091"],
101
+ ["191809940903789913", "2622135995787988267", "11896532978969810917", "4190194594349526641"],
102
+ ["15274610103381035090", "8257501250757004237", "17964992045413344902", "487852087658017767"],
103
+ ["2750312694502113576", "1648098958150119142", "15888022152062783514", "943744291570812954"],
104
+ ["13401887959856669341", "12148743835027779828", "4649934400901799214", "2180229756539280623"],
105
+ ["16154625936771356011", "6183841582449658189", "4188748572435777793", "9849966958679384806"],
106
+ ["12310963375009219252", "2054543063946214916", "15077082713800261238", "8323470249226296007"],
107
+ ["5428085482209520772", "7862316662409074576", "2752979489523299649", "549198729904928139"],
108
+ ["5951791680496272547", "6915567076990531311", "4184389348201572913", "7473809054799620333"],
109
+ ["6919216411715167525", "2646842652035756074", "1802896550161044086", "1249296484336785461"],
110
+ ["5551570540045461356", "12050914138862802082", "7062690080466350390", "14805225695747496249"],
111
+ ["5139064556238821710", "1749778882169369284", "17373299079737518583", "16048099913850054299"]
112
+ ],
113
+ "row_exist": [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true],
114
+ "node_type": "0"
115
+ },
116
+ {
117
+ "rows": [
118
+ ["10243488283507964985", "14280689071757106332", "2554265652416421230", "11889187775775575905"],
119
+ ["10556256216480562625", "11730339539057833593", "3215107905451140769", "14253277203204925698"],
120
+ ["9865252336369986003", "15193838217849009612", "1988597573386948407", "7623832259298063840"],
121
+ ["13171423393121267393", "8674247594106456905", "6764708787691121080", "2693557388034691442"],
122
+ ["7102085493196156044", "11685262668105812477", "4646473891342597870", "2556652641672594418"],
123
+ ["13304118412828910852", "1042715987950183696", "11214555271316634064", "4335527290867867955"],
124
+ ["4051787765350473342", "4975456944434874450", "12826437732859671676", "2780216033164673499"],
125
+ ["14665723001205500941", "9691600008719234226", "7081185465253409235", "13555292108437776650"],
126
+ ["10816256126116286471", "581096568560913561", "17140754593076188960", "8645594507796796339"],
127
+ ["17654700456282982700", "2387304199359200092", "11476164253386829482", "9745940840070269407"],
128
+ ["1654546207469228139", "3693289044968973141", "18050473866551055691", "912080879052749169"],
129
+ ["16227784718956941665", "11772668130411622022", "18089438312304007108", "7733016593473072881"],
130
+ ["81999518906732219", "14015631457220568595", "1422001567548083705", "11534067873302865511"],
131
+ ["7107574335984014460", "10229696147073193297", "14571858279764390521", "5709175760428631087"],
132
+ ["17948131165620720569", "5830988394861026152", "364488741599653220", "13046119972894298129"],
133
+ ["11051980073402370464", "7245017957056179612", "14003056353570984489", "2386947007393273635"]
134
+ ],
135
+ "row_exist": [true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true],
136
+ "node_type": "0"
137
+ },
138
+ {
139
+ "rows": [
140
+ ["0", "0", "0", "0"],
141
+ ["13580300232231609012", "18001255940302140622", "10662513367161039524", "2919380087617481871"],
142
+ ["0", "0", "0", "0"],
143
+ ["12245912451404771364", "3903638451894801289", "1057782395635835042", "5362630719488416193"],
144
+ ["14949973886094959686", "864614121862097295", "16600931899016722340", "15094620655868895698"],
145
+ ["3080859047288602111", "1027972329123687141", "2273391972247862494", "6295957585226744932"],
146
+ ["14749914466593197973", "9168694760443217861", "7799689942180282168", "11232188434628820741"],
147
+ ["3568585117210882843", "17544102760716602316", "6311596574169168615", "5977626269403184807"],
148
+ ["0", "0", "0", "0"],
149
+ ["7572174119633261425", "12894901693461620883", "18083129998479371209", "17141165865398319897"],
150
+ ["0", "0", "0", "0"],
151
+ ["0", "0", "0", "0"],
152
+ ["8158004997451105891", "4740431708386091415", "17636220932068323336", "3354757968806884176"],
153
+ ["17534134625373578377", "934778189173264355", "15551516878384019517", "1026883469410163164"],
154
+ ["0", "0", "0", "0"],
155
+ ["12067342176128531549", "9802560583520285053", "16528153709100503190", "4934415379202044661"]
156
+ ],
157
+ "row_exist": [
158
+ false,
159
+ true,
160
+ false,
161
+ true,
162
+ true,
163
+ true,
164
+ true,
165
+ true,
166
+ false,
167
+ true,
168
+ false,
169
+ false,
170
+ true,
171
+ true,
172
+ false,
173
+ true
174
+ ],
175
+ "node_type": "0"
176
+ },
177
+ {
178
+ "rows": [
179
+ ["0", "0", "0", "0"],
180
+ ["0", "0", "0", "0"],
181
+ ["16473368864426571780", "5897157522498723363", "5308604954321325241", "7584364450010199047"],
182
+ ["0", "0", "0", "0"],
183
+ ["0", "0", "0", "0"],
184
+ ["0", "0", "0", "0"],
185
+ ["0", "0", "0", "0"],
186
+ ["0", "0", "0", "0"],
187
+ ["0", "0", "0", "0"],
188
+ ["6029873436835646037", "4086735387219981484", "16080498206684064613", "3507193842316677696"],
189
+ ["0", "0", "0", "0"],
190
+ ["0", "0", "0", "0"],
191
+ ["0", "0", "0", "0"],
192
+ ["0", "0", "0", "0"],
193
+ ["0", "0", "0", "0"],
194
+ ["0", "0", "0", "0"]
195
+ ],
196
+ "row_exist": [
197
+ false,
198
+ false,
199
+ true,
200
+ false,
201
+ false,
202
+ false,
203
+ false,
204
+ false,
205
+ false,
206
+ true,
207
+ false,
208
+ false,
209
+ false,
210
+ false,
211
+ false,
212
+ false
213
+ ],
214
+ "node_type": "0"
215
+ },
216
+ {
217
+ "rows": [
218
+ ["0", "0", "0", "0"],
219
+ ["0", "0", "0", "0"],
220
+ ["0", "0", "0", "0"],
221
+ ["0", "0", "0", "0"],
222
+ ["0", "0", "0", "0"],
223
+ ["0", "0", "0", "0"],
224
+ ["0", "0", "0", "0"],
225
+ ["0", "0", "0", "0"],
226
+ ["0", "0", "0", "0"],
227
+ ["0", "0", "0", "0"],
228
+ ["0", "0", "0", "0"],
229
+ ["0", "0", "0", "0"],
230
+ ["0", "0", "0", "0"],
231
+ ["0", "0", "0", "0"],
232
+ ["0", "0", "0", "0"],
233
+ ["0", "0", "0", "0"]
234
+ ],
235
+ "row_exist": [
236
+ false,
237
+ false,
238
+ false,
239
+ false,
240
+ false,
241
+ false,
242
+ false,
243
+ false,
244
+ false,
245
+ false,
246
+ false,
247
+ false,
248
+ false,
249
+ false,
250
+ false,
251
+ false
252
+ ],
253
+ "node_type": "0"
254
+ },
255
+ {
256
+ "rows": [
257
+ ["0", "0", "0", "0"],
258
+ ["0", "0", "0", "0"],
259
+ ["0", "0", "0", "0"],
260
+ ["0", "0", "0", "0"],
261
+ ["0", "0", "0", "0"],
262
+ ["0", "0", "0", "0"],
263
+ ["0", "0", "0", "0"],
264
+ ["0", "0", "0", "0"],
265
+ ["0", "0", "0", "0"],
266
+ ["0", "0", "0", "0"],
267
+ ["0", "0", "0", "0"],
268
+ ["0", "0", "0", "0"],
269
+ ["0", "0", "0", "0"],
270
+ ["0", "0", "0", "0"],
271
+ ["0", "0", "0", "0"],
272
+ ["0", "0", "0", "0"]
273
+ ],
274
+ "row_exist": [
275
+ false,
276
+ false,
277
+ false,
278
+ false,
279
+ false,
280
+ false,
281
+ false,
282
+ false,
283
+ false,
284
+ false,
285
+ false,
286
+ false,
287
+ false,
288
+ false,
289
+ false,
290
+ false
291
+ ],
292
+ "node_type": "0"
293
+ },
294
+ {
295
+ "rows": [
296
+ ["0", "0", "0", "0"],
297
+ ["0", "0", "0", "0"],
298
+ ["0", "0", "0", "0"],
299
+ ["0", "0", "0", "0"],
300
+ ["0", "0", "0", "0"],
301
+ ["0", "0", "0", "0"],
302
+ ["0", "0", "0", "0"],
303
+ ["0", "0", "0", "0"],
304
+ ["0", "0", "0", "0"],
305
+ ["0", "0", "0", "0"],
306
+ ["0", "0", "0", "0"],
307
+ ["0", "0", "0", "0"],
308
+ ["0", "0", "0", "0"],
309
+ ["0", "0", "0", "0"],
310
+ ["0", "0", "0", "0"],
311
+ ["0", "0", "0", "0"]
312
+ ],
313
+ "row_exist": [
314
+ false,
315
+ false,
316
+ false,
317
+ false,
318
+ false,
319
+ false,
320
+ false,
321
+ false,
322
+ false,
323
+ false,
324
+ false,
325
+ false,
326
+ false,
327
+ false,
328
+ false,
329
+ false
330
+ ],
331
+ "node_type": "0"
332
+ },
333
+ {
334
+ "rows": [
335
+ ["0", "0", "0", "0"],
336
+ ["0", "0", "0", "0"],
337
+ ["0", "0", "0", "0"],
338
+ ["0", "0", "0", "0"],
339
+ ["0", "0", "0", "0"],
340
+ ["0", "0", "0", "0"],
341
+ ["0", "0", "0", "0"],
342
+ ["0", "0", "0", "0"],
343
+ ["0", "0", "0", "0"],
344
+ ["0", "0", "0", "0"],
345
+ ["0", "0", "0", "0"],
346
+ ["0", "0", "0", "0"],
347
+ ["0", "0", "0", "0"],
348
+ ["0", "0", "0", "0"],
349
+ ["0", "0", "0", "0"],
350
+ ["0", "0", "0", "0"]
351
+ ],
352
+ "row_exist": [
353
+ false,
354
+ false,
355
+ false,
356
+ false,
357
+ false,
358
+ false,
359
+ false,
360
+ false,
361
+ false,
362
+ false,
363
+ false,
364
+ false,
365
+ false,
366
+ false,
367
+ false,
368
+ false
369
+ ],
370
+ "node_type": "0"
371
+ },
372
+ {
373
+ "rows": [
374
+ ["0", "0", "0", "0"],
375
+ ["0", "0", "0", "0"],
376
+ ["0", "0", "0", "0"],
377
+ ["0", "0", "0", "0"],
378
+ ["0", "0", "0", "0"],
379
+ ["0", "0", "0", "0"],
380
+ ["0", "0", "0", "0"],
381
+ ["0", "0", "0", "0"],
382
+ ["0", "0", "0", "0"],
383
+ ["0", "0", "0", "0"],
384
+ ["0", "0", "0", "0"],
385
+ ["0", "0", "0", "0"],
386
+ ["0", "0", "0", "0"],
387
+ ["0", "0", "0", "0"],
388
+ ["0", "0", "0", "0"],
389
+ ["0", "0", "0", "0"]
390
+ ],
391
+ "row_exist": [
392
+ false,
393
+ false,
394
+ false,
395
+ false,
396
+ false,
397
+ false,
398
+ false,
399
+ false,
400
+ false,
401
+ false,
402
+ false,
403
+ false,
404
+ false,
405
+ false,
406
+ false,
407
+ false
408
+ ],
409
+ "node_type": "0"
410
+ },
411
+ {
412
+ "rows": [
413
+ ["0", "0", "0", "0"],
414
+ ["0", "0", "0", "0"],
415
+ ["0", "0", "0", "0"],
416
+ ["0", "0", "0", "0"],
417
+ ["0", "0", "0", "0"],
418
+ ["0", "0", "0", "0"],
419
+ ["0", "0", "0", "0"],
420
+ ["0", "0", "0", "0"],
421
+ ["0", "0", "0", "0"],
422
+ ["0", "0", "0", "0"],
423
+ ["0", "0", "0", "0"],
424
+ ["0", "0", "0", "0"],
425
+ ["0", "0", "0", "0"],
426
+ ["0", "0", "0", "0"],
427
+ ["0", "0", "0", "0"],
428
+ ["0", "0", "0", "0"]
429
+ ],
430
+ "row_exist": [
431
+ false,
432
+ false,
433
+ false,
434
+ false,
435
+ false,
436
+ false,
437
+ false,
438
+ false,
439
+ false,
440
+ false,
441
+ false,
442
+ false,
443
+ false,
444
+ false,
445
+ false,
446
+ false
447
+ ],
448
+ "node_type": "0"
449
+ },
450
+ {
451
+ "rows": [
452
+ ["0", "0", "0", "0"],
453
+ ["0", "0", "0", "0"],
454
+ ["0", "0", "0", "0"],
455
+ ["0", "0", "0", "0"],
456
+ ["0", "0", "0", "0"],
457
+ ["0", "0", "0", "0"],
458
+ ["0", "0", "0", "0"],
459
+ ["0", "0", "0", "0"],
460
+ ["0", "0", "0", "0"],
461
+ ["0", "0", "0", "0"],
462
+ ["0", "0", "0", "0"],
463
+ ["0", "0", "0", "0"],
464
+ ["0", "0", "0", "0"],
465
+ ["0", "0", "0", "0"],
466
+ ["0", "0", "0", "0"],
467
+ ["0", "0", "0", "0"]
468
+ ],
469
+ "row_exist": [
470
+ false,
471
+ false,
472
+ false,
473
+ false,
474
+ false,
475
+ false,
476
+ false,
477
+ false,
478
+ false,
479
+ false,
480
+ false,
481
+ false,
482
+ false,
483
+ false,
484
+ false,
485
+ false
486
+ ],
487
+ "node_type": "0"
488
+ }
489
+ ],
490
+ "account": {
491
+ "address": [
492
+ "216",
493
+ "218",
494
+ "107",
495
+ "242",
496
+ "105",
497
+ "100",
498
+ "175",
499
+ "157",
500
+ "126",
501
+ "237",
502
+ "158",
503
+ "3",
504
+ "229",
505
+ "52",
506
+ "21",
507
+ "211",
508
+ "122",
509
+ "169",
510
+ "96",
511
+ "69"
512
+ ],
513
+ "balance": [
514
+ "1",
515
+ "189",
516
+ "179",
517
+ "116",
518
+ "6",
519
+ "27",
520
+ "3",
521
+ "254",
522
+ "10",
523
+ "0",
524
+ "0",
525
+ "0",
526
+ "0",
527
+ "0",
528
+ "0",
529
+ "0",
530
+ "0",
531
+ "0",
532
+ "0",
533
+ "0",
534
+ "0",
535
+ "0",
536
+ "0",
537
+ "0",
538
+ "0",
539
+ "0",
540
+ "0",
541
+ "0",
542
+ "0",
543
+ "0",
544
+ "0",
545
+ "0"
546
+ ],
547
+ "balance_length": "9",
548
+ "code_hash": ["926127867056156632", "11210311266776869355", "13126016491190329403", "7864128633858226886"],
549
+ "nonce": ["6", "108", "0", "0", "0", "0", "0", "0"],
550
+ "nonce_length": "2",
551
+ "storage_hash": ["11985710400040593494", "7996352875557389311", "13883872631106586715", "2428675928708047361"]
552
+ }
553
+ }
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Fetches an account proof from the Ethereum mainnet and saves it as account_proof.json.
3
+ * This script is not using any Aztec library code, so it's easily portable.
4
+ */
5
+ import fs from 'fs';
6
+ import { dirname, join } from 'path';
7
+ import { fileURLToPath } from 'url';
8
+ import { createPublicClient, fromRlp, hexToBytes, http } from 'viem';
9
+ import { mainnet } from 'viem/chains';
10
+
11
+ const __dirname = dirname(fileURLToPath(import.meta.url));
12
+
13
+ const RPC_URL = process.env.RPC_URL;
14
+ const ADDRESS = (process.env.ADDRESS || '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') as `0x${string}`;
15
+ const BLOCK_TAG = process.env.BLOCK_NUMBER ? BigInt(process.env.BLOCK_NUMBER) : 'latest';
16
+ const MAX_ACCOUNT_PATH = 15;
17
+
18
+ function padTo(arr: number[], len: number) {
19
+ return [...arr, ...Array(len - arr.length).fill(0)].slice(0, len);
20
+ }
21
+
22
+ function toBytes(hex: `0x${string}`) {
23
+ return Array.from(hexToBytes(hex));
24
+ }
25
+
26
+ function bytesToU64s(bytes: number[]) {
27
+ const paddedBytes = padTo(bytes, 32);
28
+ return Array.from({ length: 4 }, (_, i) => {
29
+ let val = 0n;
30
+ for (let j = 0; j < 8; j++) {
31
+ val += BigInt(paddedBytes[i * 8 + j]) << BigInt(j * 8);
32
+ }
33
+ return val.toString();
34
+ });
35
+ }
36
+
37
+ function toBytesAndLen(val: bigint | number) {
38
+ if (val === 0n || val === 0) {
39
+ return { bytes: [0], length: 0 };
40
+ }
41
+ let hex = val.toString(16);
42
+ if (hex.length % 2) {
43
+ hex = '0' + hex;
44
+ }
45
+ const bytes = toBytes(`0x${hex}`);
46
+ return { bytes, length: bytes.length };
47
+ }
48
+
49
+ function parseNode(rlp: `0x${string}`) {
50
+ // Should be safe when working with branches and extensions without embedded children.
51
+ const decoded = fromRlp(rlp) as `0x${string}`[];
52
+ const node = {
53
+ rows: Array(16)
54
+ .fill(0)
55
+ .map(() => Array(32).fill(0)),
56
+ row_exist: Array(16).fill(false),
57
+ node_type: 0,
58
+ };
59
+
60
+ if (decoded.length === 17) {
61
+ for (let i = 0; i < 16; i++) {
62
+ if (decoded[i] !== '0x') {
63
+ node.row_exist[i] = true;
64
+ node.rows[i] = padTo(toBytes(decoded[i]), 32);
65
+ }
66
+ }
67
+ } else if (decoded.length === 2) {
68
+ const keyBytes = toBytes(decoded[0]);
69
+ const prefix = keyBytes[0];
70
+ if (prefix >> 4 >= 2) {
71
+ throw new Error('Unsupported: leaf node in proof path');
72
+ }
73
+ node.node_type = 1;
74
+ // Extension header format expected by the noir code: check out storage_proof types.nr.
75
+ node.rows[0][0] = prefix >> 4;
76
+ node.rows[0][8] = prefix & 0x0f;
77
+ node.rows[0][16] = keyBytes.length - 1;
78
+
79
+ for (let i = 1; i < keyBytes.length && i < 32; i++) {
80
+ node.rows[1][i - 1] = keyBytes[i];
81
+ }
82
+ node.rows[2] = padTo(toBytes(decoded[1]), 32);
83
+ node.row_exist[0] = node.row_exist[1] = node.row_exist[2] = true;
84
+ }
85
+ return node;
86
+ }
87
+
88
+ function parseProof(proof: `0x${string}`[], maxLen: number) {
89
+ const nodes = proof.slice(0, -1).slice(0, maxLen).map(parseNode);
90
+ while (nodes.length < maxLen) {
91
+ nodes.push({
92
+ rows: Array(16)
93
+ .fill(0)
94
+ .map(() => Array(32).fill(0)),
95
+ row_exist: Array(16).fill(false),
96
+ node_type: 0,
97
+ });
98
+ }
99
+ return nodes;
100
+ }
101
+
102
+ function nodeToLibFormat(node: { rows: number[][]; row_exist: boolean[]; node_type: number }) {
103
+ return {
104
+ rows: node.rows.map(bytesToU64s),
105
+ row_exist: node.row_exist,
106
+ node_type: String(node.node_type),
107
+ };
108
+ }
109
+
110
+ async function main() {
111
+ if (!RPC_URL) {
112
+ throw new Error('RPC_URL is not set');
113
+ }
114
+ console.log(`Fetching account proof for ${ADDRESS}`);
115
+
116
+ const client = createPublicClient({
117
+ chain: mainnet,
118
+ transport: http(RPC_URL),
119
+ });
120
+
121
+ const [blockNumber, proof, block] = await Promise.all([
122
+ client.getBlockNumber(),
123
+ client.getProof({
124
+ address: ADDRESS,
125
+ storageKeys: [],
126
+ blockNumber: BLOCK_TAG === 'latest' ? undefined : BLOCK_TAG,
127
+ }),
128
+ client.getBlock({
129
+ blockNumber: BLOCK_TAG === 'latest' ? undefined : BLOCK_TAG,
130
+ }),
131
+ ]);
132
+
133
+ console.log(`Block: ${blockNumber}, Account nodes: ${proof.accountProof.length}`);
134
+
135
+ // The -1 is because the last node in the proof is the leaf, which is excluded from path verification.
136
+ const accountPathLen = proof.accountProof.length - 1;
137
+ if (accountPathLen > MAX_ACCOUNT_PATH) {
138
+ throw new Error(
139
+ `Account proof path length ${accountPathLen} exceeds MAX_ACCOUNT_PATH ${MAX_ACCOUNT_PATH}. Increase the limit.`,
140
+ );
141
+ }
142
+
143
+ const nonce = toBytesAndLen(proof.nonce);
144
+ const balance = toBytesAndLen(proof.balance);
145
+
146
+ const data = {
147
+ block_number: String(blockNumber),
148
+ node_length: String(accountPathLen),
149
+ root: bytesToU64s(toBytes(block.stateRoot)),
150
+ nodes: parseProof(proof.accountProof, MAX_ACCOUNT_PATH).map(nodeToLibFormat),
151
+ account: {
152
+ address: toBytes(ADDRESS).map(String),
153
+ balance: padTo(balance.bytes, 32).map(String),
154
+ balance_length: String(balance.length),
155
+ code_hash: bytesToU64s(toBytes(proof.codeHash)),
156
+ nonce: padTo(nonce.bytes, 8).map(String),
157
+ nonce_length: String(nonce.length),
158
+ storage_hash: bytesToU64s(toBytes(proof.storageHash)),
159
+ },
160
+ };
161
+
162
+ fs.writeFileSync(join(__dirname, 'account_proof.json'), JSON.stringify(data, null, 2));
163
+ console.log('account_proof.json generated');
164
+ }
165
+
166
+ main().catch(console.error);