-
Notifications
You must be signed in to change notification settings - Fork 7
Use obfuscated key in deployment #68
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Submodule forge-std
updated
75 files
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
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
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 |
|---|---|---|
| @@ -1,21 +1,36 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| pragma solidity ^0.8.13; | ||
|
|
||
| import "forge-std/Script.sol"; | ||
| import "./ValidatedAddress.sol"; | ||
| import "../src/CoWSwapEthFlow.sol"; | ||
| import {Script, console} from "forge-std/Script.sol"; | ||
| import {Vm} from "forge-std/Vm.sol"; | ||
|
|
||
| import {CoWSwapEthFlow, ICoWSwapSettlement, IWrappedNativeToken} from "src/CoWSwapEthFlow.sol"; | ||
|
|
||
| import {ValidatedAddress} from "./ValidatedAddress.sol"; | ||
| import {Obfuscator} from "./ObfuscateKey.sol"; | ||
|
|
||
| /// @title Deployer Script for the ETH Flow Contract | ||
| /// @author CoW Swap Developers. | ||
| contract Deploy is Script { | ||
| function run() external { | ||
| vm.startBroadcast(); | ||
|
|
||
| new CoWSwapEthFlow( | ||
| ICoWSwapSettlement(ValidatedAddress.cowSwapSettlement()), | ||
| IWrappedNativeToken(ValidatedAddress.wrappedNativeToken()) | ||
| /// @param obfuscatedPk An obfuscated version of the private key used for | ||
| /// deploying the contract. | ||
| function run(bytes32 obfuscatedPk) external { | ||
| ICoWSwapSettlement settlement = ICoWSwapSettlement( | ||
| ValidatedAddress.cowSwapSettlement() | ||
| ); | ||
| IWrappedNativeToken wrappedNativeToken = IWrappedNativeToken( | ||
| ValidatedAddress.wrappedNativeToken() | ||
| ); | ||
|
|
||
| uint256 pk = uint256(Obfuscator.deobfuscate(obfuscatedPk)); | ||
| Vm.Wallet memory wallet = vm.createWallet(pk); | ||
| console.log("Deployer address: ", wallet.addr); | ||
|
|
||
| vm.stopBroadcast(); | ||
| vm.broadcast(wallet.privateKey); | ||
| CoWSwapEthFlow ethFlow = new CoWSwapEthFlow( | ||
| settlement, | ||
| wrappedNativeToken | ||
| ); | ||
| console.log("Contract deployed at:", address(ethFlow)); | ||
| } | ||
| } |
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,32 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.13; | ||
|
|
||
| import {Script, console} from "forge-std/Script.sol"; | ||
|
|
||
| library Obfuscator { | ||
| bytes32 internal constant SHIFT = | ||
| 0x31337def1beef31337def1beef31337def1beef31337def1beef1173def1beef; | ||
|
|
||
| function obfuscate(bytes32 input) internal pure returns (bytes32) { | ||
| return SHIFT ^ input; | ||
| } | ||
|
|
||
| function deobfuscate(bytes32 input) internal pure returns (bytes32) { | ||
| // This function is the inverse of itself. | ||
| return obfuscate(input); | ||
| } | ||
| } | ||
|
|
||
| /// @title Helper script to obfuscate a key for use in the deployment process. | ||
| /// @dev This obfuscation isn't intended to be secure, it's just here to avoid | ||
| /// reusing the private keys in other contexts by accident. | ||
| /// @author CoW Swap Developers. | ||
| contract ObfuscateKey is Script { | ||
| function run(bytes32 key) external pure { | ||
| console.log("Obfuscation parameter:", vm.toString(Obfuscator.SHIFT)); | ||
| console.log( | ||
| "Obfuscated key: ", | ||
| vm.toString(Obfuscator.obfuscate(key)) | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense, and would prevent someone from having it in their
envand deploying something else.Do you plan to also update in secret manager the key to obfuscate, so we prevent people from importing that into anywere and also making it easier to use only as input of this script?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The secret should contain an entry explicitly named
ETHFLOW_OBFUSCATED_PKfor ease of copypaste and the actual private key just in case it's ever needed with a warning "do not use."