Commit 12180775 authored by tre's avatar tre

update the auth id for Faucet to be bytes32 instead of bytes

parent b353c11f
...@@ -57,11 +57,10 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -57,11 +57,10 @@ contract AdminFaucetAuthModuleTest is Test {
* @notice Get signature as a bytes blob. * @notice Get signature as a bytes blob.
* *
*/ */
function _getSignature(uint256 _signingPrivateKey, bytes32 _digest) function _getSignature(
internal uint256 _signingPrivateKey,
pure bytes32 _digest
returns (bytes memory) ) internal pure returns (bytes memory) {
{
(uint8 v, bytes32 r, bytes32 s) = vm.sign(_signingPrivateKey, _digest); (uint8 v, bytes32 r, bytes32 s) = vm.sign(_signingPrivateKey, _digest);
bytes memory signature = abi.encodePacked(r, s, v); bytes memory signature = abi.encodePacked(r, s, v);
...@@ -80,7 +79,7 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -80,7 +79,7 @@ contract AdminFaucetAuthModuleTest is Test {
uint256 _eip712Chainid, uint256 _eip712Chainid,
address _eip712VerifyingContract, address _eip712VerifyingContract,
address recipient, address recipient,
bytes memory id, bytes32 id,
bytes32 nonce bytes32 nonce
) internal view returns (bytes memory) { ) internal view returns (bytes memory) {
AdminFaucetAuthModule.Proof memory proof = AdminFaucetAuthModule.Proof( AdminFaucetAuthModule.Proof memory proof = AdminFaucetAuthModule.Proof(
...@@ -114,7 +113,7 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -114,7 +113,7 @@ contract AdminFaucetAuthModuleTest is Test {
block.chainid, block.chainid,
address(adminFam), address(adminFam),
fundsReceiver, fundsReceiver,
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
nonce nonce
); );
...@@ -122,7 +121,7 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -122,7 +121,7 @@ contract AdminFaucetAuthModuleTest is Test {
assertEq( assertEq(
adminFam.verify( adminFam.verify(
Faucet.DripParameters(payable(fundsReceiver), nonce), Faucet.DripParameters(payable(fundsReceiver), nonce),
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
proof proof
), ),
true true
...@@ -142,7 +141,7 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -142,7 +141,7 @@ contract AdminFaucetAuthModuleTest is Test {
block.chainid, block.chainid,
address(adminFam), address(adminFam),
fundsReceiver, fundsReceiver,
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
nonce nonce
); );
...@@ -150,7 +149,7 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -150,7 +149,7 @@ contract AdminFaucetAuthModuleTest is Test {
assertEq( assertEq(
adminFam.verify( adminFam.verify(
Faucet.DripParameters(payable(fundsReceiver), nonce), Faucet.DripParameters(payable(fundsReceiver), nonce),
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
proof proof
), ),
false false
...@@ -172,7 +171,7 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -172,7 +171,7 @@ contract AdminFaucetAuthModuleTest is Test {
block.chainid, block.chainid,
address(adminFam), address(adminFam),
fundsReceiver, fundsReceiver,
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
nonce nonce
); );
...@@ -180,7 +179,7 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -180,7 +179,7 @@ contract AdminFaucetAuthModuleTest is Test {
assertEq( assertEq(
adminFam.verify( adminFam.verify(
Faucet.DripParameters(payable(fundsReceiver), nonce), Faucet.DripParameters(payable(fundsReceiver), nonce),
abi.encodePacked(randomAddress), keccak256(abi.encodePacked(randomAddress)),
proof proof
), ),
false false
......
...@@ -16,7 +16,7 @@ contract FaucetHelper { ...@@ -16,7 +16,7 @@ contract FaucetHelper {
* @notice EIP712 typehash for the Proof type. * @notice EIP712 typehash for the Proof type.
*/ */
bytes32 public constant PROOF_TYPEHASH = bytes32 public constant PROOF_TYPEHASH =
keccak256("Proof(address recipient,bytes32 nonce,bytes id)"); keccak256("Proof(address recipient,bytes32 nonce,bytes32 id)");
/** /**
* @notice EIP712 typehash for the EIP712Domain type that is included as part of the signature. * @notice EIP712 typehash for the EIP712Domain type that is included as part of the signature.
...@@ -48,11 +48,9 @@ contract FaucetHelper { ...@@ -48,11 +48,9 @@ contract FaucetHelper {
* *
* @return EIP-712 typed struct hash. * @return EIP-712 typed struct hash.
*/ */
function getProofStructHash(AdminFaucetAuthModule.Proof memory _proof) function getProofStructHash(
public AdminFaucetAuthModule.Proof memory _proof
pure ) public pure returns (bytes32) {
returns (bytes32)
{
return keccak256(abi.encode(PROOF_TYPEHASH, _proof.recipient, _proof.nonce, _proof.id)); return keccak256(abi.encode(PROOF_TYPEHASH, _proof.recipient, _proof.nonce, _proof.id));
} }
......
...@@ -31,7 +31,7 @@ contract Faucet { ...@@ -31,7 +31,7 @@ contract Faucet {
*/ */
event Drip( event Drip(
string indexed authModule, string indexed authModule,
bytes indexed userId, bytes32 indexed userId,
uint256 amount, uint256 amount,
address indexed recipient address indexed recipient
); );
...@@ -49,7 +49,7 @@ contract Faucet { ...@@ -49,7 +49,7 @@ contract Faucet {
*/ */
struct AuthParameters { struct AuthParameters {
IFaucetAuthModule module; IFaucetAuthModule module;
bytes id; bytes32 id;
bytes proof; bytes proof;
} }
...@@ -76,12 +76,12 @@ contract Faucet { ...@@ -76,12 +76,12 @@ contract Faucet {
/** /**
* @notice Mapping of authentication IDs to the next timestamp at which they can be used. * @notice Mapping of authentication IDs to the next timestamp at which they can be used.
*/ */
mapping(IFaucetAuthModule => mapping(bytes => uint256)) public timeouts; mapping(IFaucetAuthModule => mapping(bytes32 => uint256)) public timeouts;
/** /**
* @notice Maps from id to nonces to whether or not they have been used. * @notice Maps from id to nonces to whether or not they have been used.
*/ */
mapping(bytes => mapping(bytes32 => bool)) public nonces; mapping(bytes32 => mapping(bytes32 => bool)) public nonces;
/** /**
* @notice Modifier that makes a function admin priviledged. * @notice Modifier that makes a function admin priviledged.
......
...@@ -21,7 +21,7 @@ contract AdminFaucetAuthModule is IFaucetAuthModule, EIP712 { ...@@ -21,7 +21,7 @@ contract AdminFaucetAuthModule is IFaucetAuthModule, EIP712 {
* @notice EIP712 typehash for the Proof type. * @notice EIP712 typehash for the Proof type.
*/ */
bytes32 public constant PROOF_TYPEHASH = bytes32 public constant PROOF_TYPEHASH =
keccak256("Proof(address recipient,bytes32 nonce,bytes id)"); keccak256("Proof(address recipient,bytes32 nonce,bytes32 id)");
/** /**
* @notice Struct that represents a proof that verifies the admin. * @notice Struct that represents a proof that verifies the admin.
...@@ -33,7 +33,7 @@ contract AdminFaucetAuthModule is IFaucetAuthModule, EIP712 { ...@@ -33,7 +33,7 @@ contract AdminFaucetAuthModule is IFaucetAuthModule, EIP712 {
struct Proof { struct Proof {
address recipient; address recipient;
bytes32 nonce; bytes32 nonce;
bytes id; bytes32 id;
} }
/** /**
...@@ -54,7 +54,7 @@ contract AdminFaucetAuthModule is IFaucetAuthModule, EIP712 { ...@@ -54,7 +54,7 @@ contract AdminFaucetAuthModule is IFaucetAuthModule, EIP712 {
*/ */
function verify( function verify(
Faucet.DripParameters memory _params, Faucet.DripParameters memory _params,
bytes memory _id, bytes32 _id,
bytes memory _proof bytes memory _proof
) external view returns (bool) { ) external view returns (bool) {
// Generate a EIP712 typed data hash to compare against the proof. // Generate a EIP712 typed data hash to compare against the proof.
......
...@@ -17,7 +17,7 @@ interface IFaucetAuthModule { ...@@ -17,7 +17,7 @@ interface IFaucetAuthModule {
*/ */
function verify( function verify(
Faucet.DripParameters memory _params, Faucet.DripParameters memory _params,
bytes memory _id, bytes32 _id,
bytes memory _proof bytes memory _proof
) external view returns (bool); ) external view returns (bool);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment