-
-
Notifications
You must be signed in to change notification settings - Fork 478
Add support for eth_getTransactionCount to prover #5338
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import {Logger} from "@lodestar/utils"; | ||
| import {ELRequestHandler, ELVerifiedRequestHandler} from "../interfaces.js"; | ||
| import {ProofProvider} from "../proof_provider/proof_provider.js"; | ||
| import {ELRequestPayload, ELResponse} from "../types.js"; | ||
| import {eth_getBalance} from "../verified_requests/eth_getBalance.js"; | ||
| import {eth_getTransactionCount} from "../verified_requests/eth_getTransactionCount.js"; | ||
|
|
||
| /* eslint-disable @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any */ | ||
| export const supportedELRequests: Record<string, ELVerifiedRequestHandler<any, any>> = { | ||
| eth_getBalance: eth_getBalance, | ||
| eth_getTransactionCount: eth_getTransactionCount, | ||
| }; | ||
| /* eslint-enable @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any*/ | ||
|
|
||
| export async function processAndVerifyRequest({ | ||
| payload, | ||
| handler, | ||
| proofProvider, | ||
| logger, | ||
| }: { | ||
| payload: ELRequestPayload; | ||
| handler: ELRequestHandler; | ||
| proofProvider: ProofProvider; | ||
| logger: Logger; | ||
| }): Promise<ELResponse | undefined> { | ||
| await proofProvider.waitToBeReady(); | ||
| logger.debug("Processing request", {method: payload.method, params: JSON.stringify(payload.params)}); | ||
| const verifiedHandler = supportedELRequests[payload.method]; | ||
|
|
||
| if (verifiedHandler !== undefined) { | ||
| logger.verbose("Verified request handler found", {method: payload.method}); | ||
| return verifiedHandler({payload, handler, proofProvider, logger}); | ||
| } | ||
|
|
||
| logger.warn("Verified request handler not found. Falling back to proxy.", {method: payload.method}); | ||
| return handler(payload); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import {ELVerifiedRequestHandler} from "../interfaces.js"; | ||
| import {bufferToHex} from "../utils/conversion.js"; | ||
| import {getELProof, isValidAccount, isValidStorageKeys} from "../utils/execution.js"; | ||
| import {generateRPCResponseForPayload, generateUnverifiedResponseForPayload} from "../utils/json_rpc.js"; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| export const eth_getTransactionCount: ELVerifiedRequestHandler< | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nazarhussain since it shares most of the steps from
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure will refactor in upcoming PRs. |
||
| [address: string, block?: number | string], | ||
| string | ||
| > = async ({handler, payload, logger, proofProvider}) => { | ||
| const { | ||
| params: [address, block], | ||
| } = payload; | ||
| const executionPayload = await proofProvider.getExecutionPayload(block ?? "latest"); | ||
| const proof = await getELProof(handler, [address, [], bufferToHex(executionPayload.blockHash)]); | ||
|
|
||
| if ( | ||
| (await isValidAccount({ | ||
| address: address, | ||
| stateRoot: executionPayload.stateRoot, | ||
| proof, | ||
| })) && | ||
| (await isValidStorageKeys({storageKeys: [], proof})) | ||
| ) { | ||
| return generateRPCResponseForPayload(payload, proof.nonce); | ||
| } | ||
|
|
||
| logger.error("Request could not be verified."); | ||
| return generateUnverifiedResponseForPayload(payload, "eth_getTransactionCount request can not be verified."); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import {allForks} from "@lodestar/types"; | ||
|
|
||
| export const validExecutionPayload: allForks.ExecutionPayload = ({ | ||
| blockHash: Buffer.alloc(32), | ||
| stateRoot: Buffer.from("7c0f9a6f21d82c2d7690db7aa36c9938de11891071eed6e50ff8b06b5ae7018a", "hex"), | ||
| } as unknown) as allForks.ExecutionPayload; | ||
|
|
||
| export const invalidExecutionPayload: allForks.ExecutionPayload = ({ | ||
| blockHash: Buffer.alloc(32), | ||
| stateRoot: Buffer.from("ac0d3a6f21d82c2d7690db7aa36c9938de11891071eed6e50ff8b06b5ae7018a", "hex"), | ||
| } as unknown) as allForks.ExecutionPayload; |
Check failure
Code scanning / CodeQL
Unvalidated dynamic method call