Skip to content
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

# ✨ Feature Request: Implement Offset Helper with Matrix Index Support #62

Open
1 task done
joepegler opened this issue Oct 1, 2024 · 0 comments
Open
1 task done
Assignees
Labels
enhancement New feature or request

Comments

@joepegler
Copy link
Collaborator

joepegler commented Oct 1, 2024

What

Implement an offset helper that allows users to specify argument locations using a string format "number.number.number" (e.g., "0.1.3") to represent matrix indices. Replace the current offsetIndex in the Rule type with offsetPath.

Why

  • Provide more flexibility in specifying argument locations, especially for complex data structures like matrices and nested arrays
  • Simplify the process of calculating offsets for users by handling the multiplication by 32 internally
  • Improve the accuracy of offset calculations for various data types, including arrays and bytes
  • Align with Solidity's ABI specification for argument encoding

How

  1. Update the Rule type in the smart sessions module:

    type Rule = {
      // ... other properties
      offsetPath: string // Format: "number.number.number"
    }
  2. Implement an offset helper function:

    function calculateOffset(functionSignature: string, offsetPath: string): number {
      // Parse the function signature
      // Calculate the base offset based on the argument position
      // Handle special cases for arrays, bytes, and nested structures
      // Apply the offsetPath to navigate through nested structures
      // Return the final offset (always a multiple of 32)
    }
  3. Utilize viem's encodeFunctionData and decodeFunctionData methods to assist in parsing function signatures and argument structures

  4. Implement special handling for arrays and bytes as per the Solidity ABI specification

  5. Add validation for the offsetPath format to ensure it's correctly formatted

  6. Update existing code that uses offsetIndex to use the new offsetPath and calculateOffset function

  7. Create unit tests covering various scenarios:

    • Simple arguments
    • Arrays
    • Nested structures
    • Edge cases (e.g., very long arrays, complex nested structures)
  8. Update documentation to explain the new offsetPath format and provide examples of its usage

  9. Create a migration guide for users updating from offsetIndex to offsetPath

References


  • I agree to follow this project's Code of Conduct.
@joepegler joepegler added the enhancement New feature or request label Oct 1, 2024
@joepegler joepegler self-assigned this Oct 1, 2024
@joepegler joepegler changed the title feat: offset helper for smart sessions # ✨ Feature Request: Implement Offset Helper with Matrix Index Support Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant