Skip to content

Fix: Override StudioNet consensus address to prevent 0x0...0 routing#141

Open
ngh1105 wants to merge 1 commit intogenlayerlabs:mainfrom
ngh1105:fix-studionet-zero-address
Open

Fix: Override StudioNet consensus address to prevent 0x0...0 routing#141
ngh1105 wants to merge 1 commit intogenlayerlabs:mainfrom
ngh1105:fix-studionet-zero-address

Conversation

@ngh1105
Copy link

@ngh1105 ngh1105 commented Mar 3, 2026

Fixes # (Leave blank if there is no linked issue)

WHAT TO PUT IN "What"

  • Modified initializeConsensusSmartContract inside src/chains/actions.ts to override the API's returned consensus address specifically for studionet.
  • Added a fallback safety check to enforce 0xb7278A61aa25c888815aFC32Ad3cC52fF24fE575 natively as the canonical Consensus Main Contract address if the active chain being requested is StudioNet.

WHAT TO PUT IN "Why"

  • To fix a critical transaction routing bug: The sim_getConsensusContract RPC method at the endpoint https://studio.genlayer.com/api currently returns an anomalous zero address (0x0...0).
  • To add more value to the user: By natively overriding this backend bug at the client SDK level, frontend developers using Web3 wallets (like MetaMask) alongside genlayer-js will no longer encounter intrusive "Zero Address" warnings, allowing GenVM smart contract transactions to be signed and routed successfully.

WHAT TO PUT IN "Testing done"

  • Tested compiling the modified SDK into a local Next.js frontend application via local module resolution.
  • Confirmed that transactions triggered by genlayer-js via writeContract reliably route to the correct 0xb727... consensus address instead of 0x0...0.
  • Verified the correct fallback operation does not affect or break normal initialization behaviors on localnet.

WHAT TO PUT IN "Decisions made"

  • Decided to implement the fix as a hardcoded conditional-override directly at the SDK's action layer (src/chains/actions.ts). This is the most non-intrusive approach to bypass the unreliable API backend strictly for StudioNet requests, masking the bug from end-users until the GenLayer Studio RPC is permanently fixed.

WHAT TO PUT IN "Checks"
[x] I have tested this code
[x] I have reviewed my own PR
[ ] I have created an issue for this PR
[x] I have set a descriptive PR title compliant with conventional commits

WHAT TO PUT IN "Reviewing tips"

  • The added logic block is intentionally and tightly scoped to chain.id === studionet.id inside the promise resolution of sim_getConsensusContract.

WHAT TO PUT IN "User facing release notes"

  • Fix: StudioNet transactions and genlayer-js routing interactions now correctly resolve to the functioning default Consensus Main Contract address, preventing unexpected reversions/transaction failures caused by a zero-address routing bug.

Summary by CodeRabbit

  • Bug Fixes

    • Improved studionet environment configuration
  • Style

    • Updated import formatting

@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

The pull request introduces a conditional override in the chain actions logic that, when the chain is studionet, sets the consensusMainContract address to a hard-coded value, bypassing an associated warning. The change is localized and does not affect public API signatures.

Changes

Cohort / File(s) Summary
Studionet Chain Override
src/chains/actions.ts
Adds a conditional check that, when the chain is studionet, overrides the consensusMainContract address with a hard-coded value. Import formatting is adjusted with whitespace-only changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • cristiam86

Poem

🐰 A little override, neat and small,
For studionet chains, addressing all,
Hard-coded paths to make things right,
The rabbit hops through network light! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: overriding the StudioNet consensus address to fix a 0x0...0 routing issue.
Description check ✅ Passed The PR description includes all required template sections with detailed explanations of what was changed, why, testing done, decisions made, and checks completed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/chains/actions.ts (2)

55-58: Make StudioNet override a zero-address fallback and avoid duplicated address literals.

The current logic overwrites any StudioNet RPC address unconditionally. That can hide future contract rotations and route to a stale address. Prefer overriding only when RPC returns the zero address, and source fallback from studionet.consensusMainContract.address.

🛠️ Suggested update
-        // --- LexNet Hack: Force the transaction destination to bypass MetaMaks 0x0...0 warning
+        // StudioNet fallback: override only when RPC returns the zero address.
         if (client.chain?.id === studionet.id) {
-          consensusMainContract.result.address = "0xb7278A61aa25c888815aFC32Ad3cC52fF24fE575";
+          const rpcAddress = consensusMainContract.result.address?.toLowerCase();
+          const isZeroAddress =
+            rpcAddress === "0x0000000000000000000000000000000000000000";
+          const fallbackAddress = studionet.consensusMainContract?.address;
+          if (isZeroAddress && fallbackAddress) {
+            consensusMainContract.result.address = fallbackAddress;
+          }
         }

Based on learnings: Applies to **/*chain*.{ts,tsx} : Extend viem's Chain type with GenLayer-specific properties including consensusMainContract.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/chains/actions.ts` around lines 55 - 58, Currently the code
unconditionally sets consensusMainContract.result.address to a hard-coded
literal when client.chain?.id === studionet.id; instead change the logic to only
override when the RPC returned the zero address (e.g.,
"0x0000000000000000000000000000000000000000") and otherwise leave the RPC value
intact, and when overriding use the canonical fallback value
studionet.consensusMainContract.address rather than repeating the literal;
update the block referencing client.chain?.id, studionet.id, and
consensusMainContract.result.address to perform a zero-address check and assign
studionet.consensusMainContract.address only in that case.

1-4: Use @/* aliases for internal src imports.

Lines 2-4 currently use relative imports in a src TypeScript file. Please switch these to the configured path alias style.

♻️ Suggested update
 import { GenLayerClient, GenLayerChain } from "@/types";
-import { localnet } from "./localnet";
-import { studionet } from "./studionet";
-import { testnetAsimov } from "./testnetAsimov";
+import { localnet } from "@/chains/localnet";
+import { studionet } from "@/chains/studionet";
+import { testnetAsimov } from "@/chains/testnetAsimov";

As per coding guidelines **/*.{ts,tsx}: Use path alias @/* to reference ./src/* and @@/tests/* to reference ./tests/*.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/chains/actions.ts` around lines 1 - 4, Replace the relative imports at
the top of the file by switching to the project path alias: change the import
statements that reference localnet, studionet and testnetAsimov to use "@/…"
style (e.g., import { localnet } from "@/chains/localnet";) so the symbols
localnet, studionet and testnetAsimov are imported via the `@/`* alias instead of
relative paths; update the import lines in the module that defines
GenLayerClient/GenLayerChain accordingly and ensure TypeScript resolves the new
aliases.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/chains/actions.ts`:
- Around line 55-58: Currently the code unconditionally sets
consensusMainContract.result.address to a hard-coded literal when
client.chain?.id === studionet.id; instead change the logic to only override
when the RPC returned the zero address (e.g.,
"0x0000000000000000000000000000000000000000") and otherwise leave the RPC value
intact, and when overriding use the canonical fallback value
studionet.consensusMainContract.address rather than repeating the literal;
update the block referencing client.chain?.id, studionet.id, and
consensusMainContract.result.address to perform a zero-address check and assign
studionet.consensusMainContract.address only in that case.
- Around line 1-4: Replace the relative imports at the top of the file by
switching to the project path alias: change the import statements that reference
localnet, studionet and testnetAsimov to use "@/…" style (e.g., import {
localnet } from "@/chains/localnet";) so the symbols localnet, studionet and
testnetAsimov are imported via the `@/`* alias instead of relative paths; update
the import lines in the module that defines GenLayerClient/GenLayerChain
accordingly and ensure TypeScript resolves the new aliases.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e56de8 and 40218ae.

📒 Files selected for processing (1)
  • src/chains/actions.ts

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