Skip to content

Feat/relayer envio - #457

Merged
mani99brar merged 5 commits into
devfrom
feat/relayer-envio
Aug 5, 2026
Merged

Feat/relayer envio#457
mani99brar merged 5 commits into
devfrom
feat/relayer-envio

Conversation

@mani99brar

@mani99brar mani99brar commented May 25, 2026

Copy link
Copy Markdown
Contributor

PR-Codex overview

This PR introduces the relayer-envio-inbox, adding a new indexer for managing events from the VeaInboxArbToEth contract. It includes configurations, TypeScript support, and utility functions for decoding data and managing Merkle trees.

Detailed summary

  • Added .env and example for API token configuration.
  • Introduced relayer-envio-inbox package with TypeScript support.
  • Created utility functions in decoder.ts and merkle.ts.
  • Implemented event handlers in EventHandlers.ts for processing MessageSent, SnapshotSaved, and SnapshotSent events.
  • Defined GraphQL schema in schema.graphql.
  • Updated README.md with instructions for running the indexer and generating files.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added an Envio Indexer service exposing GraphQL data for inbox messages, snapshots, Merkle nodes, and related entities.
    • Added event tracking for messages sent, snapshots saved, and snapshots sent.
  • Documentation

    • Added local setup, build, code generation, and GraphQL Playground instructions.
    • Documented the required ENVIO_API_TOKEN environment variable.
  • Tests

    • Added unit tests covering message decoding and Merkle hashing utilities.
  • Chores

    • Added workspace configuration, development scripts, and ignore rules for generated and environment files.

@netlify

netlify Bot commented May 25, 2026

Copy link
Copy Markdown

Deploy Preview for veascan ready!

Name Link
🔨 Latest commit ed8fa60
🔍 Latest deploy log https://app.netlify.com/projects/veascan/deploys/6a72faee4a4a3f0008ff967a
😎 Deploy Preview https://deploy-preview-457--veascan.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented May 25, 2026

Copy link
Copy Markdown

Deploy Preview for veashi-scan canceled.

Name Link
🔨 Latest commit ed8fa60
🔍 Latest deploy log https://app.netlify.com/projects/veashi-scan/deploys/6a72faee0ca3d6000860d264

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This pull request adds relayer-envio-inbox, an Envio indexer workspace for VeaInboxArbToEth on chain 421614. It decodes events, stores GraphQL entities, and reconstructs Merkle tree state from message and snapshot events.

Changes

Envio Indexer Implementation

Layer / File(s) Summary
Workspace setup and project configuration
package.json, .gitignore, relayer-envio-inbox/package.json, relayer-envio-inbox/.env.example, relayer-envio-inbox/.gitignore, relayer-envio-inbox/README.md, relayer-envio-inbox/tsconfig.json, relayer-envio-inbox/jest.config.ts, relayer-envio-inbox/envio-env.d.ts
Registers the workspace and adds Envio, TypeScript, Jest, environment, build, test, and local development configuration.
GraphQL schema definition
relayer-envio-inbox/schema.graphql
Defines entities for messages, snapshots, Merkle nodes, inboxes, senders, and receivers.
Merkle hashing, decoding, and tests
relayer-envio-inbox/src/utils/merkle.ts, relayer-envio-inbox/src/utils/decoder.ts, relayer-envio-inbox/test/Test.ts
Adds node payload decoding and deterministic Keccak-based Merkle helpers. Jest tests validate parsing, hashing, determinism, and ordering.
Event handlers and indexer configuration
relayer-envio-inbox/config.yaml, relayer-envio-inbox/src/EventHandlers.ts
Wires three contract events to handlers. The handlers persist event data and update or reconstruct Merkle nodes.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant VeaInboxArbToEth as VeaInboxArbToEth Contract
  participant EventHandlers as EventHandlers
  participant MerkleUtils as Merkle Utils
  participant IndexStore as Envio Store
  VeaInboxArbToEth->>EventHandlers: emit MessageSent, SnapshotSaved, or SnapshotSent
  EventHandlers->>MerkleUtils: decode node data and compute hashes
  MerkleUtils->>EventHandlers: return decoded fields and Merkle hashes
  EventHandlers->>IndexStore: persist event entities and MerkleNode records
Loading

Possibly related PRs

  • kleros/vea#418: Adds related network-specific Vea inbox contract and subgraph configuration.
  • kleros/vea#438: Changes the VeaInboxArbToEth event and data encoding consumed by this indexer.

Suggested reviewers: jaybuidl

Poem

🐰 A new indexer starts its run,
Events are stored one by one,
Merkle nodes rebuild in flight,
Snapshots keep the roots aligned,
GraphQL records bloom bright.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title identifies the main change, which is the addition of the Envio relayer indexer.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/relayer-envio

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (1)
relayer-envio-inbox/test/Test.ts (1)

12-85: ⚡ Quick win

Consider adding error case tests.

The test suite provides good coverage of expected behavior but doesn't test error conditions such as:

  • Malformed hex input (invalid characters, missing 0x prefix)
  • Wrong input lengths (too short or too long)
  • Invalid address formats
  • Boundary values (e.g., max nonce value)

If the utility functions are expected to handle these cases gracefully, adding negative tests would improve robustness.

🧪 Example error case tests
describe("decodeNodeData - error cases", () => {
  it("handles invalid hex input", () => {
    expect(() => decodeNodeData("not-hex")).toThrow();
  });

  it("handles input that is too short", () => {
    expect(() => decodeNodeData("0x1234")).toThrow();
  });
});

describe("leafHash - edge cases", () => {
  it("handles empty input", () => {
    expect(() => leafHash("0x")).not.toThrow();
  });
});

Note: Adjust expectations based on whether functions should throw or handle gracefully.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@relayer-envio-inbox/test/Test.ts` around lines 12 - 85, Add negative and
edge-case tests to cover malformed and boundary inputs: add a new
"decodeNodeData - error cases" suite that asserts decodeNodeData throws or
handles invalid hex (e.g., missing "0x" or non-hex chars) and inputs that are
too short/too long or have invalid address lengths; add tests for extreme nonce
values (max uint64) and for when trailing data is absent; also add tests for
leafHash, concatAndSort, and hashPair that check behavior on empty input,
invalid hex, and unexpected lengths (assert throw or notThrow based on intended
behavior) so the functions decodeNodeData, leafHash, concatAndSort, and hashPair
are covered for error and boundary conditions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@relayer-envio-inbox/.env.example`:
- Line 2: The ENVIO_API_TOKEN placeholder in .env.example is quoted; remove the
surrounding double quotes so the line reads ENVIO_API_TOKEN=<YOUR-API-TOKEN> to
match typical .env formatting and avoid accidental quoted secrets; update any
related documentation or README references that show the example so they also
use the unquoted placeholder string.

In `@relayer-envio-inbox/README.md`:
- Line 22: Update the README entry that currently references "Yarn (use v1 or
newer)" to require the repo's pinned version by changing the text to "Yarn (use
v4.6.0)" and, if desired, update the link target to the modern Yarn installation
guidance (or a short note about enabling Corepack) so contributors install Yarn
4.6.0 instead of Yarn 1; locate and modify the exact line containing the current
"[Yarn (use v1 or newer)]" text in README.md.

In `@relayer-envio-inbox/src/EventHandlers.ts`:
- Around line 103-143: The Merkle reconstruction loop corrupts large uint64
`count` by coercing it to JS Number and using 32-bit bitwise ops; change `size`,
`oldCount`, `height`, and `index` to bigint (initialize e.g. size =
BigInt(count)), and replace all numeric bit ops with bigint ops: use `& 1n`
instead of `& 1`, `>>= 1n` instead of `>>= 1`, and `2n ** height` instead of `2
** height`; update uses in the loop (variables `size`, `oldCount`, `height`,
`index`, and the `if ((size & 1) === 1)` branch and index calculations) so
template ids like `${inbox}-${index}` still stringify correctly and ensure
comparisons use bigint where needed.

In `@relayer-envio-inbox/src/utils/decoder.ts`:
- Around line 9-13: decodeNodeData currently calls hexToBuffer(...) and performs
fixed-offset reads (bytes.readBigUInt64BE(0), subarray(8,28), subarray(28,48))
without validating length; add a minimum-length guard that validates
bytes.length >= 48 before any fixed reads and handle insufficient length by
returning a safe value (e.g., null/undefined) or throwing a descriptive error so
callers (like EventHandlers.ts using event.params._nodeData) don't break; update
decodeNodeData to perform the length check right after hexToBuffer and ensure
downstream callers handle the null/error case appropriately.

---

Nitpick comments:
In `@relayer-envio-inbox/test/Test.ts`:
- Around line 12-85: Add negative and edge-case tests to cover malformed and
boundary inputs: add a new "decodeNodeData - error cases" suite that asserts
decodeNodeData throws or handles invalid hex (e.g., missing "0x" or non-hex
chars) and inputs that are too short/too long or have invalid address lengths;
add tests for extreme nonce values (max uint64) and for when trailing data is
absent; also add tests for leafHash, concatAndSort, and hashPair that check
behavior on empty input, invalid hex, and unexpected lengths (assert throw or
notThrow based on intended behavior) so the functions decodeNodeData, leafHash,
concatAndSort, and hashPair are covered for error and boundary conditions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 958bba1f-d5a6-4269-bafc-6ab1c27cf89f

📥 Commits

Reviewing files that changed from the base of the PR and between 8911800 and 0d07a13.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (15)
  • .gitignore
  • package.json
  • relayer-envio-inbox/.env.example
  • relayer-envio-inbox/.gitignore
  • relayer-envio-inbox/README.md
  • relayer-envio-inbox/config.yaml
  • relayer-envio-inbox/envio-env.d.ts
  • relayer-envio-inbox/jest.config.ts
  • relayer-envio-inbox/package.json
  • relayer-envio-inbox/schema.graphql
  • relayer-envio-inbox/src/EventHandlers.ts
  • relayer-envio-inbox/src/utils/decoder.ts
  • relayer-envio-inbox/src/utils/merkle.ts
  • relayer-envio-inbox/test/Test.ts
  • relayer-envio-inbox/tsconfig.json

Comment thread relayer-envio-inbox/.env.example Outdated
Comment thread relayer-envio-inbox/README.md Outdated
Comment thread relayer-envio-inbox/src/EventHandlers.ts Outdated
Comment thread relayer-envio-inbox/src/utils/decoder.ts
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 25, 2026
@mani99brar
mani99brar marked this pull request as ready for review May 25, 2026 14:01
@mani99brar
mani99brar requested a review from jaybuidl as a code owner May 25, 2026 14:01
@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@mani99brar
mani99brar merged commit cf601d0 into dev Aug 5, 2026
15 of 17 checks passed
@mani99brar
mani99brar deleted the feat/relayer-envio branch August 5, 2026 09:09
@coderabbitai coderabbitai Bot mentioned this pull request Aug 19, 2026
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.

1 participant