-
Notifications
You must be signed in to change notification settings - Fork 65
Add coupon discount validator #96
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ef29cd4
lint
stevieraykatz b0983e9
Remove unused state var
stevieraykatz 79777e3
Add unit tests, add address as salt to signature hash
stevieraykatz 010ada7
lint
stevieraykatz c0a7a6d
Fix natspec
stevieraykatz 30018dc
Add zero address checks
stevieraykatz c8718fc
Remove redundant owner check
stevieraykatz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import {ECDSA} from "solady/utils/ECDSA.sol"; | ||
import {Ownable} from "solady/auth/Ownable.sol"; | ||
|
||
import {IDiscountValidator} from "src/L2/interface/IDiscountValidator.sol"; | ||
|
||
/// @title Discount Validator for: Coinbase Attestation Validator | ||
/// | ||
/// @notice Implements a two step validation schema for verifying coinbase attestations | ||
/// 1. Verify that the wallet has an active Coinbase Verification for the stored `schemaID`. | ||
/// 2. Signature verification to valiate signatures from the Coinbase sybil resistance service. | ||
/// https://github.com/coinbase/verifications | ||
/// | ||
/// @author Coinbase (https://github.com/base-org/usernames) | ||
contract CouponDiscountValidator is Ownable, IDiscountValidator { | ||
/// @dev The attestation service signer. | ||
address signer; | ||
|
||
/// @notice Thrown when the signature expiry date >= block.timestamp. | ||
error SignatureExpired(); | ||
|
||
/// @notice Attestation Validator constructor | ||
/// | ||
/// @param owner_ The permissioned `owner` in the `Ownable` context. | ||
/// @param signer_ The off-chain signer of the Coinbase sybil resistance service. | ||
constructor(address owner_, address signer_) { | ||
_initializeOwner(owner_); | ||
signer = signer_; | ||
} | ||
|
||
/// @notice Allows the owner to update the expected signer. | ||
/// | ||
/// @param signer_ The address of the new signer. | ||
function setSigner(address signer_) external onlyOwner { | ||
|
||
signer = signer_; | ||
} | ||
|
||
/// @notice Required implementation for compatibility with IDiscountValidator. | ||
/// | ||
/// @dev The data must be encoded as `abi.encode(discountClaimerAddress, expiry, signature_bytes)`. | ||
/// | ||
/// @param validationData opaque bytes for performing the validation. | ||
/// | ||
/// @return `true` if the validation data provided is determined to be valid for the specified claimer, else `false`. | ||
function isValidDiscountRegistration(address, bytes calldata validationData) external view returns (bool) { | ||
(uint64 expiry, bytes32 uuid, uint256 salt, bytes memory sig) = | ||
abi.decode(validationData, (uint64, bytes32, uint256, bytes)); | ||
if (expiry < block.timestamp) revert SignatureExpired(); | ||
|
||
address returnedSigner = ECDSA.recover(_makeSignatureHash(uuid, expiry, salt), sig); | ||
return returnedSigner == signer; | ||
} | ||
|
||
|
||
/// @notice Generates a hash for signing/verifying. | ||
/// | ||
/// @dev The message hash should be dervied by: `keccak256(abi.encode(0x1900, trustedSignerAddress, discountClaimerAddress, couponUui, claimsPerUuid, expiry, salt))`. | ||
/// Compliant with EIP-191 for `Data for intended validator`: https://eips.ethereum.org/EIPS/eip-191#version-0x00 . | ||
/// | ||
/// @param couponUuid The Uuid of the coupon. | ||
/// @param expires The date of the signature expiry. | ||
/// @param salt Unique salt for this signature. | ||
/// | ||
/// @return The EIP-191 compliant signature hash. | ||
function _makeSignatureHash(bytes32 couponUuid, uint64 expires, uint256 salt) internal view returns (bytes32) { | ||
return keccak256(abi.encodePacked(hex"1900", address(this), signer, couponUuid, expires, salt)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.