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

chore: review proof routes #6843

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions packages/api/src/beacon/client/proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import {ChainForkConfig} from "@lodestar/config";
import {ApiClientMethods, IHttpClient, createApiClientMethods} from "../../utils/client/index.js";
import {Endpoints, getDefinitions} from "../routes/proof.js";

// TODO: revisit, do we still need to override methods? Make sure we still return same format as previously

export type ApiClient = ApiClientMethods<Endpoints>;

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/beacon/routes/proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {ArrayOf} from "../../utils/codecs.js";
import {VersionCodec, VersionMeta} from "../../utils/metadata.js";

export const CompactMultiProofType = new ContainerType({
// TODO ensure limit of all lists is sane
leaves: ArrayOf(ssz.Root),
leaves: ArrayOf(ssz.Root, 10000),
Copy link
Member Author

@nflaig nflaig Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am asuming this is sufficient and sane enough, same value we use in

export const HashListType = new ListCompositeType(ssz.Root, 10000);

but I am not that familiar with return values of proof routes, would be good to get eyes on this. Better to have a too high limit, than breaking large proofs by setting it too low.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10k is plenty big, I wanna say we had 512 set as MAX_PROOF_GINDICES at some point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a configurable limit on the server which as you noted is 512. the limit in the ssz type might still be useful to avoid crashing the client

// It's currently possible to request gigantic proofs (eg: a proof of the entire beacon state)
// We want some some sort of resistance against this DoS vector.
const maxGindicesInProof = opts.maxGindicesInProof ?? 512;

preventing server dos vector should be covered

descriptor: new ByteListType(2048),
});

Expand Down
35 changes: 0 additions & 35 deletions packages/api/src/beacon/server/proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,6 @@ import {ChainForkConfig} from "@lodestar/config";
import {ApplicationMethods, FastifyRoutes, createFastifyRoutes} from "../../utils/server/index.js";
import {Endpoints, getDefinitions} from "../routes/proof.js";

// TODO: revisit, do we need still need to override handlers?

export function getRoutes(config: ChainForkConfig, methods: ApplicationMethods<Endpoints>): FastifyRoutes<Endpoints> {
return createFastifyRoutes(getDefinitions(config), methods);
// const serverRoutes = createFastifyRoutes(definitions, methods);

// return {
// // Non-JSON routes. Return binary
// getStateProof: {
// ...serverRoutes.getStateProof,
// handler: async (req) => {
// const args = definitions.getStateProof.req.parseReq(req);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could implement the same logic in serialize / deserialize in the route without overriding the handler if that's the format we wanna keep

// const {data} = await methods.getStateProof(args);
// const leaves = (data as CompactMultiProof).leaves;
// const response = new Uint8Array(32 * leaves.length);
// for (let i = 0; i < leaves.length; i++) {
// response.set(leaves[i], i * 32);
// }
// // Fastify 3.x.x will automatically add header `Content-Type: application/octet-stream` if Buffer
// return Buffer.from(response);
// },
// },
// getBlockProof: {
// ...serverRoutes.getBlockProof,
// handler: async (req) => {
// const args = definitions.getBlockProof.req.parseReq(req);
// const {data} = await methods.getBlockProof(args);
// const leaves = (data as CompactMultiProof).leaves;
// const response = new Uint8Array(32 * leaves.length);
// for (let i = 0; i < leaves.length; i++) {
// response.set(leaves[i], i * 32);
// }
// // Fastify 3.x.x will automatically add header `Content-Type: application/octet-stream` if Buffer
// return Buffer.from(response);
// },
// },
// };
}
Loading