diff --git a/chain_config.json b/chain_config.json index 51840a65..978de3f5 100644 --- a/chain_config.json +++ b/chain_config.json @@ -6,7 +6,7 @@ "isCancun": true, "extraFlags": "", "gasMultiplierPercent": 200, - "minGasPriceGwei": 1, + "minGasPriceGwei": 10, "safe": { "singleton": "0xfb1bffC9d739B8D520DaF37dF666da4C687191EA", "factory": "0xC22834581EbC8527d974F8a1c97E1bEA4EF910BC", diff --git a/sh/common_deploy_settler.sh b/sh/common_deploy_settler.sh index 50e9df41..5c6a3ce0 100644 --- a/sh/common_deploy_settler.sh +++ b/sh/common_deploy_settler.sh @@ -13,6 +13,13 @@ trap 'trap - EXIT; set +e; rm -f '"$(_escape "$flat_taker_source")"' '"$(_escape forge flatten -o "$flat_metatx_source" src/chains/"$chain_display_name"/MetaTxn.sol >/dev/null forge build "$flat_metatx_source" +declare flat_intent_source +flat_intent_source="$project_root"/src/flat/"$chain_display_name"IntentFlat.sol +declare -r flat_intent_source +trap 'trap - EXIT; set +e; rm -f '"$(_escape "$flat_taker_source")"' '"$(_escape "$flat_metatx_source")"' '"$(_escape "$flat_intent_source")" EXIT +forge flatten -o "$flat_intent_source" src/chains/"$chain_display_name"/Intent.sol >/dev/null +forge build "$flat_intent_source" + declare taker_artifact taker_artifact="$project_root"/out/"$chain_display_name"TakerSubmittedFlat.sol/"$chain_display_name"Settler.json declare -r taker_artifact @@ -21,7 +28,11 @@ declare metatx_artifact metatx_artifact="$project_root"/out/"$chain_display_name"MetaTxnFlat.sol/"$chain_display_name"SettlerMetaTxn.json declare -r metatx_artifact -if [ ! -f "$taker_artifact" ] || [ ! -f "$metatx_artifact" ] ; then +declare intent_artifact +intent_artifact="$project_root"/out/"$chain_display_name"IntentFlat.sol/"$chain_display_name"SettlerIntent.json +declare -r intent_artifact + +if [ ! -f "$taker_artifact" ] || [ ! -f "$metatx_artifact" ] || [ ! -f "$intent_artifact" ] ; then echo 'Cannot find '"$chain_display_name"'Settler.json' >&2 exit 1 fi @@ -38,6 +49,10 @@ declare metatx_initcode metatx_initcode="$(cast concat-hex "$(jq -Mr .bytecode.object < "$metatx_artifact")" "$constructor_args")" declare -r metatx_initcode +declare intent_initcode +intent_initcode="$(cast concat-hex "$(jq -Mr .bytecode.object < "$intent_artifact")" "$constructor_args")" +declare -r intent_initcode + declare -r deploy_sig='deploy(uint128,bytes)(address,uint32)' declare deploy_taker_calldata @@ -48,35 +63,96 @@ declare deploy_metatx_calldata deploy_metatx_calldata="$(cast calldata "$deploy_sig" 3 "$metatx_initcode")" declare -r deploy_metatx_calldata +declare deploy_intent_calldata +deploy_intent_calldata="$(cast calldata "$deploy_sig" 4 "$intent_initcode")" +declare -r deploy_intent_calldata + +declare next_intent_settler_address +next_intent_settler_address="$(cast call --rpc-url "$rpc_url" "$deployer_address" 'next(uint128)(address)' 4)" +declare -r next_intent_settler_address + +declare -a solvers +readarray -t solvers < "$project_root"/sh/solvers.txt +declare -r -a solvers + +declare -a setsolver_calldatas +declare setsolver_calldata +declare prev_solver=0x0000000000000000000000000000000000000001 +declare solver +for solver in "${solvers[@]}" ; do + setsolver_calldata="$(cast calldata 'setSolver(address,address,bool)' "$prev_solver" "$solver" true)" + setsolver_calldatas+=("$setsolver_calldata") + prev_solver="$solver" +done +unset -v solver +unset -v prev_solver +unset -v setsolver_calldata + if [[ -n "${deployer_address-}" ]] ; then declare -a deploy_calldatas if (( chainid == 534352 )) ; then + declare setsolver_calldata + for setsolver_calldata in "${setsolver_calldatas[@]}" ; do + deploy_calldatas+=( + "$( + cast concat-hex \ + 0x00 \ + "$next_intent_settler_address" \ + "$(cast to-uint256 0)" \ + "$(cast to-uint256 $(( (${#setsolver_calldata} - 2) / 2 )) )" \ + "$setsolver_calldata" + )" + ) + done deploy_calldatas=( - 0 "$deploy_taker_calldata" - 0 "$deploy_metatx_calldata" + # 0 "$deploy_taker_calldata" "$deployer_address" + # 0 "$deploy_metatx_calldata" "$deployer_address" + 0 "$deploy_intent_calldata" "$deployer_address" + 1 "$(cast calldata "$multisend_sig" "$(cast concat-hex "${deploy_calldatas[@]}")")" "$multicall_address" ) else - deploy_calldatas=( - "$( - cast concat-hex \ - 0x00 \ - "$deployer_address" \ - "$(cast to-uint256 0)" \ - "$(cast to-uint256 $(( (${#deploy_taker_calldata} - 2) / 2 )) )" \ - "$deploy_taker_calldata" - )" + deploy_calldatas+=( + # "$( + # cast concat-hex \ + # 0x00 \ + # "$deployer_address" \ + # "$(cast to-uint256 0)" \ + # "$(cast to-uint256 $(( (${#deploy_taker_calldata} - 2) / 2 )) )" \ + # "$deploy_taker_calldata" + # )" + # + # "$( + # cast concat-hex \ + # 0x00 \ + # "$deployer_address" \ + # "$(cast to-uint256 0)" \ + # "$(cast to-uint256 $(( (${#deploy_metatx_calldata} - 2) / 2 )) )" \ + # "$deploy_metatx_calldata" + # )" "$( cast concat-hex \ 0x00 \ "$deployer_address" \ "$(cast to-uint256 0)" \ - "$(cast to-uint256 $(( (${#deploy_metatx_calldata} - 2) / 2 )) )" \ - "$deploy_metatx_calldata" + "$(cast to-uint256 $(( (${#deploy_intent_calldata} - 2) / 2 )) )" \ + "$deploy_intent_calldata" )" ) + for setsolver_calldata in "${setsolver_calldatas[@]}" ; do + deploy_calldatas+=( + "$( + cast concat-hex \ + 0x00 \ + "$next_intent_settler_address" \ + "$(cast to-uint256 0)" \ + "$(cast to-uint256 $(( (${#setsolver_calldata} - 2) / 2 )) )" \ + "$setsolver_calldata" + )" + ) + done deploy_calldatas=( - 1 "$(cast calldata "$multisend_sig" "$(cast concat-hex "${deploy_calldatas[@]}")")" + 1 "$(cast calldata "$multisend_sig" "$(cast concat-hex "${deploy_calldatas[@]}")")" "$multicall_address" ) fi fi diff --git a/sh/confirm_new_settler.sh b/sh/confirm_new_settler.sh index 2344ce1b..0efd0fb2 100755 --- a/sh/confirm_new_settler.sh +++ b/sh/confirm_new_settler.sh @@ -130,18 +130,19 @@ declare -r safe_address . "$project_root"/sh/common_wallet_type.sh . "$project_root"/sh/common_deploy_settler.sh -while (( ${#deploy_calldatas[@]} >= 2 )) ; do +while (( ${#deploy_calldatas[@]} >= 3 )) ; do declare -i operation="${deploy_calldatas[0]}" declare deploy_calldata="${deploy_calldatas[1]}" - deploy_calldatas=( "${deploy_calldatas[@]:2:$((${#deploy_calldatas[@]}-2))}" ) + declare target="${deploy_calldatas[2]}" + deploy_calldatas=( "${deploy_calldatas[@]:3:$((${#deploy_calldatas[@]}-3))}" ) declare struct_json - struct_json="$(eip712_json "$deploy_calldata" $operation)" + struct_json="$(eip712_json "$deploy_calldata" $operation "$target")" declare signature signature="$(sign_call "$struct_json")" - save_signature settler_confirmation "$deploy_calldata" "$signature" $operation + save_signature settler_confirmation "$deploy_calldata" "$signature" $operation "$target" SAFE_NONCE_INCREMENT=$((${SAFE_NONCE_INCREMENT:-0} + 1)) done diff --git a/sh/deploy_new_settler.sh b/sh/deploy_new_settler.sh index 474ca089..b0df7ea9 100755 --- a/sh/deploy_new_settler.sh +++ b/sh/deploy_new_settler.sh @@ -151,22 +151,20 @@ declare -i gas_estimate_multiplier gas_estimate_multiplier="$(get_config gasMultiplierPercent)" declare -r -i gas_estimate_multiplier -while (( ${#deploy_calldatas[@]} >= 2 )) ; do +while (( ${#deploy_calldatas[@]} >= 3 )) ; do declare -i operation="${deploy_calldatas[0]}" declare deploy_calldata="${deploy_calldatas[1]}" - deploy_calldatas=( "${deploy_calldatas[@]:2:$((${#deploy_calldatas[@]}-2))}" ) - - declare signing_hash - signing_hash="$(eip712_hash "$deploy_calldata" $operation)" + declare target="${deploy_calldatas[2]}" + deploy_calldatas=( "${deploy_calldatas[@]:3:$((${#deploy_calldatas[@]}-3))}" ) declare packed_signatures - packed_signatures="$(retrieve_signatures settler_confirmation "$deploy_calldata" $operation)" + packed_signatures="$(retrieve_signatures settler_confirmation "$deploy_calldata" $operation "$target")" # configure gas limit declare -a args=( "$safe_address" "$execTransaction_sig" # to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, signatures - "$(target $operation)" 0 "$deploy_calldata" $operation 0 0 0 "$(cast address-zero)" "$(cast address-zero)" "$packed_signatures" + "$target" 0 "$deploy_calldata" $operation 0 0 0 "$(cast address-zero)" "$(cast address-zero)" "$packed_signatures" ) # set gas limit and add multiplier/headroom (again mostly for Arbitrum) diff --git a/sh/generate_solvers.sh b/sh/generate_solvers.sh new file mode 100755 index 00000000..5a8b2d8a --- /dev/null +++ b/sh/generate_solvers.sh @@ -0,0 +1,163 @@ +#!/usr/bin/env bash + +## POSIX Bash implementation of realpath +## Copied and modified from https://github.com/mkropat/sh-realpath and https://github.com/AsymLabs/realpath-lib/ +## Copyright (c) 2014 Michael Kropat - MIT License +## Copyright (c) 2013 Asymmetry Laboratories - MIT License + +function realpath { + _resolve_symlinks "$(_canonicalize "$1")" +} + +function _directory { + local out slsh + slsh=/ + out="$1" + out="${out//$slsh$slsh/$slsh}" + if [ "$out" = / ]; then + echo / + return + fi + out="${out%/}" + case "$out" in + */*) + out="${out%/*}" + ;; + *) + out=. + ;; + esac + if [ "$out" ]; then + printf '%s\n' "$out" + else + echo / + fi +} + +function _file { + local out slsh + slsh=/ + out="$1" + out="${out//$slsh$slsh/$slsh}" + if [ "$out" = / ]; then + echo / + return + fi + out="${out%/}" + out="${out##*/}" + printf '%s\n' "$out" +} + +function _resolve_symlinks { + local path pattern context + while [ -L "$1" ]; do + context="$(_directory "$1")" + path="$(POSIXLY_CORRECT=y ls -ld -- "$1" 2>/dev/null)" + pattern='*'"$(_escape "$1")"' -> ' + path="${path#$pattern}" + set -- "$(_canonicalize "$(_prepend_context "$context" "$path")")" "$@" + _assert_no_path_cycles "$@" || return 1 + done + printf '%s\n' "$1" +} + +function _escape { + local out + out='' + local -i i + for ((i=0; i < ${#1}; i+=1)); do + out+='\'"${1:$i:1}" + done + printf '%s\n' "$out" +} + +function _prepend_context { + if [ "$1" = . ]; then + printf '%s\n' "$2" + else + case "$2" in + /* ) printf '%s\n' "$2" ;; + * ) printf '%s\n' "$1/$2" ;; + esac + fi +} + +function _assert_no_path_cycles { + local target path + + if [ $# -gt 16 ]; then + return 1 + fi + + target="$1" + shift + + for path in "$@"; do + if [ "$path" = "$target" ]; then + return 1 + fi + done +} + +function _canonicalize { + local d f + if [ -d "$1" ]; then + (CDPATH= cd -P "$1" 2>/dev/null && pwd -P) + else + d="$(_directory "$1")" + f="$(_file "$1")" + (CDPATH= cd -P "$d" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$f") + fi +} + +## end POSIX Bash implementation of realpath + +set -Eeufo pipefail -o posix + +declare project_root +project_root="$(_directory "$(_directory "$(realpath "${BASH_SOURCE[0]}")")")" +declare -r project_root +cd "$project_root" + +echo "This script is mostly for Duncan's use in generating the file solvers.txt ." >&2 +echo "You probably don't need to run this script." >&2 +echo "The only reason you'd need to run this script is if the production or staging" >&2 +echo 'chain worker mnemonics have been rotated.' >&2 +echo '' >&2 + +. "$project_root"/sh/common.sh +. "$project_root"/sh/common_secrets.sh + +declare -i num_production_addresses +num_production_addresses="$(get_secret intentWorkers limit.production)" +declare -r -i num_production_addresses + +declare production_mnemonic +production_mnemonic="$(get_secret intentWorkers mnemonic.production)" +declare -r production_mnemonic + +declare -i num_staging_addresses +num_staging_addresses="$(get_secret intentWorkers limit.staging)" +declare -r -i num_staging_addresses + +declare staging_mnemonic +staging_mnemonic="$(get_secret intentWorkers mnemonic.staging)" +declare -r staging_mnemonic + +declare -a solvers=() +declare privkey +declare solver + +for (( i = 0 ; i < $num_production_addresses ; i++ )) ; do + privkey="$(cast wallet private-key "$production_mnemonic" "m/44'/60'/0'/0/$i")" + solver="$(cast wallet address "$privkey")" + solvers+=("$solver") +done + +for (( i = 0 ; i < $num_staging_addresses ; i++ )) ; do + privkey="$(cast wallet private-key "$staging_mnemonic" "m/44'/60'/0'/0/$i")" + solver="$(cast wallet address "$privkey")" + solvers+=("$solver") +done + +printf '%s\n' "${solvers[@]}" diff --git a/sh/solvers.txt b/sh/solvers.txt new file mode 100644 index 00000000..e9631b10 --- /dev/null +++ b/sh/solvers.txt @@ -0,0 +1,60 @@ +0xc65f45c3Ac07C57C566341811234c8aA5AfBbb40 +0x0a1ac7d31142760c430d0bb7C801c3C727A81d69 +0x399ffeeE2b7E86d69A2b2bbA51D882eB3a83e196 +0xc7c42E765017De6d08887D92E5cdc9843aA5888D +0x2894BfcaE3B449959215B89433b860cac7Cc3450 +0x81FD0A1D13059E473C1E02D73705124315E14CbA +0xEFF023Bb006dA503414507062BB4B86291e8707f +0x3d3d3979D9F3422cF36EA900515971CBe44deE9F +0x1b1aA8f5830DB779e905872D75EA13E688C897Ef +0x22c45Fb52C9EF7bfaff34a0DAf4ec9C361bBbE17 +0xac844837a2B58db4B4deF35b243ee14c3e36A96b +0x27a43aBD397fB52Bf874dda13BE35858e5C72762 +0xab2Ef589567019058Bd8157EC32d89A093E50e92 +0xB5c67a3B815B88acD2524B3CC83f2A0dA5C51347 +0xD6d8F61c549E4cFdc7f5E240f942Caa8D6BB8856 +0xC375BE3817Ce7A9C4e0Ca652fb895315Ff300EF1 +0x7BB10f234d7872FC52998592e2EeBb246Ec17430 +0xF6b988c573897C7b9C90747858AA5D8c56e210B5 +0xE8db823D5D17fAc0AB7183e03f688de0CE63DE15 +0x0F9DFd170F6d3109F801F1475b11a9c135232538 +0xfa7fFbEC31B82b06B56d91754e003c4E8Fe12652 +0x8C410057a8933d579926dEcCD043921A974A24ee +0xC7A80eA2a3aff9f4e367Fc285d635ef5b177789D +0x3810b6c2FDa013Cc9462C5B5447f9221995E7ca1 +0x3525A90B8105009Ce4BA4201c0dFd16530Ee2702 +0x167c9aA7fBAB3B0d29058c12496C6Aac8D593b50 +0x2276f36C0C077ABf138fBbC045143c3d53aC190c +0xF2432aE59486A76589CE08Dd73ddac82Baf728AE +0xe5285E8156c440EB32dF19113d1DAdB55F068e6f +0x7fc35307C64A142c9A77Eaa347538D3d9FF3c3CE +0x828A17f453918a069955f85e97D801d36aD8B8e7 +0xf93A1E472aa52d0354Fe17D7967263Cd62A3c02C +0xe045F62A4446e47db8aFA0bF8BB48098ca296083 +0x722370435dae49714C44a849158A0B4385e7648F +0x3b0eb3F7eD141e4f7153c612132f79C4C22147F4 +0x0FC3f0bC769fb677AD3D9BF64c470550629e255e +0x14b7441748b088dB204530EE4739a7065e0148E1 +0x74865ca9AfBB2d38995cc7f6697E25C38038c44F +0x7fF41EcD5db04431753D46E1b0873B9BE2c97B5a +0xA9fcaDB0Ba4125C2C9c19f0778C18837ce859c34 +0x435e41592aa56823c838f7fBCa911a7F11bFA2BC +0xf60Ca1e2Fa1bD4d421b0aAed014171aEEAeF3B55 +0x7F630b7db949FC936b4dE35E502FF7F32cDFFF20 +0xF44040eC9d35425DCAb04f04fe0b9818481cb6dA +0x03421553988977107a7cDD4432036F8CF46BD986 +0xe918AFAa7368263Be01fFc4A31ceA2b434b7F37C +0xdd4380237331A77E45443C49aFeAe89482F084Db +0xc8383D5a074Ef1759941435C58e87059fc792430 +0xD84FEe90443c8CEbeFddD99d2F7098BF1b403dc9 +0x6D65379715b79B2e37837D36C408fBE465Acc7C2 +0xA85795B9b37e200c67398D7796aB301a838f539D +0xb0E9e6222D4A8e546a96b978bFcCF8F7046D07fA +0x56a7088c115eCB109F35D0C41103618e6bF59B1F +0x1F61FD6803C8251de1300d7735cEB6998cdbDf6a +0x25F2cDBB8d3D0b9c682e333c6A513274D279a32a +0x265F0Aab72294a248f925deCf3b1c25ec7F6F63d +0xa440524e9bAA0833aDF6d9Aff76f364A2AEA13b9 +0xDed916A6B6D16923638469C386d38D5e06fFf73e +0xF64070d7A33D7AE1E6C316C477d76b9eb25E7fB6 +0x99C580bE6280012cbAaa97390F13c0b44b670F22 diff --git a/sh/verify_settler.sh b/sh/verify_settler.sh index 67609dae..7502077f 100755 --- a/sh/verify_settler.sh +++ b/sh/verify_settler.sh @@ -121,17 +121,11 @@ cd "$project_root" . "$project_root"/sh/common.sh -declare deployer_address -deployer_address="$(get_config deployment.deployer)" -declare -r deployer_address - -# calls encoded as operation (always zero) 1 byte -# target address 20 bytes -# value 32 bytes -# data length 32 bytes -# data variable -declare -r multisend_sig='multiSend(bytes)' +declare safe_address +safe_address="$(get_config governance.deploymentSafe)" +declare -r safe_address +. "$project_root"/sh/common_safe.sh . "$project_root"/sh/common_deploy_settler.sh declare -r erc721_ownerof_sig='ownerOf(uint256)(address)' @@ -152,4 +146,12 @@ declare -r metatx_settler verify_contract "$constructor_args" "$metatx_settler" "$flat_metatx_source":"$chain_display_name"SettlerMetaTxn -echo 'Verified metatx Settler. All done!' >&2 +echo 'Verified metatx Settler... verifying intent Settler...' >&2 + +declare intent_settler +intent_settler="$(cast call --rpc-url "$rpc_url" "$deployer_address" "$erc721_ownerof_sig" 4)" +declare -r intent_settler + +verify_contract "$constructor_args" "$intent_settler" "$flat_intent_source":"$chain_display_name"SettlerIntent + +echo 'Verified intent Settler. All done!' >&2 diff --git a/src/SettlerIntent.sol b/src/SettlerIntent.sol index 7ab2e0d2..7080db83 100644 --- a/src/SettlerIntent.sol +++ b/src/SettlerIntent.sol @@ -42,7 +42,7 @@ abstract contract SettlerIntent is Permit2PaymentIntent, SettlerMetaTxn, MultiCa _$()[_SENTINEL_SOLVER] = _SENTINEL_SOLVER; } - function owner() public returns (address owner_) { + function owner() public view returns (address owner_) { // Solidity generates extremely bloated code for the following block, so it has been // rewritten in assembly so as not to blow out the contract size limit /* @@ -67,7 +67,7 @@ abstract contract SettlerIntent is Permit2PaymentIntent, SettlerMetaTxn, MultiCa revert(ptr, returndatasize()) } - // If calldata is short (we need at least 64 bytes), revert with an empty reason. + // If returndata is short (we need at least 64 bytes), revert with an empty reason. if lt(returndatasize(), 0x40) { revert(0x00, 0x00) } // Load the return values that were automatically written into the first 2 slots of diff --git a/src/vendor/SafeTransferLib.sol b/src/vendor/SafeTransferLib.sol index 54340a09..9819bdc5 100644 --- a/src/vendor/SafeTransferLib.sol +++ b/src/vendor/SafeTransferLib.sol @@ -41,7 +41,7 @@ library SafeTransferLib { revert(ptr, returndatasize()) } // Check for short returndata and missing code - if iszero(gt(returndatasize(), 0x1f)) { revert(0x00, 0x00) } + if iszero(lt(0x1f, returndatasize())) { revert(0x00, 0x00) } r := mload(0x00) } @@ -64,7 +64,7 @@ library SafeTransferLib { } // We check that the call either returned exactly 1 [true] (can't just be non-zero // data), or had no return data. - if iszero(or(and(eq(mload(0x00), 0x01), gt(returndatasize(), 0x1f)), iszero(returndatasize()))) { + if iszero(or(and(eq(mload(0x00), 0x01), lt(0x1f, returndatasize())), iszero(returndatasize()))) { mstore(0x00, 0x7939f424) // Selector for `TransferFromFailed()` revert(0x1c, 0x04) } @@ -92,7 +92,7 @@ library SafeTransferLib { } // We check that the call either returned exactly 1 [true] (can't just be non-zero // data), or had no return data. - if iszero(or(and(eq(mload(0x00), 0x01), gt(returndatasize(), 0x1f)), iszero(returndatasize()))) { + if iszero(or(and(eq(mload(0x00), 0x01), lt(0x1f, returndatasize())), iszero(returndatasize()))) { mstore(0x00, 0x90b8ec18) // Selector for `TransferFailed()` revert(0x1c, 0x04) } @@ -119,7 +119,7 @@ library SafeTransferLib { } // We check that the call either returned exactly 1 [true] (can't just be non-zero // data), or had no return data. - if iszero(or(and(eq(mload(0x00), 0x01), gt(returndatasize(), 0x1f)), iszero(returndatasize()))) { + if iszero(or(and(eq(mload(0x00), 0x01), lt(0x1f, returndatasize())), iszero(returndatasize()))) { mstore(0x00, 0x3e3f8f73) // Selector for `ApproveFailed()` revert(0x1c, 0x04) }