Skip to content

Commit

Permalink
Merge branch 'develop' into jg/rate_limit_p2p_unsafe_sync_requests
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] committed May 18, 2023
2 parents e3e4ddb + 846be4e commit 45fdc8d
Show file tree
Hide file tree
Showing 20 changed files with 471 additions and 71 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-cameras-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/sdk': patch
---

add eco bridge adapter
5 changes: 5 additions & 0 deletions .changeset/strange-bugs-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/contracts-periphery': patch
---

Change type for auth id on Faucet contracts from bytes to bytes32
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,12 @@ jobs:
name: anvil-l1
background: true
# atm this is goerli but we should use mainnet after bedrock is live
command: anvil --fork-url $ANVIL_L1_FORK_URL --fork-block-number 8847426
command: anvil --fork-url $ANVIL_L1_FORK_URL --fork-block-number 9023108
- run:
name: anvil-l2
background: true
# atm this is goerli but we should use mainnet after bedrock is live
command: anvil --fork-url $ANVIL_L2_FORK_URL --port 9545 --fork-block-number 8172732
command: anvil --fork-url $ANVIL_L2_FORK_URL --port 9545 --fork-block-number 9504811
- run:
name: build
command: yarn build
Expand All @@ -586,7 +586,7 @@ jobs:
command: npx wait-on tcp:9545 && cast block-number --rpc-url http://localhost:9545
- run:
name: test:next
command: yarn test:next
command: yarn test:next:run
no_output_timeout: 5m
working_directory: packages/sdk
environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ contract AdminFaucetAuthModuleTest is Test {
uint256 _eip712Chainid,
address _eip712VerifyingContract,
address recipient,
bytes memory id,
bytes32 id,
bytes32 nonce
) internal view returns (bytes memory) {
AdminFaucetAuthModule.Proof memory proof = AdminFaucetAuthModule.Proof(
Expand Down Expand Up @@ -114,15 +114,15 @@ contract AdminFaucetAuthModuleTest is Test {
block.chainid,
address(adminFam),
fundsReceiver,
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
nonce
);

vm.prank(nonAdmin);
assertEq(
adminFam.verify(
Faucet.DripParameters(payable(fundsReceiver), nonce),
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
proof
),
true
Expand All @@ -142,15 +142,15 @@ contract AdminFaucetAuthModuleTest is Test {
block.chainid,
address(adminFam),
fundsReceiver,
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
nonce
);

vm.prank(admin);
assertEq(
adminFam.verify(
Faucet.DripParameters(payable(fundsReceiver), nonce),
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
proof
),
false
Expand All @@ -172,15 +172,15 @@ contract AdminFaucetAuthModuleTest is Test {
block.chainid,
address(adminFam),
fundsReceiver,
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
nonce
);

vm.prank(admin);
assertEq(
adminFam.verify(
Faucet.DripParameters(payable(fundsReceiver), nonce),
abi.encodePacked(randomAddress),
keccak256(abi.encodePacked(randomAddress)),
proof
),
false
Expand Down
71 changes: 44 additions & 27 deletions packages/contracts-periphery/contracts/foundry-tests/Faucet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { FaucetHelper } from "../testing/helpers/FaucetHelper.sol";
contract Faucet_Initializer is Test {
event Drip(
string indexed authModule,
bytes indexed userId,
bytes32 indexed userId,
uint256 amount,
address indexed recipient
);
Expand Down Expand Up @@ -103,7 +103,7 @@ contract Faucet_Initializer is Test {
uint256 _eip712Chainid,
address _eip712VerifyingContract,
address recipient,
bytes memory id,
bytes32 id,
bytes32 nonce
) internal view returns (bytes memory) {
AdminFaucetAuthModule.Proof memory proof = AdminFaucetAuthModule.Proof(
Expand Down Expand Up @@ -140,14 +140,18 @@ contract FaucetTest is Faucet_Initializer {
block.chainid,
address(optimistNftFam),
fundsReceiver,
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
nonce
);

vm.prank(nonAdmin);
faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce),
Faucet.AuthParameters(optimistNftFam, abi.encodePacked(fundsReceiver), signature)
Faucet.AuthParameters(
optimistNftFam,
keccak256(abi.encodePacked(fundsReceiver)),
signature
)
);
}

Expand All @@ -161,15 +165,19 @@ contract FaucetTest is Faucet_Initializer {
block.chainid,
address(optimistNftFam),
fundsReceiver,
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
nonce
);

vm.prank(nonAdmin);
vm.expectRevert("Faucet: drip parameters could not be verified by security module");
faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce),
Faucet.AuthParameters(optimistNftFam, abi.encodePacked(fundsReceiver), signature)
Faucet.AuthParameters(
optimistNftFam,
keccak256(abi.encodePacked(fundsReceiver)),
signature
)
);
}

Expand All @@ -183,15 +191,19 @@ contract FaucetTest is Faucet_Initializer {
block.chainid,
address(optimistNftFam),
fundsReceiver,
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
nonce
);

uint256 recipientBalanceBefore = address(fundsReceiver).balance;
vm.prank(nonAdmin);
faucet.drip(
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;
assertEq(
Expand All @@ -211,15 +223,15 @@ contract FaucetTest is Faucet_Initializer {
block.chainid,
address(githubFam),
fundsReceiver,
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
nonce
);

uint256 recipientBalanceBefore = address(fundsReceiver).balance;
vm.prank(nonAdmin);
faucet.drip(
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;
assertEq(
Expand All @@ -239,17 +251,22 @@ contract FaucetTest is Faucet_Initializer {
block.chainid,
address(githubFam),
fundsReceiver,
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
nonce
);

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);
faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature)
Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature)
);
}

Expand All @@ -263,22 +280,22 @@ contract FaucetTest is Faucet_Initializer {
block.chainid,
address(githubFam),
fundsReceiver,
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
nonce
);

vm.startPrank(faucetContractAdmin);
faucet.drip(
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));

vm.expectRevert("Faucet: provided auth module is not supported by this faucet");
faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature)
Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature)
);
vm.stopPrank();
}
Expand All @@ -293,20 +310,20 @@ contract FaucetTest is Faucet_Initializer {
block.chainid,
address(githubFam),
fundsReceiver,
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
nonce
);

vm.startPrank(faucetContractAdmin);
faucet.drip(
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");
faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature)
Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature)
);
vm.stopPrank();
}
Expand All @@ -321,14 +338,14 @@ contract FaucetTest is Faucet_Initializer {
block.chainid,
address(githubFam),
fundsReceiver,
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
nonce0
);

vm.startPrank(faucetContractAdmin);
faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce0),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature0)
Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature0)
);

bytes32 nonce1 = faucetHelper.consumeNonce();
Expand All @@ -339,14 +356,14 @@ contract FaucetTest is Faucet_Initializer {
block.chainid,
address(githubFam),
fundsReceiver,
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
nonce1
);

vm.expectRevert("Faucet: auth cannot be used yet because timeout has not elapsed");
faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce1),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature1)
Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature1)
);
vm.stopPrank();
}
Expand All @@ -361,14 +378,14 @@ contract FaucetTest is Faucet_Initializer {
block.chainid,
address(githubFam),
fundsReceiver,
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
nonce0
);

vm.startPrank(faucetContractAdmin);
faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce0),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature0)
Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature0)
);

bytes32 nonce1 = faucetHelper.consumeNonce();
Expand All @@ -379,14 +396,14 @@ contract FaucetTest is Faucet_Initializer {
block.chainid,
address(githubFam),
fundsReceiver,
abi.encodePacked(fundsReceiver),
keccak256(abi.encodePacked(fundsReceiver)),
nonce1
);

vm.warp(startingTimestamp + 1 days + 1 seconds);
faucet.drip(
Faucet.DripParameters(payable(fundsReceiver), nonce1),
Faucet.AuthParameters(githubFam, abi.encodePacked(fundsReceiver), signature1)
Faucet.AuthParameters(githubFam, keccak256(abi.encodePacked(fundsReceiver)), signature1)
);
vm.stopPrank();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract FaucetHelper {
* @notice EIP712 typehash for the Proof type.
*/
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract Faucet {
*/
event Drip(
string indexed authModule,
bytes indexed userId,
bytes32 indexed userId,
uint256 amount,
address indexed recipient
);
Expand All @@ -49,7 +49,7 @@ contract Faucet {
*/
struct AuthParameters {
IFaucetAuthModule module;
bytes id;
bytes32 id;
bytes proof;
}

Expand All @@ -76,12 +76,12 @@ contract Faucet {
/**
* @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.
*/
mapping(bytes => mapping(bytes32 => bool)) public nonces;
mapping(bytes32 => mapping(bytes32 => bool)) public nonces;

/**
* @notice Modifier that makes a function admin priviledged.
Expand Down
Loading

0 comments on commit 45fdc8d

Please sign in to comment.