Skip to content

fix: normalize response bytes in getKeysFromRelayer#2

Open
luchobonatti wants to merge 2 commits intomainfrom
fix/378-response-bytes-normalization
Open

fix: normalize response bytes in getKeysFromRelayer#2
luchobonatti wants to merge 2 commits intomainfrom
fix/378-response-bytes-normalization

Conversation

@luchobonatti
Copy link
Copy Markdown
Member

@luchobonatti luchobonatti commented Apr 8, 2026

Closes: zama-ai#378

Summary

  • Replace inline response.bytes() / response.arrayBuffer() logic in getKeysFromRelayer with the existing getResponseBytes() utility
  • getResponseBytes() already uses normalizeBytes() which handles Uint8Array, ArrayBuffer, and ArrayBufferView — fixing the case where undici (Next.js) returns ArrayBuffer from response.bytes()

Changes

File Change
src/relayer-provider/v1/networkV1.ts Replace 2 inline byte-reading blocks (12 lines) with getResponseBytes() calls (2 lines)

Test plan

  • prettier:check passes
  • eslint passes
  • networkV1.test.ts — 1 suite, all pass
  • fetch.test.ts — 1 suite, all pass

Copilot AI review requested due to automatic review settings April 8, 2026 19:17
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR normalizes relayer key/CRS response body handling in getKeysFromRelayer by reusing the shared getResponseBytes() utility, improving compatibility with fetch implementations (e.g., undici/Next.js returning ArrayBuffer from response.bytes()).

Changes:

  • Replace inline response.bytes() / response.arrayBuffer() branching with getResponseBytes() for the public key fetch.
  • Replace inline response.bytes() / response.arrayBuffer() branching with getResponseBytes() for the CRS (2048) fetch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

await publicParams2048Response.arrayBuffer(),
);
}
const publicParams2048 = await getResponseBytes(publicParams2048Response);
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

getResponseBytes() already returns a Uint8Array, but later this buffer is wrapped with new Uint8Array(publicParams2048) before deserialization. That constructor call will clone the entire CRS byte array, which can be very large and adds avoidable memory/CPU overhead. Since the bytes are already normalized, pass publicParams2048 directly to CompactPkeCrs.safe_deserialize(...) (and drop the extra new Uint8Array(...)).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: response.bytes() returns ArrayBuffer in Next.js/undici; SDK assumes Uint8Array and fails key deserialization

2 participants