Skip to content

Commit

Permalink
sign over chain id and salt
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipp Makarov authored and Filipp Makarov committed Dec 12, 2024
1 parent a240742 commit 369c515
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 53 deletions.
2 changes: 1 addition & 1 deletion contracts/utils/Deployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract Deployer is SoladyOwnable {
constructor(address _owner) SoladyOwnable(_owner) {}

function deploy(bytes32 _salt, bytes calldata _creationCode, bytes calldata signature) external returns (address deployedContract) {
bytes32 hash = keccak256(_creationCode);
bytes32 hash = keccak256(abi.encode(_creationCode, _salt, block.chainid));
if (!_verifySignature(hash, signature)) revert InvalidBytecodeSignature();
deployedContract = Create3.create3(_salt, _creationCode);
emit ContractDeployed(deployedContract);
Expand Down
2 changes: 1 addition & 1 deletion scripts/bash-deploy/artifacts/Deployer/Deployer.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions scripts/bash-deploy/artifacts/Deployer/verify.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions scripts/bash-deploy/deploy-gasdaddy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ if [ $proceed = "y" ]; then
printf "Creating verification artifacts\n"

forge verify-contract --show-standard-json-input $(cast address-zero) BiconomySponsorshipPaymaster > ./artifacts/BiconomySponsorshipPaymaster/verify.json
forge verify-contract --show-standard-json-input $(cast address-zero) BiconomyTokenPaymaster > ./artifacts/BiconomyTokenPaymaster/verify.json

else
printf "Using precompiled artifacts\n"
Expand Down
3 changes: 2 additions & 1 deletion scripts/bash-deploy/deploy-prerequisites.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fi

### Create3 Deployer ###

CREATE3_DEPLOYER_SIZE=$(cast codesize --rpc-url $CHAIN_NAME 0x000000aFCC4940A247A53bEa5f3f4602433fe815)
CREATE3_DEPLOYER_SIZE=$(cast codesize --rpc-url $CHAIN_NAME $CREATE3_DEPLOYER_ADDRESS)
# printf "CREATE3 DEPLOYER Codesize: $CREATE3_DEPLOYER_SIZE\n"

if [ $CREATE3_DEPLOYER_SIZE -eq 0 ]; then
Expand All @@ -137,6 +137,7 @@ if [ $CREATE3_DEPLOYER_SIZE -eq 0 ]; then
printf "Rebuilding create3 deployer artifacts...\n"
forge build > /dev/null
cp ../../out/Deployer.sol/Deployer.json ./artifacts/Deployer/.
forge verify-contract --show-standard-json-input $(cast address-zero) Deployer > ./artifacts/Deployer/verify.json
else
printf "Using existing create3 deployer artifacts\n"
fi
Expand Down
6 changes: 2 additions & 4 deletions scripts/foundry/DeployDeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {DeterministicDeployerLib} from "./utils/DeterministicDeployerLib.sol";

contract DeployDeployer is Script {

bytes32 constant CREATE3_DEPLOYER_DEPLOYMENT_SALT = 0x00000000000000000000000000000000000000007d24613b61566e02484a50c5;
bytes32 constant CREATE3_DEPLOYER_DEPLOYMENT_SALT = 0x000000000000000000000000000000000000000068be161e3f742b0423335623; // => 0x0000003d8fE88f1591774CCD958baF0211Ee2183
address constant DEPLOYER_OWNER = 0x336A8f5251F3b0723d04FBDD25858fca02BB22E3;
bytes32 constant DEPLOYER_BYTECODE_HASH = 0xb474e2c7cd2df923dc66b1fbf61eb752b66b7aecb94e055878c3c75061de219c;

Expand All @@ -19,6 +19,7 @@ contract DeployDeployer is Script {
address expectedDeployer = DeterministicDeployerLib.computeAddress(bytecode, args, CREATE3_DEPLOYER_DEPLOYMENT_SALT);

// initcode hash to look for the salt
console.log("Deployer bytecode hash for salt generation: ");
console.logBytes32(keccak256(abi.encodePacked(bytecode, args)));

bytes32 deployerBytecodeHash;
Expand All @@ -29,9 +30,6 @@ contract DeployDeployer is Script {
deployerBytecodeHash := extcodehash(expectedDeployer)
}

//console.logBytes32(deployerBytecodeHash);
//console.log("Size", codeLength);

if (codeLength != 0) {
if (deployerBytecodeHash != DEPLOYER_BYTECODE_HASH) {
revert("Deployer bytecode hash mismatch");
Expand Down
76 changes: 30 additions & 46 deletions scripts/foundry/DeployGasdaddy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ contract DeployGasdaddy is Script {
bytes32 constant SPONSORSHIP_PAYMASTER_DEPLOYMENT_SALT = 0x3e81534a95d3368136d6c49522f8e20ada0b768931512a65c785c15a83178777; //
bytes32 constant TOKEN_PAYMASTER_DEPLOYMENT_SALT = 0xf5516e76713013dc560228c61d8ad21680be770b25fcaed28edf3071e09bb777; //

// CREATE3 DEPLOYER ADDRESS
address constant CREATE3_DEPLOYER_ADDRESS = 0x000000aFCC4940A247A53bEa5f3f4602433fe815;

// CONSTRUCTOR ARGS
address constant VERIFYING_PAYMASTER_OWNER = 0x2cf491602ad22944D9047282aBC00D3e52F56B37;
address constant VERIFYING_SIGNER = 0xC6dAB8652E5E9749523bA948F42d5944584E4e73;
Expand All @@ -42,16 +39,13 @@ contract DeployGasdaddy is Script {
uint256 constant PAYMASTER_ID_WITHDRAWAL_DELAY = 3600; // 1 hour
address constant ENTRY_POINT_V07 = 0x0000000071727De22E5E9d8BAf0edAc6f37da032;

mapping (uint256 => bytes) public signaturesForMinDeposits;
mapping (uint256 chainId => TokenPMConfig) public tokenPMConfigs;

Create3Deployer create3Deployer;


function setUp() public {
create3Deployer = Create3Deployer(CREATE3_DEPLOYER_ADDRESS);

_fillSignaturesForMinDepositsSponsPM();
create3Deployer = Create3Deployer(vm.envAddress("CREATE3_DEPLOYER_ADDRESS"));

_fillTokenPMConfigs();

Expand Down Expand Up @@ -90,34 +84,9 @@ contract DeployGasdaddy is Script {
PAYMASTER_ID_WITHDRAWAL_DELAY,
minDeposit
);
console.log("args abi encoded: ");
console.log("args abi encoded for sponsorship PM: ");
console.logBytes(args);

// Use this block to get initcode hashes to sign
/*
uint256[] memory minDeposits = new uint256[](5);
minDeposits[0] = 1e15;
minDeposits[1] = 1e16;
minDeposits[2] = 1e17;
minDeposits[3] = 1e18;
minDeposits[4] = 1e19;
for (uint256 i = 0; i < minDeposits.length; i++) {
minDeposit = minDeposits[i];
args = abi.encode(
VERIFYING_PAYMASTER_OWNER,
ENTRY_POINT_V07,
VERIFYING_SIGNER,
FEE_COLLECTOR,
SPONSORSHIP_PM_UNACCOUNTED_GAS,
PAYMASTER_ID_WITHDRAWAL_DELAY,
minDeposit
);
console.log("min deposit: ", (minDeposit));
console.logBytes32(keccak256(abi.encodePacked(bytecode, args)));
}
*/

///
/// TOKEN PAYMASTER
///
Expand All @@ -127,10 +96,35 @@ contract DeployGasdaddy is Script {
codeSize := extcodesize(tokenPM)
}
console.log("Token Paymaster address: ", tokenPM, " || >> Code Size: ", codeSize);

TokenPMConfig memory config = tokenPMConfigs[block.chainid];
args = abi.encode(
VERIFYING_PAYMASTER_OWNER,
VERIFYING_SIGNER,
ENTRY_POINT_V07,
TOKEN_PM_UNACCOUNTED_GAS,
config.nativeAssetDecimals,
config.nativeAssetToUsdOracle,
config.nativeAssetPriceExpiryDuration,
config.swapRouter,
config.wrappedNativeAddress,
config.independentTokens,
config.tokenInfos,
new address[](0), // swappable tokens
new uint24[](0) // swappable token fees
);
console.log("args abi encoded for token PM: ");
console.logBytes(args);
}

//
// DEPLOY GASDADDY
//

function deployGasDaddy(uint256 minDeposit) public returns (uint256 contractsDeployedCount) {

uint256 create3deployerOwnerPk = vm.envUint("CREATE3_OWNER_PK");

//
// SPONSORSHIP PAYMASTER
//
Expand All @@ -153,16 +147,15 @@ contract DeployGasdaddy is Script {
console.log("Sponsorship Paymaster already deployed at", sponsorshipPM);
} else {
bytes memory initcode = abi.encodePacked(bytecode, args);
bytes memory signature = signaturesForMinDeposits[minDeposit];
sponsorshipPM = create3Deployer.deploy(SPONSORSHIP_PAYMASTER_DEPLOYMENT_SALT, initcode, signature);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(create3deployerOwnerPk, keccak256(abi.encode(initcode, SPONSORSHIP_PAYMASTER_DEPLOYMENT_SALT, block.chainid)));
sponsorshipPM = create3Deployer.deploy(SPONSORSHIP_PAYMASTER_DEPLOYMENT_SALT, initcode, abi.encodePacked(r, s, v));
console.log("Sponsorship Paymaster deployed at", sponsorshipPM);
contractsDeployedCount++;
}

///
/// TOKEN PAYMASTER
///
uint256 create3deployerOwnerPk = vm.envUint("CREATE3_OWNER_PK");

bytecode = vm.getCode("scripts/bash-deploy/artifacts/BiconomyTokenPaymaster/BiconomyTokenPaymaster.json");
TokenPMConfig memory config = tokenPMConfigs[block.chainid];
Expand Down Expand Up @@ -198,22 +191,13 @@ contract DeployGasdaddy is Script {
return contractsDeployedCount;
} else {
bytes memory initcode = abi.encodePacked(bytecode, args);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(create3deployerOwnerPk, keccak256(initcode));
(uint8 v, bytes32 r, bytes32 s) = vm.sign(create3deployerOwnerPk, keccak256(abi.encode(initcode, TOKEN_PAYMASTER_DEPLOYMENT_SALT, block.chainid)));
tokenPM = create3Deployer.deploy(TOKEN_PAYMASTER_DEPLOYMENT_SALT, initcode, abi.encodePacked(r, s, v));
console.log("Token Paymaster deployed at", tokenPM);
contractsDeployedCount++;
}
}

function _fillSignaturesForMinDepositsSponsPM() internal {
// Signatures for Sponsorship PM
signaturesForMinDeposits[1e15] = hex'f799f0e37b89b42d667d6cf6ca461bb4e1d9818a5568a640ad89dbe74a16b18b105a3ecbe06828faaf91153bf2238bd5bf9f52cda834eb2ddc81c5665b77901f1b'; //0.001 native token
signaturesForMinDeposits[1e16] = hex'3d4fc4d9a447fb205cc50dce4b74230f0e0baea776bbce2cced39e1b82f612bc5de05607fdeaf3734f8577a8b829b0dd05bb0fe760e4fe9dda28b729d45c95d21c'; //0.01 native token
signaturesForMinDeposits[1e17] = hex'f121c54fabc0f95a2baa1cc296135d125f636532d489a9850a0ea3fe7f52694a2954b6f5cd42aca1e2203e7e39108a878477bfe2f90ed6a38ec578199e5586111c'; //0.1 native token
signaturesForMinDeposits[1e18] = hex'0e2f4921b34b8a2a6ceab67bd7db9655c0e272a725cbb5da84acaad1d023237817a1cb754fd65dd45bebc43312dafb9b53c8e58619da7da5acc9ea96294534141b'; //1 native token
signaturesForMinDeposits[1e19] = hex'6e559e01580bc8cd18fabef2d0aa018f35dc5cb1aa0c26e8cb8b9c45478382cf0fcc208ad2564d693418957e417a90b9081716fa1c01cba65e8442edaed584541c'; //10 native tokens
}

function _fillTokenPMConfigs() internal {
// in case we want to support independent tokens
/*
Expand Down

0 comments on commit 369c515

Please sign in to comment.