Skip to content

fix: handle short storage values in beacon proxy pattern #7282

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

Merged

Conversation

catalyst17
Copy link
Contributor

@catalyst17 catalyst17 commented Jun 5, 2025

[SDK] Fix: Handle short storage values in beacon proxy pattern

Notes for the reviewer

Tests follow-up to #7281

Added a unit test that specifically verifies the implementation can handle short storage values returned from eth_getStorageAt, which was the original issue we were trying to fix.

Summary by CodeRabbit

  • Tests
    • Added a new test suite to verify correct handling of beacon proxy patterns, including edge cases with short storage values in smart contract bytecode resolution.

PR-Codex overview

This PR focuses on fixing the implementation resolution for the Beacon proxy pattern in the thirdweb package by enhancing the test coverage to ensure proper handling of short storage values.

Detailed summary

  • Updated the test in handleBeaconProxyPattern.test.ts to verify handling of short storage values.
  • Mocked dependencies such as getBytecode, eth_getStorageAt, and getRpcClient.
  • Created a mock contract to test the resolution of implementation addresses.
  • Ensured that the test checks for defined results without throwing errors.

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

Copy link

vercel bot commented Jun 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 5, 2025 0:27am
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 5, 2025 0:27am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 5, 2025 0:27am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 5, 2025 0:27am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 5, 2025 0:27am

Copy link

changeset-bot bot commented Jun 5, 2025

🦋 Changeset detected

Latest commit: e493133

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
thirdweb Patch
@thirdweb-dev/wagmi-adapter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Jun 5, 2025

Warning

Rate limit exceeded

@catalyst17 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 15 minutes and 5 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b55d4cf and e493133.

📒 Files selected for processing (2)
  • .changeset/cold-icons-shop.md (1 hunks)
  • packages/thirdweb/src/utils/bytecode/handleBeaconProxyPattern.test.ts (1 hunks)

Walkthrough

A new test suite has been added to verify the handling of the beacon proxy pattern in smart contract bytecode resolution. The test specifically targets scenarios involving short storage values and ensures the implementation address is correctly resolved without errors, using mocked dependencies and conditional execution based on an environment variable.

Changes

File(s) Change Summary
packages/thirdweb/src/utils/bytecode/handleBeaconProxyPattern.test.ts Added a test suite for the beacon proxy pattern, focusing on short storage value handling with mocks.

Sequence Diagram(s)

sequenceDiagram
    participant TestSuite
    participant MockedGetBytecode
    participant MockedRpcClient
    participant ResolveImplementation

    TestSuite->>MockedGetBytecode: getBytecode (returns empty, then dummy bytecode)
    TestSuite->>MockedRpcClient: eth_getStorageAt (returns short hex string)
    TestSuite->>ResolveImplementation: resolveImplementation(address, client)
    ResolveImplementation->>MockedGetBytecode: getBytecode(address)
    ResolveImplementation->>MockedRpcClient: eth_getStorageAt(address, slot)
    ResolveImplementation-->>TestSuite: Returns implementation address
Loading

Possibly related PRs

Suggested reviewers

  • jnsdls
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Jun 5, 2025
Copy link
Contributor Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

@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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/thirdweb/src/utils/bytecode/handleBeaconProxyPattern.test.ts (1)

1-26: Remove unused imports to improve code clarity.

Multiple imports are flagged as unused by static analysis and should be removed to keep the code clean and maintainable.

Apply this diff to remove unused imports:

-import type { Abi } from "abitype";
 import type { EIP1193RequestFn, EIP1474Methods } from "viem";
 import { beforeEach, describe, expect, it, vi } from "vitest";
-import {
-  DUMMY_BYTECODE,
-  ERC1967_PROXY_BYTECODE,
-  ERC1967_PROXY_CONSTRUCTOR_ABI,
-} from "../../../test/src/abis/proxy.js";
 import { ANVIL_CHAIN } from "../../../test/src/chains.js";
 import { TEST_CLIENT } from "../../../test/src/test-clients.js";
-import {
-  BASE_USDC_IMPLEMENTATION,
-  BASE_USDC_PROXY_CONTRACT,
-  NFT_DROP_CONTRACT,
-  NFT_DROP_IMPLEMENTATION,
-  POLYGON_USDT_IMPLEMENTATION,
-  POLYGON_USDT_PROXY_CONTRACT,
-} from "../../../test/src/test-contracts.js";
-import { TEST_ACCOUNT_A } from "../../../test/src/test-wallets.js";
 import { getBytecode } from "../../contract/actions/get-bytecode.js";
-import { getContract } from "../../contract/contract.js";
-import { deployContract } from "../../contract/deployment/deploy-with-abi.js";
 import { eth_getStorageAt } from "../../rpc/actions/eth_getStorageAt.js";
 import { getRpcClient } from "../../rpc/rpc.js";
 import { resolveImplementation } from "./resolveImplementation.js";
🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 5-5: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 6-6: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 7-7: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 12-12: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 13-13: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 14-14: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 15-15: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 16-16: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 17-17: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 19-19: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 21-21: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 22-22: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c0b80d and d9ae677.

📒 Files selected for processing (2)
  • packages/thirdweb/src/utils/bytecode/handleBeaconProxyPattern.test.ts (1 hunks)
  • packages/thirdweb/src/utils/bytecode/resolveImplementation.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/thirdweb/src/utils/bytecode/resolveImplementation.ts (1)
packages/thirdweb/src/exports/thirdweb.ts (1)
  • isAddress (308-308)
packages/thirdweb/src/utils/bytecode/handleBeaconProxyPattern.test.ts (1)
packages/thirdweb/src/utils/bytecode/resolveImplementation.ts (1)
  • resolveImplementation (26-90)
🪛 Biome (1.9.4)
packages/thirdweb/src/utils/bytecode/handleBeaconProxyPattern.test.ts

[error] 1-1: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 5-5: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 6-6: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 7-7: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 12-12: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 13-13: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 14-14: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 15-15: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 16-16: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 17-17: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 19-19: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 21-21: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)


[error] 22-22: This import is unused.

Unused imports might be the result of an incomplete refactoring.
Safe fix: Remove the unused import.

(lint/correctness/noUnusedImports)

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Unit Tests
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: Size
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
packages/thirdweb/src/utils/bytecode/resolveImplementation.ts (1)

52-52: Excellent defensive programming practice!

Adding the isAddress(beacon) validation before proceeding with beacon proxy resolution is a smart improvement. This prevents potential runtime errors when the storage data doesn't contain a valid Ethereum address format, making the code more robust against edge cases with malformed storage values.

packages/thirdweb/src/utils/bytecode/handleBeaconProxyPattern.test.ts (2)

38-67: Well-structured test for the edge case!

The test effectively verifies the handling of short storage values in beacon proxy pattern resolution. The mocking strategy correctly simulates the scenario where eth_getStorageAt returns a short value ("0x1234"), ensuring the implementation doesn't throw errors and handles this edge case gracefully.


32-34: Appropriate use of conditional test execution.

The conditional test execution based on TW_SECRET_KEY environment variable is a good practice for tests that may require specific setup or credentials, ensuring they only run in appropriate environments.

Copy link
Contributor

github-actions bot commented Jun 5, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 62.57 KB (0%) 1.3 s (0%) 242 ms (+98.88% 🔺) 1.5 s
thirdweb (cjs) 345.55 KB (0%) 7 s (0%) 933 ms (+6.84% 🔺) 7.9 s
thirdweb (minimal + tree-shaking) 5.7 KB (0%) 114 ms (0%) 59 ms (+671.34% 🔺) 173 ms
thirdweb/chains (tree-shaking) 531 B (0%) 11 ms (0%) 51 ms (+1939.28% 🔺) 61 ms
thirdweb/react (minimal + tree-shaking) 19.56 KB (0%) 392 ms (0%) 79 ms (+247.86% 🔺) 470 ms

Copy link

codecov bot commented Jun 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.58%. Comparing base (7c0b80d) to head (e493133).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7282      +/-   ##
==========================================
- Coverage   55.58%   55.58%   -0.01%     
==========================================
  Files         909      909              
  Lines       58670    58670              
  Branches     4163     4158       -5     
==========================================
- Hits        32613    32609       -4     
- Misses      25950    25955       +5     
+ Partials      107      106       -1     
Flag Coverage Δ
packages 55.58% <ø> (-0.01%) ⬇️

see 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joaquim-verges joaquim-verges merged commit e3e3142 into main Jun 5, 2025
24 of 25 checks passed
@joaquim-verges joaquim-verges deleted the fix_handle_short_storage_values_in_beacon_proxy_pattern branch June 5, 2025 12:21
@joaquim-verges joaquim-verges mentioned this pull request Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants