Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Scroll integration #42

Merged
merged 129 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
0971ed6
Make testResolver work
makoto Oct 20, 2023
383f29a
Update bun.lockb
makoto Oct 20, 2023
88dc259
Add coinType
makoto Oct 23, 2023
8a58674
Make text record work
makoto Oct 23, 2023
8cb5256
Add hardhat-storage-layout
makoto Oct 23, 2023
641e15b
Use the real Resolver contracts
makoto Oct 23, 2023
914c66e
Add contenthash
makoto Oct 23, 2023
9a1a74d
Add comment
makoto Oct 23, 2023
9a386ea
Update README
makoto Oct 23, 2023
db89d14
Change the license to ENS labs
makoto Oct 23, 2023
805b218
Remove console.log
makoto Oct 23, 2023
757d787
Add an explanation
makoto Oct 23, 2023
93ef4b7
typo
makoto Oct 23, 2023
b3141e5
Remove L1Verifier.sol
makoto Oct 23, 2023
80292c4
Remove L1Verifier.sol
makoto Oct 23, 2023
0a227de
Rename test
makoto Oct 23, 2023
7f086ce
Add hardhat-deploy
makoto Oct 23, 2023
749ccd0
Add deployment script
makoto Oct 23, 2023
6c9f241
Remove deployment addresses
makoto Oct 23, 2023
4871812
Merge branch 'crosschain-resolver' into crosschain-resolver-deployment
makoto Oct 23, 2023
50d48b6
Apply suggestions from code review
makoto Oct 25, 2023
84dd082
Add immutable and constants
makoto Oct 25, 2023
40be600
Remove getStatic
makoto Oct 25, 2023
415392b
Fix the wrong constants
makoto Oct 25, 2023
7987695
Merge branch 'main' into crosschain-resolver
makoto Oct 25, 2023
507bfb4
Update bun.lockb
makoto Oct 25, 2023
0ee53c8
Remove contracts-bedrock
makoto Oct 25, 2023
574297d
Update bun.lockb
makoto Oct 25, 2023
3e49356
Add bun
makoto Oct 25, 2023
98adc6e
Remove package-lock.json
makoto Oct 26, 2023
a4044bd
update bun.lockb
TateB Oct 26, 2023
780b416
Merge branch 'revert-test-script' into crosschain-resolver
makoto Oct 27, 2023
9ffd059
Use BrowserProvider
makoto Oct 27, 2023
73f286f
Revert to use fork
makoto Oct 27, 2023
c713107
Put immutable and constant together
makoto Oct 27, 2023
fc128af
Use bytes20 instead
makoto Oct 27, 2023
f013347
Apply suggestions from code review
makoto Oct 27, 2023
f9a056e
Remove gasLimit and gas
makoto Oct 27, 2023
8974854
Merge branch 'crosschain-resolver' of https://github.com/ensdomains/e…
makoto Oct 27, 2023
d84a766
Add test for the empty record
makoto Oct 27, 2023
e0ea493
Remove remote
makoto Oct 27, 2023
e20e6c3
Remove RECORD_VERSIONS_REF constant
makoto Oct 30, 2023
74bb4cc
Copy crosschain resolver to crosschain reverse resolver
makoto Oct 30, 2023
b8c56d0
Rename the function name
makoto Oct 30, 2023
553696e
Add crosschain reverse registrar
makoto Oct 30, 2023
4443f88
Update README.md
makoto Oct 30, 2023
541d5f5
Replace OwnedResolver with DelegatableResolverFactory
makoto Nov 1, 2023
3a50148
replace target with targets
makoto Nov 2, 2023
2fd26ac
Add isAuthorised
makoto Nov 2, 2023
3e83644
Add test for setTarget
makoto Nov 2, 2023
59a5424
Modify deployment code
makoto Nov 2, 2023
4859c62
Remove getTarget and add TargetSet event
makoto Nov 2, 2023
8a00bae
WIP: Adding NameWrapper into test
makoto Nov 2, 2023
c1490e1
Use L2ReverseRegistrar
makoto Nov 6, 2023
912d1e8
Revert L1Resolver.sol and update L1ReverseResolver.sol storage slot l…
makoto Nov 6, 2023
b635152
Update storage slot info
makoto Nov 6, 2023
131c836
Enable ccip read on name
makoto Nov 6, 2023
377e2f4
Add clearRecords and fixed typo
makoto Nov 6, 2023
0cd293c
Fix failing test temporarily
makoto Nov 6, 2023
9d8a668
Resolve conflicts
makoto Nov 6, 2023
77c04ea
Update ens-contracts
makoto Nov 6, 2023
b48c4ef
Merge branch 'bug/zeroref' into feature/crosschain-resolver-with-reve…
makoto Nov 7, 2023
35b91ee
Resolve conflicts
makoto Nov 10, 2023
7fad46a
Update bun
makoto Nov 10, 2023
5ef2612
Resolve conflicts
makoto Nov 10, 2023
4de68ed
Resolve conflicts
makoto Nov 10, 2023
8240df8
Commit bun
makoto Nov 10, 2023
6e725f6
Update ens-contracts on crosschain-reverse-resolver
makoto Nov 10, 2023
e142a7b
Recreate bun.lockb
makoto Nov 10, 2023
c52f671
Crosschain resolver with reverse registrar with deploy script (#18)
makoto Nov 27, 2023
9be5192
Add support interface (#21)
makoto Nov 30, 2023
d173654
Add metadata (#22)
makoto Dec 6, 2023
acabddc
Resolve conflicts and update bun
makoto Dec 10, 2023
3027453
Arb deployment (#23)
makoto Dec 20, 2023
587de25
Add Sepolia verifier contracts and gateway deployment details (#26)
makoto Jan 4, 2024
b868b70
Add .wrangler to gitignore
makoto Jan 25, 2024
676b174
Copy arb-gateway to scroll-gateway
makoto Mar 6, 2024
9264a21
Replace arb to scroll
makoto Mar 6, 2024
a55c9da
Rename from arb to scroll
makoto Mar 6, 2024
b55f3d0
replace arb to scroll
makoto Mar 6, 2024
806d311
Rename from Arb to Scroll
makoto Mar 11, 2024
0c3ea5f
Modify ScrollProofService
makoto Mar 11, 2024
96c0f9a
Add scroll- to workspace
makoto Mar 11, 2024
db05839
Update rollupABI
makoto Mar 11, 2024
2af9e7b
Sepolia resolvers (#27)
makoto Apr 11, 2024
c80e72c
Remove crosschain-resolver and crosschain-reverse-resolver
makoto Apr 11, 2024
eed343e
Add .yalc to .gitignore
makoto Apr 16, 2024
bea378d
v0.1.0-beta.1
makoto Apr 16, 2024
9839dfb
Pushed all versions to 0.1.0-beta.2
makoto Apr 17, 2024
c99bb0e
Add repo info and bump to beta.3
makoto Apr 17, 2024
719b9b3
Add links to arb related repos
makoto Apr 18, 2024
21737ef
Remove old deployment info
makoto Apr 18, 2024
0cd2987
Revert removed scripts
makoto Apr 18, 2024
3c4ae2d
Recreate bun.lockb
makoto Apr 18, 2024
e83be49
Remove console.log and tidy up props
makoto Apr 19, 2024
3e94f8f
Merge branch 'main' into npm
makoto Apr 19, 2024
519b9eb
Merge branch 'npm' into scroll
makoto Apr 22, 2024
fa4baf7
Update package
makoto Apr 22, 2024
73d8851
Fix worker error
makoto Apr 22, 2024
1b14bb0
Rename to makeScrollGateway
makoto Apr 24, 2024
109e06c
Make simple proofs for fixed values test pass
makoto Apr 24, 2024
7cc1d4b
Fix linting error
makoto Apr 24, 2024
68c3dc4
Fix linting error
makoto Apr 24, 2024
b398a6a
remove log result util (#40)
mdtanrikulu Apr 25, 2024
cf75a9f
Pass multiple storage slots
makoto Apr 26, 2024
708d115
Rename sepoliaforbase to sepoliaForBase
makoto Apr 26, 2024
0eba5cf
Update op-gateway/README.md
makoto Apr 26, 2024
a461c2c
Add EVMProofHelper2
makoto Apr 26, 2024
b80d664
move propsDecoder (#41)
makoto Apr 26, 2024
1592925
Merge branch 'npm' into scroll
makoto Apr 26, 2024
ea52ed7
Merge branch 'main' into scroll
makoto Apr 26, 2024
fa73e0e
Add compressProof
makoto Apr 29, 2024
372ec98
Make scroll verifier working
makoto May 6, 2024
e423972
Add estimateCCIPReadCallbackGas
makoto May 6, 2024
7984b3b
Pass compressedProof as storageProof
makoto May 7, 2024
cf18c96
Create MerkleTrieProofHelper
makoto May 7, 2024
5f7a8ef
Remove nested array from StateProof.storageProofs
makoto May 8, 2024
cf4554a
Simplify log tracker on scroll gateway worker
makoto May 8, 2024
318771d
Remove wrong comment
makoto May 8, 2024
374d64c
Update comment and documentation
makoto May 8, 2024
7fbb0b4
Remove unused cache from scroll-gateway
makoto May 8, 2024
1a62678
Remove L2_ROLLUP and L1_PROVIDER_URL
makoto May 8, 2024
e1a3e64
Fix linting error
makoto May 8, 2024
c36fad7
Update evm-gateway/src/utils.ts
makoto May 20, 2024
ce40028
Update evm-verifier/contracts/MerkleTrieProofHelper.sol
makoto May 20, 2024
05a2788
Fix error
makoto May 20, 2024
21709e4
Add SEARCH_URL
makoto May 20, 2024
d7ca0ad
Add StateRootMismatch error
makoto May 20, 2024
79fad1a
Change l2 rollup address
makoto May 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions arb-gateway/src/ArbProofService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable prettier/prettier */
import { EVMProofHelper, type IProofService } from '@ensdomains/evm-gateway';
import { EVMProofHelper, convertIntoMerkleTrieProof, type IProofService } from '@ensdomains/evm-gateway';
import { AbiCoder, Contract, EventLog, ethers, toBeHex, type AddressLike, toNumber } from 'ethers';
import rollupAbi from "./abi/rollupABI.js";
import type { IBlockCache } from './blockCache/IBlockCache.js';
Expand Down Expand Up @@ -63,7 +63,7 @@ export class ArbProofService implements IProofService<ArbProvableBlock> {
return AbiCoder.defaultAbiCoder().encode(
[
'tuple(bytes32 version, bytes32 sendRoot, uint64 nodeIndex,bytes rlpEncodedBlock)',
'tuple(bytes[] stateTrieWitness, bytes[][] storageProofs)',
'tuple(bytes stateTrieWitness, bytes[] storageProofs)',
],
[
{
Expand All @@ -73,7 +73,7 @@ export class ArbProofService implements IProofService<ArbProvableBlock> {
nodeIndex: block.nodeIndex,
rlpEncodedBlock: block.rlpEncodedBlock
},
proof,
convertIntoMerkleTrieProof(proof)
]
);
}
Expand Down
2 changes: 1 addition & 1 deletion arb-gateway/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function fetch(request: CFWRequest, env: Env) {
await tracker.trackEvent(request, 'request', { props }, true);
return app
.handle(request)
.then(tracker.logResult.bind(null, propsDecoder, request));
.then(tracker.logResult.bind(tracker, propsDecoder, request));
}

export default {
Expand Down
11 changes: 3 additions & 8 deletions arb-verifier/contracts/ArbVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {StateProof, EVMProofHelper} from '@ensdomains/evm-verifier/contracts/EVM
import {IEVMVerifier} from '@ensdomains/evm-verifier/contracts/IEVMVerifier.sol';
import {Node, IRollupCore} from '@arbitrum/nitro-contracts/src/rollup/IRollupCore.sol';
import {RLPReader} from '@eth-optimism/contracts-bedrock/src/libraries/rlp/RLPReader.sol';
import {MerkleTrieProofHelper} from '@ensdomains/evm-verifier/contracts/MerkleTrieProofHelper.sol';

struct ArbWitnessData {
bytes32 version;
Expand Down Expand Up @@ -63,14 +64,8 @@ contract ArbVerifier is IEVMVerifier {

//Now that we know that the block is valid, we can get the state root from the block.
bytes32 stateRoot = getStateRootFromBlock(arbData.rlpEncodedBlock);

values = EVMProofHelper.getStorageValues(
target,
commands,
constants,
stateRoot,
stateProof
);
bytes32 storageRoot = MerkleTrieProofHelper.getStorageRoot(stateRoot, target, stateProof.stateTrieWitness);
return EVMProofHelper.getStorageValues(target, MerkleTrieProofHelper.getTrieProof, commands, constants, storageRoot, stateProof.storageProofs);
}

/*
Expand Down
51 changes: 51 additions & 0 deletions arb-verifier/test/testArbVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/
import type { HardhatEthersHelpers } from '@nomicfoundation/hardhat-ethers/types';
import { expect } from 'chai';
import {
AbiCoder,
concat,
Contract,
FetchRequest,
Provider,
Expand All @@ -28,6 +30,23 @@ declare module 'hardhat/types/runtime' {
ethers: ethersObj;
}
}
const estimateCCIPReadCallbackGas = async (provider, cb) => {
try{
await cb()
}catch(e){
const [sender, urls, data, callbackFunction, extraData ] = e.revert.args
const url = `http://localhost:8080/${sender}/${data}.json`
const responseData:any = await (await fetch(url)).json()
const encoder = new AbiCoder()
const encoded = encoder.encode([ "bytes", "bytes" ], [responseData.data, extraData]);
const newdata = concat([ callbackFunction, encoded ])
const result2 = await provider.estimateGas({
to: sender,
data:newdata
});
console.log(`Gas estimate ${result2}`)
}
}

describe('ArbVerifier', () => {
let provider: Provider;
Expand Down Expand Up @@ -87,54 +106,86 @@ describe('ArbVerifier', () => {
it('simple proofs for fixed values', async () => {
const result = await target.getLatest({ enableCcipRead: true });
expect(Number(result)).to.equal(42);
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getLatest({ enableCcipRead: false });
})
});

it('simple proofs for dynamic values', async () => {
const result = await target.getName({ enableCcipRead: true });
expect(result).to.equal('Satoshi');
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getName({ enableCcipRead: false });
})
});

it('nested proofs for dynamic values', async () => {
const result = await target.getHighscorer(42, { enableCcipRead: true });
expect(result).to.equal('Hal Finney');
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getHighscorer(42, { enableCcipRead: false });
})
});

it('nested proofs for long dynamic values', async () => {
const result = await target.getHighscorer(1, { enableCcipRead: true });
expect(result).to.equal(
'Hubert Blaine Wolfeschlegelsteinhausenbergerdorff Sr.'
);
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getHighscorer(1, { enableCcipRead: false });
})
});

it('nested proofs with lookbehind', async () => {
const result = await target.getLatestHighscore({ enableCcipRead: true });
expect(Number(result)).to.equal(12345);
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getLatestHighscore({ enableCcipRead: false });
})
});

it('nested proofs with lookbehind for dynamic values', async () => {
const result = await target.getLatestHighscorer({ enableCcipRead: true });
expect(result).to.equal('Hal Finney');
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getLatestHighscorer({ enableCcipRead: false });
})
});

it('mappings with variable-length keys', async () => {
const result = await target.getNickname('Money Skeleton', {
enableCcipRead: true,
});
expect(result).to.equal('Vitalik Buterin');
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getNickname('Money Skeleton', {
enableCcipRead: false,
});
})
});

it('nested proofs of mappings with variable-length keys', async () => {
const result = await target.getPrimaryNickname({ enableCcipRead: true });
expect(result).to.equal('Hal Finney');
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getPrimaryNickname({ enableCcipRead: false });
})
});

it('treats uninitialized storage elements as zeroes', async () => {
const result = await target.getZero({ enableCcipRead: true });
expect(Number(result)).to.equal(0);
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getZero({ enableCcipRead: false });
})
});

it('treats uninitialized dynamic values as empty strings', async () => {
const result = await target.getNickname('Santa', { enableCcipRead: true });
expect(result).to.equal("");
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getNickname('Santa', { enableCcipRead: false });
})
})
});
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion evm-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@
"type": "module",
"types": "./_types/index.d.ts",
"typings": "./_types/index.d.ts"
}
}
8 changes: 4 additions & 4 deletions evm-gateway/src/EVMProofHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { toBeHex, type AddressLike, type JsonRpcProvider } from 'ethers';
* Response of the eth_getProof RPC method.
*/
interface EthGetProofResponse {
accountProof: string[];
accountProof: string;
balance: string;
codeHash: string;
nonce: string;
storageHash: string;
storageProof: {
key: string;
value: string;
proof: string[];
proof: string;
}[];
}

export interface StateProof {
stateTrieWitness: string[];
storageProofs: string[][];
stateTrieWitness: string;
storageProofs: string[];
stateRoot: string;
}

Expand Down
6 changes: 5 additions & 1 deletion evm-gateway/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export { EVMGateway, StorageLayout } from './EVMGateway.js';
export { EVMProofHelper, type StateProof } from './EVMProofHelper.js';
export type { IProofService, ProvableBlock } from './IProofService.js';
export { propsDecoder, type Router } from './utils.js';
export {
propsDecoder,
convertIntoMerkleTrieProof,
type Router,
} from './utils.js';
13 changes: 13 additions & 0 deletions evm-gateway/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { type Request as CFWRequest } from '@cloudflare/workers-types';
import { type PropsDecoder } from '@ensdomains/server-analytics';
import { AbiCoder } from 'ethers';
import { type StateProof } from './EVMProofHelper.js';
export interface Router {
handle: (request: CFWRequest) => Promise<Response>;
}
Expand All @@ -22,3 +24,14 @@ export const propsDecoder: PropsDecoder<CFWRequest> = (
return {};
}
};

const flatten = (data: string) => {
return AbiCoder.defaultAbiCoder().encode(['bytes[]'], [data]);
};

export const convertIntoMerkleTrieProof = (proof: StateProof) => {
return {
stateTrieWitness: flatten(proof.stateTrieWitness),
storageProofs: proof.storageProofs.map(flatten),
};
};
78 changes: 36 additions & 42 deletions evm-verifier/contracts/EVMProofHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {Bytes} from "@eth-optimism/contracts-bedrock/src/libraries/Bytes.sol";
import {SecureMerkleTrie} from "./SecureMerkleTrie.sol";

struct StateProof {
bytes[] stateTrieWitness; // Witness proving the `storageRoot` against a state root.
bytes[][] storageProofs; // An array of proofs of individual storage elements
bytes stateTrieWitness; // Witness proving the `storageRoot` against a state root.
bytes[] storageProofs; // An array of proofs of individual storage elements
}

uint8 constant OP_CONSTANT = 0x00;
Expand All @@ -17,52 +17,39 @@ uint8 constant FLAG_DYNAMIC = 0x01;
library EVMProofHelper {
using Bytes for bytes;

error AccountNotFound(address);
error UnknownOpcode(uint8);
error InvalidSlotSize(uint256 size);

/**
* @notice Get the storage root for the provided merkle proof
* @param stateRoot The state root the witness was generated against
* @param target The address we are fetching a storage root for
* @param witness A witness proving the value of the storage root for `target`.
* @return The storage root retrieved from the provided state root
*/
function getStorageRoot(bytes32 stateRoot, address target, bytes[] memory witness) private pure returns (bytes32) {
(bool exists, bytes memory encodedResolverAccount) = SecureMerkleTrie.get(
abi.encodePacked(target),
witness,
stateRoot
);
if(!exists) {
revert AccountNotFound(target);
}
RLPReader.RLPItem[] memory accountState = RLPReader.readList(encodedResolverAccount);
return bytes32(RLPReader.readBytes(accountState[2]));
}

/**
* @notice Prove whether the provided storage slot is part of the storageRoot
* @param target address to verify against
* @param getter function to verify the storage proof
* @param storageRoot the storage root for the account that contains the storage slot
* @param slot The storage key we are fetching the value of
* @param witness the StorageProof struct containing the necessary proof data
* @return The retrieved storage proof value or 0x if the storage slot is empty
*/
function getSingleStorageProof(bytes32 storageRoot, uint256 slot, bytes[] memory witness) private pure returns (bytes memory) {
(bool exists, bytes memory retrievedValue) = SecureMerkleTrie.get(
abi.encodePacked(slot),
function getSingleStorageProof(
address target,
function(address,uint256,bytes memory, bytes32) internal view returns(bytes memory) getter,
bytes32 storageRoot,
uint256 slot,
bytes memory witness
) private view returns (bytes memory) {
return getter(
target,
slot,
witness,
storageRoot
);
if(!exists) {
// Nonexistent values are treated as zero.
return "";
}
return RLPReader.readBytes(retrievedValue);
}

function getFixedValue(bytes32 storageRoot, uint256 slot, bytes[] memory witness) private pure returns(bytes32) {
bytes memory value = getSingleStorageProof(storageRoot, slot, witness);
function getFixedValue(
address target,
function(address,uint256,bytes memory, bytes32) internal view returns(bytes memory) getter,
bytes32 storageRoot, uint256 slot, bytes memory witness
) private view returns(bytes32) {
bytes memory value = getSingleStorageProof(target, getter, storageRoot, slot, witness);
// RLP encoded storage slots are stored without leading 0 bytes.
// Casting to bytes32 appends trailing 0 bytes, so we have to bit shift to get the
// original fixed-length representation back.
Expand All @@ -82,7 +69,7 @@ library EVMProofHelper {
}
}

function computeFirstSlot(bytes32 command, bytes[] memory constants, bytes[] memory values) private pure returns(bool isDynamic, uint256 slot) {
function computeFirstSlot(bytes32 command, bytes[] memory constants, bytes[] memory values) internal pure returns(bool isDynamic, uint256 slot) {
uint8 flags = uint8(command[0]);
isDynamic = (flags & FLAG_DYNAMIC) != 0;

Expand All @@ -96,8 +83,12 @@ library EVMProofHelper {
}
}

function getDynamicValue(bytes32 storageRoot, uint256 slot, StateProof memory proof, uint256 proofIdx) private pure returns(bytes memory value, uint256 newProofIdx) {
uint256 firstValue = uint256(getFixedValue(storageRoot, slot, proof.storageProofs[proofIdx++]));
function getDynamicValue(
address target,
function(address,uint256,bytes memory, bytes32) internal view returns(bytes memory) getter,
bytes32 storageRoot, uint256 slot, bytes[] memory proof, uint256 proofIdx) private view returns(bytes memory value, uint256 newProofIdx
) {
uint256 firstValue = uint256(getFixedValue(target, getter,storageRoot, slot, proof[proofIdx++]));
if(firstValue & 0x01 == 0x01) {
// Long value: first slot is `length * 2 + 1`, following slots are data.
uint256 length = (firstValue - 1) / 2;
Expand All @@ -107,10 +98,10 @@ library EVMProofHelper {
// all at once, but we're trying to avoid writing new library code.
while(length > 0) {
if(length < 32) {
value = bytes.concat(value, getSingleStorageProof(storageRoot, slot++, proof.storageProofs[proofIdx++]).slice(0, length));
value = bytes.concat(value, getSingleStorageProof(target, getter, storageRoot, slot++, proof[proofIdx++]).slice(0, length));
length = 0;
} else {
value = bytes.concat(value, getSingleStorageProof(storageRoot, slot++, proof.storageProofs[proofIdx++]));
value = bytes.concat(value, getSingleStorageProof(target, getter, storageRoot, slot++, proof[proofIdx++]));
length -= 32;
}
}
Expand All @@ -122,20 +113,23 @@ library EVMProofHelper {
}
}

function getStorageValues(address target, bytes32[] memory commands, bytes[] memory constants, bytes32 stateRoot, StateProof memory proof) internal pure returns(bytes[] memory values) {
bytes32 storageRoot = getStorageRoot(stateRoot, target, proof.stateTrieWitness);
function getStorageValues(
address target,
function(address,uint256,bytes memory, bytes32) internal view returns(bytes memory) getter,
bytes32[] memory commands, bytes[] memory constants, bytes32 storageRoot, bytes[] memory proof) internal view returns(bytes[] memory values
) {
uint256 proofIdx = 0;
values = new bytes[](commands.length);
for(uint256 i = 0; i < commands.length; i++) {
bytes32 command = commands[i];
(bool isDynamic, uint256 slot) = computeFirstSlot(command, constants, values);
if(!isDynamic) {
values[i] = abi.encode(getFixedValue(storageRoot, slot, proof.storageProofs[proofIdx++]));
values[i] = abi.encode(getFixedValue(target, getter, storageRoot, slot, proof[proofIdx++]));
if(values[i].length > 32) {
revert InvalidSlotSize(values[i].length);
}
} else {
(values[i], proofIdx) = getDynamicValue(storageRoot, slot, proof, proofIdx);
(values[i], proofIdx) = getDynamicValue(target, getter, storageRoot, slot, proof, proofIdx);
}
}
}
Expand Down
Loading
Loading