Skip to content

Conversation

@MukeshVermaLegit
Copy link

Description

Added a new Yul-based wrapper for ECDSA signature recovery under utils/ECDSA.sol.
This implementation focuses on gas efficiency, malformed signature tolerance, and low-level assembly optimization compared to OpenZeppelin’s version.

The file exposes a single function:

  • recover(bytes32 hash, bytes memory sig):
    • Returns the recovered address from the signature.
    • Returns address(0) on invalid or malleable input.
    • Uses direct Yul logic to reduce overhead by ~700 gas.

Also included comprehensive tests in test/utils/ECDSAT.t.sol to validate:

  • Signature correctness
  • Malleability rejection (s > n/2)
  • Fallback for malformed or incorrect signatures

Checklist

  • Ran forge snapshot
  • Ran npm run lint
  • Ran forge test — All tests passing with custom Yul and OpenZeppelin comparisons.
@MukeshVermaLegit
Copy link
Author

Gas Comparison vs OpenZeppelin ECDSA:

Test OpenZeppelin Gas This PR (Yul) Savings
testMalleableSignature 9,295 6,746 ~2,549
testRecoverValidSignature 20,283 7,037 ~13,246
`testWrongSignatureReturnsZero 12,337 1,444 ~10,893
testInvalidSigLength 6,295 408 ~5,887

Total savings across scenarios: Up to ~13k gas per signature recovery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant