Commit 64cf3657 authored by OptimismBot's avatar OptimismBot Committed by GitHub

Merge pull request #5719 from ethereum-optimism/harry/update-faucet-contract

feat(ctp): Change the type on the auth id field of the Faucet contract to bytes32
parents ed9b67c8 59995da4
---
'@eth-optimism/contracts-periphery': patch
---
Change type for auth id on Faucet contracts from bytes to bytes32
...@@ -80,7 +80,7 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -80,7 +80,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 +114,7 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -114,7 +114,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 +122,7 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -122,7 +122,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 +142,7 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -142,7 +142,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 +150,7 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -150,7 +150,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 +172,7 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -172,7 +172,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 +180,7 @@ contract AdminFaucetAuthModuleTest is Test { ...@@ -180,7 +180,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
......
...@@ -9,7 +9,7 @@ import { FaucetHelper } from "../testing/helpers/FaucetHelper.sol"; ...@@ -9,7 +9,7 @@ import { FaucetHelper } from "../testing/helpers/FaucetHelper.sol";
contract Faucet_Initializer is Test { contract Faucet_Initializer is Test {
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
); );
...@@ -103,7 +103,7 @@ contract Faucet_Initializer is Test { ...@@ -103,7 +103,7 @@ contract Faucet_Initializer 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(
...@@ -140,14 +140,18 @@ contract FaucetTest is Faucet_Initializer { ...@@ -140,14 +140,18 @@ contract FaucetTest is Faucet_Initializer {
block.chainid, block.chainid,
address(optimistNftFam), address(optimistNftFam),
fundsReceiver, fundsReceiver,
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
nonce nonce
); );
vm.prank(nonAdmin); vm.prank(nonAdmin);
faucet.drip( faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce), Faucet.DripParameters(payable(fundsReceiver), nonce),
Faucet.AuthParameters(optimistNftFam, abi.encodePacked(fundsReceiver), signature) Faucet.AuthParameters(
optimistNftFam,
keccak256(abi.encodePacked(fundsReceiver)),
signature
)
); );
} }
...@@ -161,7 +165,7 @@ contract FaucetTest is Faucet_Initializer { ...@@ -161,7 +165,7 @@ contract FaucetTest is Faucet_Initializer {
block.chainid, block.chainid,
address(optimistNftFam), address(optimistNftFam),
fundsReceiver, fundsReceiver,
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
nonce nonce
); );
...@@ -169,7 +173,11 @@ contract FaucetTest is Faucet_Initializer { ...@@ -169,7 +173,11 @@ contract FaucetTest is Faucet_Initializer {
vm.expectRevert("Faucet: drip parameters could not be verified by security module"); vm.expectRevert("Faucet: drip parameters could not be verified by security module");
faucet.drip( faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce), Faucet.DripParameters(payable(fundsReceiver), nonce),
Faucet.AuthParameters(optimistNftFam, abi.encodePacked(fundsReceiver), signature) Faucet.AuthParameters(
optimistNftFam,
keccak256(abi.encodePacked(fundsReceiver)),
signature
)
); );
} }
...@@ -183,7 +191,7 @@ contract FaucetTest is Faucet_Initializer { ...@@ -183,7 +191,7 @@ contract FaucetTest is Faucet_Initializer {
block.chainid, block.chainid,
address(optimistNftFam), address(optimistNftFam),
fundsReceiver, fundsReceiver,
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
nonce nonce
); );
...@@ -191,7 +199,11 @@ contract FaucetTest is Faucet_Initializer { ...@@ -191,7 +199,11 @@ contract FaucetTest is Faucet_Initializer {
vm.prank(nonAdmin); vm.prank(nonAdmin);
faucet.drip( faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce), Faucet.DripParameters(payable(fundsReceiver), nonce),
Faucet.AuthParameters(optimistNftFam, abi.encodePacked(fundsReceiver), signature) Faucet.AuthParameters(
optimistNftFam,
keccak256(abi.encodePacked(fundsReceiver)),
signature
)
); );
uint256 recipientBalanceAfter = address(fundsReceiver).balance; uint256 recipientBalanceAfter = address(fundsReceiver).balance;
assertEq( assertEq(
...@@ -211,7 +223,7 @@ contract FaucetTest is Faucet_Initializer { ...@@ -211,7 +223,7 @@ contract FaucetTest is Faucet_Initializer {
block.chainid, block.chainid,
address(githubFam), address(githubFam),
fundsReceiver, fundsReceiver,
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
nonce nonce
); );
...@@ -219,7 +231,7 @@ contract FaucetTest is Faucet_Initializer { ...@@ -219,7 +231,7 @@ contract FaucetTest is Faucet_Initializer {
vm.prank(nonAdmin); vm.prank(nonAdmin);
faucet.drip( faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce), Faucet.DripParameters(payable(fundsReceiver), nonce),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature) Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature)
); );
uint256 recipientBalanceAfter = address(fundsReceiver).balance; uint256 recipientBalanceAfter = address(fundsReceiver).balance;
assertEq( assertEq(
...@@ -239,17 +251,22 @@ contract FaucetTest is Faucet_Initializer { ...@@ -239,17 +251,22 @@ contract FaucetTest is Faucet_Initializer {
block.chainid, block.chainid,
address(githubFam), address(githubFam),
fundsReceiver, fundsReceiver,
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
nonce nonce
); );
vm.expectEmit(true, true, true, true, address(faucet)); vm.expectEmit(true, true, true, true, address(faucet));
emit Drip("GithubModule", abi.encodePacked(fundsReceiver), .05 ether, fundsReceiver); emit Drip(
"GithubModule",
keccak256(abi.encodePacked(fundsReceiver)),
.05 ether,
fundsReceiver
);
vm.prank(nonAdmin); vm.prank(nonAdmin);
faucet.drip( faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce), Faucet.DripParameters(payable(fundsReceiver), nonce),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature) Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature)
); );
} }
...@@ -263,14 +280,14 @@ contract FaucetTest is Faucet_Initializer { ...@@ -263,14 +280,14 @@ contract FaucetTest is Faucet_Initializer {
block.chainid, block.chainid,
address(githubFam), address(githubFam),
fundsReceiver, fundsReceiver,
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
nonce nonce
); );
vm.startPrank(faucetContractAdmin); vm.startPrank(faucetContractAdmin);
faucet.drip( faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce), Faucet.DripParameters(payable(fundsReceiver), nonce),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature) Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature)
); );
faucet.configure(githubFam, Faucet.ModuleConfig("GithubModule", false, 1 days, .05 ether)); faucet.configure(githubFam, Faucet.ModuleConfig("GithubModule", false, 1 days, .05 ether));
...@@ -278,7 +295,7 @@ contract FaucetTest is Faucet_Initializer { ...@@ -278,7 +295,7 @@ contract FaucetTest is Faucet_Initializer {
vm.expectRevert("Faucet: provided auth module is not supported by this faucet"); vm.expectRevert("Faucet: provided auth module is not supported by this faucet");
faucet.drip( faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce), Faucet.DripParameters(payable(fundsReceiver), nonce),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature) Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature)
); );
vm.stopPrank(); vm.stopPrank();
} }
...@@ -293,20 +310,20 @@ contract FaucetTest is Faucet_Initializer { ...@@ -293,20 +310,20 @@ contract FaucetTest is Faucet_Initializer {
block.chainid, block.chainid,
address(githubFam), address(githubFam),
fundsReceiver, fundsReceiver,
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
nonce nonce
); );
vm.startPrank(faucetContractAdmin); vm.startPrank(faucetContractAdmin);
faucet.drip( faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce), Faucet.DripParameters(payable(fundsReceiver), nonce),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature) Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature)
); );
vm.expectRevert("Faucet: nonce has already been used"); vm.expectRevert("Faucet: nonce has already been used");
faucet.drip( faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce), Faucet.DripParameters(payable(fundsReceiver), nonce),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature) Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature)
); );
vm.stopPrank(); vm.stopPrank();
} }
...@@ -321,14 +338,14 @@ contract FaucetTest is Faucet_Initializer { ...@@ -321,14 +338,14 @@ contract FaucetTest is Faucet_Initializer {
block.chainid, block.chainid,
address(githubFam), address(githubFam),
fundsReceiver, fundsReceiver,
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
nonce0 nonce0
); );
vm.startPrank(faucetContractAdmin); vm.startPrank(faucetContractAdmin);
faucet.drip( faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce0), Faucet.DripParameters(payable(fundsReceiver), nonce0),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature0) Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature0)
); );
bytes32 nonce1 = faucetHelper.consumeNonce(); bytes32 nonce1 = faucetHelper.consumeNonce();
...@@ -339,14 +356,14 @@ contract FaucetTest is Faucet_Initializer { ...@@ -339,14 +356,14 @@ contract FaucetTest is Faucet_Initializer {
block.chainid, block.chainid,
address(githubFam), address(githubFam),
fundsReceiver, fundsReceiver,
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
nonce1 nonce1
); );
vm.expectRevert("Faucet: auth cannot be used yet because timeout has not elapsed"); vm.expectRevert("Faucet: auth cannot be used yet because timeout has not elapsed");
faucet.drip( faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce1), Faucet.DripParameters(payable(fundsReceiver), nonce1),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature1) Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature1)
); );
vm.stopPrank(); vm.stopPrank();
} }
...@@ -361,14 +378,14 @@ contract FaucetTest is Faucet_Initializer { ...@@ -361,14 +378,14 @@ contract FaucetTest is Faucet_Initializer {
block.chainid, block.chainid,
address(githubFam), address(githubFam),
fundsReceiver, fundsReceiver,
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
nonce0 nonce0
); );
vm.startPrank(faucetContractAdmin); vm.startPrank(faucetContractAdmin);
faucet.drip( faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce0), Faucet.DripParameters(payable(fundsReceiver), nonce0),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature0) Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature0)
); );
bytes32 nonce1 = faucetHelper.consumeNonce(); bytes32 nonce1 = faucetHelper.consumeNonce();
...@@ -379,14 +396,14 @@ contract FaucetTest is Faucet_Initializer { ...@@ -379,14 +396,14 @@ contract FaucetTest is Faucet_Initializer {
block.chainid, block.chainid,
address(githubFam), address(githubFam),
fundsReceiver, fundsReceiver,
abi.encodePacked(fundsReceiver), keccak256(abi.encodePacked(fundsReceiver)),
nonce1 nonce1
); );
vm.warp(startingTimestamp + 1 days + 1 seconds); vm.warp(startingTimestamp + 1 days + 1 seconds);
faucet.drip( faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce1), Faucet.DripParameters(payable(fundsReceiver), nonce1),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature1) Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature1)
); );
vm.stopPrank(); vm.stopPrank();
} }
......
...@@ -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.
......
...@@ -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