Commit 5ff1f55c authored by Andreas Bigger's avatar Andreas Bigger

Port faucet periphery contracts to triple slash natspec styling

parent 0ae1166b
AdminFaucetAuthModuleTest:test_adminProof_verify_succeeds() (gas: 57577) AdminFaucetAuthModuleTest:test_adminProof_verify_succeeds() (gas: 57573)
AdminFaucetAuthModuleTest:test_nonAdminProof_verify_succeeds() (gas: 59050) AdminFaucetAuthModuleTest:test_nonAdminProof_verify_succeeds() (gas: 59050)
AdminFaucetAuthModuleTest:test_proofWithWrongId_verify_succeeds() (gas: 60673) AdminFaucetAuthModuleTest:test_proofWithWrongId_verify_succeeds() (gas: 60673)
AssetReceiverTest:test_constructor_succeeds() (gas: 9696) AssetReceiverTest:test_constructor_succeeds() (gas: 9696)
...@@ -70,14 +70,14 @@ Drippie_Test:test_status_unauthorized_reverts() (gas: 167344) ...@@ -70,14 +70,14 @@ Drippie_Test:test_status_unauthorized_reverts() (gas: 167344)
Drippie_Test:test_trigger_oneFunction_succeeds() (gas: 338143) Drippie_Test:test_trigger_oneFunction_succeeds() (gas: 338143)
Drippie_Test:test_trigger_twoFunctions_succeeds() (gas: 491870) Drippie_Test:test_trigger_twoFunctions_succeeds() (gas: 491870)
Drippie_Test:test_twice_inOneInterval_reverts() (gas: 303767) Drippie_Test:test_twice_inOneInterval_reverts() (gas: 303767)
FaucetTest:test_authAdmin_drip_succeeds() (gas: 366111) FaucetTest:test_authAdmin_drip_succeeds() (gas: 366107)
FaucetTest:test_drip_afterTimeout_succeeds() (gas: 447899) FaucetTest:test_drip_afterTimeout_succeeds() (gas: 447891)
FaucetTest:test_drip_beforeTimeout_reverts() (gas: 378888) FaucetTest:test_drip_beforeTimeout_reverts() (gas: 378884)
FaucetTest:test_drip_disabledModule_reverts() (gas: 352405) FaucetTest:test_drip_disabledModule_reverts() (gas: 352401)
FaucetTest:test_drip_emitsEvent_succeeds() (gas: 369165) FaucetTest:test_drip_emitsEvent_succeeds() (gas: 369161)
FaucetTest:test_drip_githubSendsCorrectAmount_succeeds() (gas: 366611) FaucetTest:test_drip_githubSendsCorrectAmount_succeeds() (gas: 366607)
FaucetTest:test_drip_optimistNftSendsCorrectAmount_succeeds() (gas: 366555) FaucetTest:test_drip_optimistNftSendsCorrectAmount_succeeds() (gas: 366551)
FaucetTest:test_drip_preventsReplayAttacks_succeeds() (gas: 369218) FaucetTest:test_drip_preventsReplayAttacks_succeeds() (gas: 369214)
FaucetTest:test_initialize_succeeds() (gas: 7626) FaucetTest:test_initialize_succeeds() (gas: 7626)
FaucetTest:test_nonAdmin_drip_fails() (gas: 262520) FaucetTest:test_nonAdmin_drip_fails() (gas: 262520)
FaucetTest:test_receive_succeeds() (gas: 17401) FaucetTest:test_receive_succeeds() (gas: 17401)
......
...@@ -3,32 +3,23 @@ pragma solidity 0.8.15; ...@@ -3,32 +3,23 @@ pragma solidity 0.8.15;
import { IFaucetAuthModule } from "./authmodules/IFaucetAuthModule.sol"; import { IFaucetAuthModule } from "./authmodules/IFaucetAuthModule.sol";
/** /// @title SafeSend
* @title SafeSend /// @notice Sends ETH to a recipient account without triggering any code.
* @notice Sends ETH to a recipient account without triggering any code.
*/
contract SafeSend { contract SafeSend {
/** /// @param _recipient Account to send ETH to.
* @param _recipient Account to send ETH to.
*/
constructor(address payable _recipient) payable { constructor(address payable _recipient) payable {
selfdestruct(_recipient); selfdestruct(_recipient);
} }
} }
/** /// @title Faucet
* @title Faucet /// @notice Faucet contract that drips ETH to users.
* @notice Faucet contract that drips ETH to users.
*/
contract Faucet { contract Faucet {
/** /// @notice Emitted on each drip.
* @notice Emitted on each drip. /// @param authModule The type of authentication that was used for verifying the drip.
* /// @param userId The id of the user that requested the drip.
* @param authModule The type of authentication that was used for verifying the drip. /// @param amount The amount of funds sent.
* @param userId The id of the user that requested the drip. /// @param recipient The recipient of the drip.
* @param amount The amount of funds sent.
* @param recipient The recipient of the drip.
*/
event Drip( event Drip(
string indexed authModule, string indexed authModule,
bytes32 indexed userId, bytes32 indexed userId,
...@@ -36,26 +27,20 @@ contract Faucet { ...@@ -36,26 +27,20 @@ contract Faucet {
address indexed recipient address indexed recipient
); );
/** /// @notice Parameters for a drip.
* @notice Parameters for a drip.
*/
struct DripParameters { struct DripParameters {
address payable recipient; address payable recipient;
bytes32 nonce; bytes32 nonce;
} }
/** /// @notice Parameters for authentication.
* @notice Parameters for authentication.
*/
struct AuthParameters { struct AuthParameters {
IFaucetAuthModule module; IFaucetAuthModule module;
bytes32 id; bytes32 id;
bytes proof; bytes proof;
} }
/** /// @notice Configuration for an authentication module.
* @notice Configuration for an authentication module.
*/
struct ModuleConfig { struct ModuleConfig {
string name; string name;
bool enabled; bool enabled;
...@@ -63,74 +48,51 @@ contract Faucet { ...@@ -63,74 +48,51 @@ contract Faucet {
uint256 amount; uint256 amount;
} }
/** /// @notice Admin address that can configure the faucet.
* @notice Admin address that can configure the faucet.
*/
address public immutable ADMIN; address public immutable ADMIN;
/** /// @notice Mapping of authentication modules to their configurations.
* @notice Mapping of authentication modules to their configurations.
*/
mapping(IFaucetAuthModule => ModuleConfig) public modules; mapping(IFaucetAuthModule => ModuleConfig) public modules;
/** /// @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(bytes32 => 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(bytes32 => 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.
*/
modifier priviledged() { modifier priviledged() {
require(msg.sender == ADMIN, "Faucet: function can only be called by admin"); require(msg.sender == ADMIN, "Faucet: function can only be called by admin");
_; _;
} }
/** /// @param _admin Admin address that can configure the faucet.
* @param _admin Admin address that can configure the faucet.
*/
constructor(address _admin) { constructor(address _admin) {
ADMIN = _admin; ADMIN = _admin;
} }
/** /// @notice Allows users to donate ETH to this contract.
* @notice Allows users to donate ETH to this contract.
*/
receive() external payable { receive() external payable {
// Thank you! // Thank you!
} }
/** /// @notice Allows the admin to withdraw funds.
* @notice Allows the admin to withdraw funds. /// @param _recipient Address to receive the funds.
* /// @param _amount Amount of ETH in wei to withdraw.
* @param _recipient Address to receive the funds.
* @param _amount Amount of ETH in wei to withdraw.
*/
function withdraw(address payable _recipient, uint256 _amount) public priviledged { function withdraw(address payable _recipient, uint256 _amount) public priviledged {
new SafeSend{ value: _amount }(_recipient); new SafeSend{ value: _amount }(_recipient);
} }
/** /// @notice Allows the admin to configure an authentication module.
* @notice Allows the admin to configure an authentication module. /// @param _module Authentication module to configure.
* /// @param _config Configuration to set for the module.
* @param _module Authentication module to configure.
* @param _config Configuration to set for the module.
*/
function configure(IFaucetAuthModule _module, ModuleConfig memory _config) public priviledged { function configure(IFaucetAuthModule _module, ModuleConfig memory _config) public priviledged {
modules[_module] = _config; modules[_module] = _config;
} }
/** /// @notice Drips ETH to a recipient account.
* @notice Drips ETH to a recipient account. /// @param _params Drip parameters.
* /// @param _auth Authentication parameters.
* @param _params Drip parameters.
* @param _auth Authentication parameters.
*/
function drip(DripParameters memory _params, AuthParameters memory _auth) public { function drip(DripParameters memory _params, AuthParameters memory _auth) public {
// Grab the module config once. // Grab the module config once.
ModuleConfig memory config = modules[_auth.module]; ModuleConfig memory config = modules[_auth.module];
......
...@@ -6,41 +6,30 @@ import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/Sig ...@@ -6,41 +6,30 @@ import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/Sig
import { IFaucetAuthModule } from "./IFaucetAuthModule.sol"; import { IFaucetAuthModule } from "./IFaucetAuthModule.sol";
import { Faucet } from "../Faucet.sol"; import { Faucet } from "../Faucet.sol";
/** /// @title AdminFaucetAuthModule
* @title AdminFaucetAuthModule /// @notice FaucetAuthModule that allows an admin to sign off on a given faucet drip. Takes an admin
* @notice FaucetAuthModule that allows an admin to sign off on a given faucet drip. Takes an admin /// as the constructor argument.
* as the constructor argument.
*/
contract AdminFaucetAuthModule is IFaucetAuthModule, EIP712 { contract AdminFaucetAuthModule is IFaucetAuthModule, EIP712 {
/** /// @notice Admin address that can sign off on drips.
* @notice Admin address that can sign off on drips.
*/
address public immutable ADMIN; address public immutable ADMIN;
/** /// @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,bytes32 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. /// @custom:field recipient Address that will be receiving the faucet funds.
* /// @custom:field nonce Pseudorandom nonce to prevent replay attacks.
* @custom:field recipient Address that will be receiving the faucet funds. /// @custom:field id id for the user requesting the faucet funds.
* @custom:field nonce Pseudorandom nonce to prevent replay attacks.
* @custom:field id id for the user requesting the faucet funds.
*/
struct Proof { struct Proof {
address recipient; address recipient;
bytes32 nonce; bytes32 nonce;
bytes32 id; bytes32 id;
} }
/** /// @param _admin Admin address that can sign off on drips.
* @param _admin Admin address that can sign off on drips. /// @param _name Contract name.
* @param _name Contract name. /// @param _version The current major version of the signing domain.
* @param _version The current major version of the signing domain.
*/
constructor( constructor(
address _admin, address _admin,
string memory _name, string memory _name,
...@@ -49,22 +38,19 @@ contract AdminFaucetAuthModule is IFaucetAuthModule, EIP712 { ...@@ -49,22 +38,19 @@ contract AdminFaucetAuthModule is IFaucetAuthModule, EIP712 {
ADMIN = _admin; ADMIN = _admin;
} }
/** /// @inheritdoc IFaucetAuthModule
* @inheritdoc IFaucetAuthModule
*/
function verify( function verify(
Faucet.DripParameters memory _params, Faucet.DripParameters memory _params,
bytes32 _id, bytes32 _id,
bytes memory _proof bytes memory _proof
) external view returns (bool) { ) external view returns (bool valid_) {
// Generate a EIP712 typed data hash to compare against the proof. // Generate a EIP712 typed data hash to compare against the proof.
return valid_ = SignatureChecker.isValidSignatureNow(
SignatureChecker.isValidSignatureNow( ADMIN,
ADMIN, _hashTypedDataV4(
_hashTypedDataV4( keccak256(abi.encode(PROOF_TYPEHASH, _params.recipient, _params.nonce, _id))
keccak256(abi.encode(PROOF_TYPEHASH, _params.recipient, _params.nonce, _id)) ),
), _proof
_proof );
);
} }
} }
...@@ -3,18 +3,14 @@ pragma solidity 0.8.15; ...@@ -3,18 +3,14 @@ pragma solidity 0.8.15;
import { Faucet } from "../Faucet.sol"; import { Faucet } from "../Faucet.sol";
/** /// @title IFaucetAuthModule
* @title IFaucetAuthModule /// @notice Interface for faucet authentication modules.
* @notice Interface for faucet authentication modules.
*/
interface IFaucetAuthModule { interface IFaucetAuthModule {
/** /// @notice Verifies that the given drip parameters are valid.
* @notice Verifies that the given drip parameters are valid. /// @param _params Drip parameters to verify.
* /// @param _id Authentication ID to verify.
* @param _params Drip parameters to verify. /// @param _proof Authentication proof to verify.
* @param _id Authentication ID to verify. /// @return valid_ True if the drip parameters are valid.
* @param _proof Authentication proof to verify.
*/
function verify( function verify(
Faucet.DripParameters memory _params, Faucet.DripParameters memory _params,
bytes32 _id, bytes32 _id,
......
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