Skip to content

Commit e7881f9

Browse files
ae2079cursoragent
andcommitted
fix: align CreateX deployment checks
Use CreateX's guarded salt for deterministic address prediction. Retry the CreateX preflight check to tolerate flaky RPC responses. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f3946df commit e7881f9

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

script/DeployDonationHandlerImplementation.s.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {Script, console} from 'forge-std/Script.sol';
1010

1111
interface ICreateX {
1212
function deployCreate2(bytes32 salt, bytes memory initCode) external payable returns (address deployed);
13+
/// @dev Two-arg overload uses deployer = CreateX (`_SELF`). `salt` must match `_guard(userSalt)` used inside `deployCreate2`.
1314
function computeCreate2Address(bytes32 salt, bytes32 initCodeHash) external view returns (address computed);
1415
}
1516

@@ -28,7 +29,9 @@ contract DeployDonationHandlerImplementation is Script {
2829
bytes memory initCode = type(DonationHandler).creationCode;
2930
bytes32 initCodeHash = keccak256(initCode);
3031

31-
address predicted = CREATEX.computeCreate2Address(IMPLEMENTATION_SALT, initCodeHash);
32+
// CreateX `deployCreate2` hashes arbitrary salts via `_guard`; predict using the same guarded salt.
33+
bytes32 guardedSalt = keccak256(abi.encode(IMPLEMENTATION_SALT));
34+
address predicted = CREATEX.computeCreate2Address(guardedSalt, initCodeHash);
3235

3336
console.log('=== CREATE2 DonationHandler implementation (CreateX) ===');
3437
console.log('Predicted address:', predicted);

scripts/deploy-implementation.sh

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ set -e
55
# Usage: ./scripts/deploy-implementation.sh <chain>
66
# Requires .env: PRIVATE_KEY, <CHAIN>_RPC (e.g. BASE_RPC), ETHERSCAN_API_KEY for --verify
77
#
8+
# Optional env for CreateX prefetch retries (RPC flake): CREATEX_MAX_ATTEMPTS (default 5), CREATEX_RETRY_DELAY_SEC (default 4).
9+
#
810
# Build uses FOUNDRY_PROFILE=deterministic — see foundry.toml (must match manual forge script runs).
911
# Chain names match foundry.toml [rpc_endpoints] keys (mainnet, base, sepolia, ...).
1012
#
@@ -26,11 +28,38 @@ if [[ -z "${!RPC_VAR}" ]]; then
2628
fi
2729

2830
CREATEX_ADDRESS="0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed"
29-
CREATEX_CODE=$(cast code "$CREATEX_ADDRESS" --rpc-url "${!RPC_VAR}" 2>/dev/null || true)
30-
if [[ -z "$CREATEX_CODE" || "$CREATEX_CODE" == "0x" ]]; then
31-
echo "Error: CreateX not deployed at $CREATEX_ADDRESS on this RPC (cast code returned empty)."
32-
exit 1
33-
fi
31+
CREATEX_MAX_ATTEMPTS="${CREATEX_MAX_ATTEMPTS:-5}"
32+
CREATEX_RETRY_DELAY_SEC="${CREATEX_RETRY_DELAY_SEC:-4}"
33+
34+
createx_ok() {
35+
local code="$1"
36+
[[ -n "$code" && "$code" != "0x" && ${#code} -gt 10 ]]
37+
}
38+
39+
attempt=1
40+
CREATEX_CODE=""
41+
while [[ $attempt -le $CREATEX_MAX_ATTEMPTS ]]; do
42+
err_file=$(mktemp)
43+
if CREATEX_CODE=$(cast code "$CREATEX_ADDRESS" --rpc-url "${!RPC_VAR}" 2>"$err_file"); then
44+
:
45+
fi
46+
if createx_ok "$CREATEX_CODE"; then
47+
rm -f "$err_file"
48+
break
49+
fi
50+
echo "Warning: CreateX prefetch attempt $attempt/$CREATEX_MAX_ATTEMPTS failed or returned empty."
51+
if [[ -s "$err_file" ]]; then
52+
echo "cast stderr:"
53+
cat "$err_file"
54+
fi
55+
rm -f "$err_file"
56+
if [[ $attempt -eq $CREATEX_MAX_ATTEMPTS ]]; then
57+
echo "Error: CreateX not available at $CREATEX_ADDRESS after $CREATEX_MAX_ATTEMPTS attempts (wrong chain, RPC down, or TLS/network flake)."
58+
exit 1
59+
fi
60+
sleep "$CREATEX_RETRY_DELAY_SEC"
61+
attempt=$((attempt + 1))
62+
done
3463

3564
LEGACY_CHAINS="celo gnosis"
3665
LEGACY_FLAG=""

0 commit comments

Comments
 (0)