Skip to content

InAppWallet EIP7702 Session Key Integration #150

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
merged 5 commits into from
Jun 23, 2025

Conversation

0xFirekeeper
Copy link
Member

@0xFirekeeper 0xFirekeeper commented Jun 20, 2025

PR-Codex overview

This PR focuses on enhancing the CreateSessionKey functionality for EIP-7702 execution modes, updating connection methods, and refining constants related to minimal accounts.

Detailed summary

  • Updated comments in Thirdweb.Console/Program.cs to clarify chain compatibility.
  • Changed authProvider from Google to Guest in InAppWallet.Create.
  • Modified CreateSessionKey method signature and implementation in EcosystemWallet.cs.
  • Added argument validation in CreateSessionKey.
  • Updated the MINIMAL_ACCOUNT_7702 constant in Constants.cs.

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

Summary by CodeRabbit

  • New Features

    • Enabled session key creation for wallets using EIP-7702 execution modes, including transaction simulation and logging.
    • Activated guest login and wallet upgrades with delegated account checks for supported wallets.
  • Bug Fixes

    • Updated the default minimal account address for EIP-7702 compatibility.
  • Improvements

    • Enhanced session key management with improved expiration handling and address resolution.
    • Added support for detecting and handling new wallet events related to value reception.
    • Updated example code to demonstrate guest authentication and simplified session key creation.

Copy link

coderabbitai bot commented Jun 20, 2025

Walkthrough

The changes activate and implement EIP-7702 session key functionality in the wallet code. This includes enabling previously commented-out logic in the console program, updating the minimal account contract address constant and ABI, and fully implementing the CreateSessionKey method in the EcosystemWallet class to support session key creation with EIP-712 signing and transaction execution.

Changes

File(s) Change Summary
Thirdweb.Console/Program.cs Activated previously commented-out EIP-7702 demo code; switched to guest auth with EIP-7702 sponsored mode; updated ENS addresses and session UID generation; simplified session key creation call.
Thirdweb/Thirdweb.Utils/Constants.cs Updated MINIMAL_ACCOUNT_7702 constant to a new Ethereum address; replaced MINIMAL_ACCOUNT_7702_ABI with new ABI adding ValueReceived event.
Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs Implemented CreateSessionKey method with full logic: execution mode validation, EIP-712 signature generation, contract call preparation, and transaction execution.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Program
    participant EcosystemWallet
    participant EthereumNetwork

    User->>Program: Start EIP-7702 demo
    Program->>EcosystemWallet: Initialize with Guest Auth & EIP-7702 Sponsored mode
    Program->>EcosystemWallet: Check if connected
    alt Not connected
        Program->>EcosystemWallet: Guest login with session ID override
    end
    Program->>EcosystemWallet: Get wallet address
    Program->>EthereumNetwork: Send zero-wei transfer to vitalik.eth (triggers upgrade)
    Program->>EcosystemWallet: Check if account is delegated
    Program->>EcosystemWallet: CreateSessionKey(chainId, signerAddress, duration, permissions)
    EcosystemWallet->>EcosystemWallet: Validate execution mode
    EcosystemWallet->>EcosystemWallet: Generate session key signature (EIP-712)
    EcosystemWallet->>EthereumNetwork: Simulate createSessionWithSig call
    EcosystemWallet->>EthereumNetwork: Execute createSessionWithSig transaction
    EcosystemWallet->>Program: Return transaction receipt
    Program->>User: Print transaction hash
Loading

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • EIP-7702: Entity not found: Issue - Could not find referenced Issue.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6388ff4 and f989fe0.

📒 Files selected for processing (1)
  • Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test-cov
🔇 Additional comments (4)
Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs (4)

453-461: Well-structured method signature for EIP-7702 session key creation.

The method signature provides comprehensive parameters with sensible defaults, supporting both full permissions and granular policy control through optional callPolicies and transferPolicies.


463-466: Appropriate execution mode validation.

The validation correctly restricts session key creation to EIP-7702 execution modes, ensuring the feature is only available when the wallet is properly configured for this functionality.


478-486: SessionSpec creation logic is well-implemented.

The SessionSpec configuration correctly calculates expiration time using Unix timestamp, provides sensible defaults for empty policy lists, and generates a unique UID when not provided. The IsWildcard flag appropriately maps to the grantFullPermissions parameter.


488-492: Transaction execution flow follows established patterns.

The implementation properly retrieves the user address, generates EIP-712 signatures with the MinimalAccount domain, creates the contract instance using the updated ABI constant, and executes the transaction. The hardcoded values "MinimalAccount" and "1" appear consistent with the EIP-7702 standard implementation.

✨ Finishing Touches
  • 📝 Generate Docstrings

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

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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs (1)

453-470: Well-implemented session key creation with proper validation and simulation.

The CreateSessionKey method implementation is solid with good practices:

Strengths:

  • Proper execution mode validation (EIP7702/EIP7702Sponsored only)
  • EIP-712 signature generation for security
  • Transaction simulation before execution for safety
  • Appropriate error handling with descriptive exception message

Minor suggestions for improvement:

Consider adding parameter validation for the SessionSpec:

 public async Task<ThirdwebTransactionReceipt> CreateSessionKey(BigInteger chainId, SessionSpec sessionKeyParams)
 {
+    if (sessionKeyParams == null)
+    {
+        throw new ArgumentNullException(nameof(sessionKeyParams));
+    }
+    if (chainId <= 0)
+    {
+        throw new ArgumentException("Chain ID must be greater than 0.", nameof(chainId));
+    }
+
     if (this.ExecutionMode is not ExecutionMode.EIP7702 and not ExecutionMode.EIP7702Sponsored)
     {
         throw new InvalidOperationException("CreateSessionKey is only supported for EIP7702 and EIP7702Sponsored execution modes.");
     }

Also consider removing the console logging on line 467 in production code or making it configurable:

-    Console.WriteLine($"Simulated session key creation transaction: {result}");
+    // Consider using a proper logging framework instead of Console.WriteLine
Thirdweb.Console/Program.cs (1)

363-405: Good demonstration of EIP-7702 session key functionality with proper workflow.

The activated console code demonstrates the full EIP-7702 workflow effectively:

Strengths:

  • Proper chain setup (Sepolia testnet)
  • Correct execution mode (EIP7702Sponsored)
  • Logical workflow: connect → transfer (to trigger upgrade) → verify delegation → create session key
  • Good use of ENS resolution for addresses
  • Proper session key configuration with expiration and policies

Consider these improvements:

  1. Add error handling around OAuth login:
 if (!await smartEoa.IsConnected())
 {
-    _ = await smartEoa.LoginWithOauth(
-        isMobile: false,
-        (url) =>
-        {
-            var psi = new ProcessStartInfo { FileName = url, UseShellExecute = true };
-            _ = Process.Start(psi);
-        }
-    );
+    try
+    {
+        _ = await smartEoa.LoginWithOauth(
+            isMobile: false,
+            (url) =>
+            {
+                var psi = new ProcessStartInfo { FileName = url, UseShellExecute = true };
+                _ = Process.Start(psi);
+            }
+        );
+    }
+    catch (Exception ex)
+    {
+        Console.WriteLine($"OAuth login failed: {ex.Message}");
+        return;
+    }
 }
  1. Consider making the session key UID more unique:
-        Uid = "my-session-key-uid".HashMessage().HexToBytes()
+        Uid = $"session-{DateTime.UtcNow:yyyyMMddHHmmss}-{Guid.NewGuid()}".HashMessage().HexToBytes()
  1. Add validation for ENS resolution:
+var vitalikAddress = await Utils.GetAddressFromENS(client, "vitalik.eth");
+if (string.IsNullOrEmpty(vitalikAddress))
+{
+    Console.WriteLine("Failed to resolve vitalik.eth ENS name");
+    return;
+}
+
-var receipt = await smartEoa.Transfer(chainId: chain, toAddress: await Utils.GetAddressFromENS(client, "vitalik.eth"), weiAmount: 0);
+var receipt = await smartEoa.Transfer(chainId: chain, toAddress: vitalikAddress, weiAmount: 0);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b6541d6 and 91119f7.

📒 Files selected for processing (3)
  • Thirdweb.Console/Program.cs (1 hunks)
  • Thirdweb/Thirdweb.Utils/Constants.cs (1 hunks)
  • Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test-cov
🔇 Additional comments (1)
Thirdweb/Thirdweb.Utils/Constants.cs (1)

38-38: Verify updated minimal account contract address.

Please confirm that the new address matches the deployed EIP-7702 minimal account contract on your target network and is correctly checksummed (EIP-55). Update any related documentation or tests to reference this value.

@codecov-commenter
Copy link

codecov-commenter commented Jun 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.84%. Comparing base (b6541d6) to head (f989fe0).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #150      +/-   ##
==========================================
- Coverage   60.94%   60.84%   -0.11%     
==========================================
  Files          41       41              
  Lines        6563     6563              
  Branches      832      832              
==========================================
- Hits         4000     3993       -7     
- Misses       2376     2382       +6     
- Partials      187      188       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 06ee56b and 6388ff4.

📒 Files selected for processing (2)
  • Thirdweb.Console/Program.cs (2 hunks)
  • Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Thirdweb.Console/Program.cs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-test-cov
🔇 Additional comments (3)
Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs (3)

453-461: Method signature looks comprehensive and well-structured.

The asynchronous method signature properly defines all necessary parameters with sensible defaults. The return type Task<ThirdwebTransactionReceipt> appropriately indicates the async nature and transaction result.


463-466: Good execution mode validation with clear error messaging.

The validation correctly restricts session key creation to EIP-7702 compatible execution modes and provides a clear error message explaining the requirement.


478-483: Verify contract method existence and EIP-712 domain parameters.

The implementation logic is well-structured, but the contract method call and signature parameters need verification to ensure compatibility.

Run the following script to verify the contract ABI contains the expected method:

#!/bin/bash
# Description: Verify that MINIMAL_ACCOUNT_7702_ABI contains the createSessionWithSig method

# Search for the createSessionWithSig method in the ABI constant
rg -A 10 -B 5 "createSessionWithSig" --type cs

Also verify that the EIP-712 domain parameters ("MinimalAccount", "1") match the actual contract implementation. The domain name and version must be consistent with the deployed contract to ensure signature validation succeeds.

@0xFirekeeper 0xFirekeeper merged commit 75f777c into main Jun 23, 2025
3 of 4 checks passed
@0xFirekeeper 0xFirekeeper deleted the firekeeper/7702-session-keys branch June 23, 2025 20:52
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.

2 participants