Skip to content

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

@joepegler

Description

@joepegler

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions