PopPunkLLC / gaslite-core

Gaslite's Highly Optimized Smart Contracts
MIT License
180 stars 31 forks source link

Use Solady ECDSA in `Claim:claimWithSignature` (calldata signature) #14

Closed 0xpolarzero closed 7 months ago

0xpolarzero commented 7 months ago

Update OpenZeppelin ECDSA to Solady.

  1. Use ECDSA.toEthSignedMessageHash to retrieve the prefixed hash.
  2. Use ECDSA.recoverCalldata with the signature as calldata to recover the signer.

It saves a total of 552 gas on each call to claimWithSignature.

- bytes32 prefixedHash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", messageHash));
- address recoveredSigner = ECDSA.recover(prefixedHash, _signature);
# saves 93 gas
+ bytes32 prefixedHash = ECDSA.toEthSignedMessageHash(messageHash);
# saves 459 gas
+ address recoveredSigner = ECDSA.recoverCalldata(prefixedHash, _signature);