prividium 0.18.1 → 0.19.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.
|
@@ -5,6 +5,32 @@ import { calculateStateMerkleRoot } from './verifiy-proofs.js';
|
|
|
5
5
|
export const DIAMOND_ABI = [
|
|
6
6
|
parseAbiItem('function storedBatchHash(uint256 _batchNumber) external view returns (bytes32)')
|
|
7
7
|
];
|
|
8
|
+
const tracerStr = `{
|
|
9
|
+
prevTop: null,
|
|
10
|
+
state: {
|
|
11
|
+
reads: {},success: null, value: null
|
|
12
|
+
},
|
|
13
|
+
step: function (log, _db) {
|
|
14
|
+
if (log.op.toString() === 'SLOAD') {
|
|
15
|
+
const addr = log.contract.getAddress();
|
|
16
|
+
const slot = this.prevTop;
|
|
17
|
+
if (!this.state.reads[addr]) this.state.reads[addr] = [];
|
|
18
|
+
if (this.state.reads[addr].indexOf(slot) === -1) this.state.reads[addr].push(slot);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (log.stack.length() > 0) {
|
|
22
|
+
this.prevTop = log.stack.peek(0).toString(16);
|
|
23
|
+
} else {
|
|
24
|
+
this.prevTop = null;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
fault: (_log, _db) => {},
|
|
28
|
+
result: function (ctx, _db) {
|
|
29
|
+
this.state.success = ctx.error === null;
|
|
30
|
+
this.state.value = ctx.output.toString('hex');
|
|
31
|
+
return this.state;
|
|
32
|
+
}
|
|
33
|
+
}`;
|
|
8
34
|
/**
|
|
9
35
|
* Verifies an ethCall disclosure response end-to-end.
|
|
10
36
|
*
|
|
@@ -60,31 +86,51 @@ export async function verifyEthCallDisclosure(disclosure, l1Client, l2Client, di
|
|
|
60
86
|
if (batchInfoHash !== storedBatchHash) {
|
|
61
87
|
return false;
|
|
62
88
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const stateOverride = disclosure.proofs.map((proof) => {
|
|
89
|
+
const contractAddress = disclosure.to;
|
|
90
|
+
const stateOverride = {};
|
|
91
|
+
for (const proof of disclosure.proofs) {
|
|
67
92
|
const address = proof.address.toLowerCase();
|
|
68
93
|
const code = contractBytecodes[address];
|
|
69
94
|
if (!code) {
|
|
70
95
|
throw new Error(`Missing bytecode for contract ${address}`);
|
|
71
96
|
}
|
|
72
|
-
|
|
73
|
-
|
|
97
|
+
const state = {};
|
|
98
|
+
for (const sp of proof.storageProofs) {
|
|
99
|
+
state[sp.key] = sp.proof.type === 'existing' ? sp.proof.value : pad('0x0');
|
|
100
|
+
}
|
|
101
|
+
stateOverride[address] = {
|
|
74
102
|
code,
|
|
75
|
-
state:
|
|
76
|
-
slot: sp.key,
|
|
77
|
-
value: sp.proof.type === 'existing' ? sp.proof.value : pad('0x0')
|
|
78
|
-
}))
|
|
103
|
+
state: state
|
|
79
104
|
};
|
|
105
|
+
}
|
|
106
|
+
const debugResult = await l2Client.request({
|
|
107
|
+
method: 'debug_traceCall',
|
|
108
|
+
params: [
|
|
109
|
+
{
|
|
110
|
+
from: disclosure.from,
|
|
111
|
+
to: contractAddress,
|
|
112
|
+
data: disclosure.callData
|
|
113
|
+
},
|
|
114
|
+
'latest',
|
|
115
|
+
{
|
|
116
|
+
tracer: tracerStr,
|
|
117
|
+
stateOverrides: stateOverride
|
|
118
|
+
}
|
|
119
|
+
]
|
|
80
120
|
});
|
|
81
|
-
|
|
82
|
-
to: contractAddress,
|
|
83
|
-
data: disclosure.callData,
|
|
84
|
-
stateOverride
|
|
85
|
-
});
|
|
86
|
-
if (!callResult.data) {
|
|
121
|
+
if (!debugResult.success) {
|
|
87
122
|
return false;
|
|
88
123
|
}
|
|
89
|
-
|
|
124
|
+
for (const address in debugResult.reads) {
|
|
125
|
+
for (const slot of debugResult.reads[address]) {
|
|
126
|
+
const realSlot = `0x${slot}`;
|
|
127
|
+
const exists = disclosure.proofs.find((p) => p.address.toLowerCase() === address.toLowerCase() &&
|
|
128
|
+
p.storageProofs.some((sp) => BigInt(sp.key) === BigInt(realSlot)));
|
|
129
|
+
if (!exists) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const callResult = debugResult.value;
|
|
135
|
+
return BigInt(callResult) === BigInt(disclosure.result);
|
|
90
136
|
}
|