Skip to content

Sequence diagram for merkle-based signature verification in IthacaAccount #49

Description

@Dargon789

Reviewer's Guide

Adds Merkle tree–based signature verification support to IthacaAccount, including a new wrapped-signature format, corresponding tests, and CI workflow tweaks to limit test scope, plus a version bump.

Sequence diagram for merkle-based signature verification in IthacaAccount

sequenceDiagram
    actor ExternalCaller
    participant IthacaAccount
    participant MerkleProofLib
    participant EfficientHashLib
    participant ECDSA

    ExternalCaller->>IthacaAccount: unwrapAndValidateSignature(digest, signature)
    activate IthacaAccount

    IthacaAccount->>IthacaAccount: check signature.length
    alt signature.length == 65
        IthacaAccount->>ECDSA: recoverCalldata(digest, signature)
        ECDSA-->>IthacaAccount: signer
        IthacaAccount-->>ExternalCaller: (signer == IthacaAccount, 0)
    else wrapped signature
        IthacaAccount->>IthacaAccount: parse keyHash, prehash, merkle flags via LibBytes
        alt prehash flag set
            IthacaAccount->>EfficientHashLib: sha2(digest)
            EfficientHashLib-->>IthacaAccount: newDigest
            IthacaAccount->>IthacaAccount: digest = newDigest
        end
        alt merkle flag set
            IthacaAccount->>IthacaAccount: _verifyMerkleSig(digest, innerSignature)
            activate IthacaAccount
            IthacaAccount->>IthacaAccount: decode proof, root, rootSig from calldata
            IthacaAccount->>MerkleProofLib: verifyCalldata(proof, root, digest)
            MerkleProofLib-->>IthacaAccount: isLeafInTree
            alt isLeafInTree
                IthacaAccount->>IthacaAccount: unwrapAndValidateSignature(root, rootSig)
                IthacaAccount-->>IthacaAccount: (isValid, keyHash)
                IthacaAccount-->>ExternalCaller: (isValid, keyHash)
            else
                IthacaAccount-->>ExternalCaller: (false, 0)
            end
        else standard wrapped signature flow
            IthacaAccount->>IthacaAccount: key = getKey(keyHash)
            IthacaAccount->>IthacaAccount: validate innerSignature with key
            IthacaAccount-->>ExternalCaller: (isValid, keyHash)
        end
    end
    deactivate IthacaAccount
Loading

Updated class diagram for IthacaAccount merkle signature support

classDiagram
    class IthacaAccount {
        +unwrapAndValidateSignature(bytes32 digest, bytes signature) bool isValid
        +unwrapAndValidateSignature(bytes32 digest, bytes signature) bytes32 keyHash
        -_verifyMerkleSig(bytes32 digest, bytes signature) bool isValid
        -_verifyMerkleSig(bytes32 digest, bytes signature) bytes32 keyHash
        +getKey(bytes32 keyHash) Key
        +_hashTypedData(bytes32 structHash) bytes32
        +_hashTypedDataSansChainId(bytes32 structHash) bytes32
        +getEIP712NameAndVersion() string name
        +getEIP712NameAndVersion() string version
        <<EIP712>>
        <<GuardedExecutor>>
    }

    class MerkleProofLib {
        +verifyCalldata(bytes32[] proof, bytes32 root, bytes32 leaf) bool
    }

    class LibBytes {
        +loadCalldata(bytes data, uint256 index) bytes32
        +truncatedCalldata(bytes data, uint256 newLength) bytes
    }

    class EfficientHashLib {
        +sha2(bytes32 input) bytes32
    }

    class ECDSA {
        +recoverCalldata(bytes32 digest, bytes signature) address
    }

    class Key {
        +address signer
        +bool isValid
    }

    IthacaAccount --> MerkleProofLib : uses
    IthacaAccount --> LibBytes : parses wrappedSignature
    IthacaAccount --> EfficientHashLib : optionalPrehash
    IthacaAccount --> ECDSA : eip191Recover
    IthacaAccount --> Key : authorizationData
Loading

File-Level Changes

Change Details Files
Introduce Merkle tree–based signature verification path and extend wrapped-signature format with a merkle flag.
  • Add MerkleProofLib dependency and internal _verifyMerkleSig helper that decodes proof, root, and root signature from calldata and verifies membership before validating the root signature
  • Extend unwrapAndValidateSignature encoding to abi.encode(innerSignature, keyHash, bool(prehash), bool(merkle)) and adjust parsing logic to read the extra flag and dispatch to _verifyMerkleSig when set
  • Keep existing direct key validation path intact, only gating the new behavior on the merkle flag
  • Bump EIP712 version string from 0.5.10 to 0.5.11 to reflect the new behavior
src/IthacaAccount.sol
Update test helpers and call sites to use the new 4-field wrapped-signature encoding and add dedicated Merkle signature coverage.
  • Append a merkle flag byte (set to 0) to all helper-generated signatures in Base.t.sol and to synthetic signatures in gas estimation / orchestrator / simulate tests so they conform to the new encoding
  • Add testMerkleSignature fuzz test that builds a random Merkle tree using murky/Merkle, generates a proof for a random leaf, and validates expected behavior for valid proofs, invalid digests, tampered proofs, and wrong roots
  • Adjust Account tests to ignore unused eip712Domain fields now that only verifyingContract is needed for domain hashing
test/Base.t.sol
test/Account.t.sol
test/Orchestrator.t.sol
test/SimulateExecute.t.sol
Tighten CI workflow tests to exclude UpgradeTests and add a CNAME file for GitHub Pages configuration.
  • Change CI forge test command to skip UpgradeTests contract to speed up or avoid flaky upgrade tests in standard CI runs
  • Add CNAME file at repository root, likely to configure a custom domain for GitHub Pages or related hosting
.github/workflows/ci.yaml
CNAME

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Originally posted by @sourcery-ai[bot] in #41 (comment)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdocumentationImprovements or additions to documentationduplicateThis issue or pull request already existsenhancementNew feature or requestgood first issueGood for newcomersinvalidThis doesn't seem rightquestionFurther information is requested

Projects

Status
Backlog
Status
Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions