-
Notifications
You must be signed in to change notification settings - Fork 45
Mining salt
In version 2.0.0, all contract addresses match the pattern 0xc700...0051.
This decision aims to make the addresses more easily recognizable on UIs.
We can make the address match the pattern through a technique called salt mining.
Essentially, we perform a brute-force search for a salt that yields an address matching the desired pattern.
In this wiki page, we explain how to perform this technique.
- jq
- foundry
- corepack
- cargo
- Clone the
cartesi/rollups-contractsrepository, install the dependencies, and build it. Read the instructions on the repository to make sure you have all the dependencies required.
pnpm install
forge soldeer install
forge build- Clone the
beincom/create2-vanity-minerrepository, and build it. Read the instructions from the repository carefully to make sure that you have your GPUs configured to operate with OpenCL.
cargo build --release- Store the
create2crunchprogram in a directory in yourPATHenvironment variable.
CREATE2CRUNCH_BIN=$HOME/.create2crunch/bin
mkdir -p "$CREATE2CRUNCH_BIN"
cp target/release/create2crunch "$CREATE2CRUNCH_BIN"
export PATH="$PATH:$CREATE2CRUNCH_BIN"- Make sure the
create2crunchprogram is now accessible from yourPATHenvironment variable.
which create2crunch- In the
rollups-contractsrepository, spin up a devnet.
pnpm start- Then, on another terminal tab, create a Bash script with the following contents.
#!/usr/bin/env bash
set -euo pipefail
[[ $# -ge 1 ]] || (>&2 echo "Usage: $0 deployment_file_path" && exit 1)
deployment_file_path=$1
shift
# deploy tx
[[ -f "$deployment_file_path" ]] || (>&2 echo "File $deployment_file_path does not exist" && exit 1)
deploy_tx_hash=$(jq -r .deployTxnHash -- "$deployment_file_path")
[[ "$deploy_tx_hash" =~ ^0x[0-9a-fA-F]{64}$ ]] || (>&2 echo "Ill-formed deployment transaction hash: $deploy_tx_hash" && exit 1)
deploy_tx=$(cast tx --json -- "$deploy_tx_hash")
# factory address
factory_address=$(echo "$deploy_tx" | jq -r .to)
[[ "$factory_address" =~ ^0x[0-9a-fA-F]{40}$ ]] || (>&2 echo "Ill-formed factory address: $factory_address" && exit 1)
# calling address (for Archnid's factory, this can be zero)
calling_address=$(cast address-zero)
# init code hash
deploy_tx_input=$(echo "$deploy_tx" | jq -r .input)
[[ "$deploy_tx_input" =~ ^0x[0-9a-fA-F]{64}([0-9a-fA-F]{2})*$ ]] || (>&2 echo "Ill-formed deployment transaction input: $deploy_tx_input" && exit 1)
init_code=$(echo "$deploy_tx_input" | sed -E 's/^0x[0-9a-fA-F]{64}/0x/')
[[ "$init_code" =~ ^0x([0-9a-fA-F]{2})*$ ]] || (>&2 echo "Ill-formed init code: $init_code" && exit 1)
init_code_hash=$(cast keccak -- "$init_code")
[[ "$init_code_hash" =~ ^0x[0-9a-fA-F]{64}$ ]] || (>&2 echo "Ill-formed init code hash: $init_code_hash" && exit 1)
# gpu device (use all available GPUs)
gpu_device=255
# address prefix and suffix (CTSI)
starts_with='c700'
ends_with='0051'
create2crunch "$factory_address" "$calling_address" "$init_code_hash" "$gpu_device" "$starts_with" "$ends_with"- Give yourself permission to execute the Bash script.
chmod +x calculate_salt_for.sh- Check which contracts don't match the address pattern yet by running the following command.
jq -r '"\(.contractName) \(.address)"' deployments/*.json | sort | grep -iv '\<0xc700[0-9a-f]*0051\>'- Then, find the first contract on the Cannonfile whose address doesn't match the pattern. Let us say, for example, this contract is the
InputBoxcontract. Then, with the devnet running in the background, run the following command.
./calculate_salt_for.sh deployments/InputBox.json- This will initiate the salt mining process, utilizing all available GPUs on your machine. Then, as soon as a salt is found, it will be displayed like so:
total runtime: 0:01:34.59818696975708 (110 cycles) work size per cycle: 67,108,864
rate: 77.91 million attempts per second total found this run: 1
current search space: fd0a7e1dxxxxxxxxeb5af27e
0x000000000000000000000000000000000000000080a213e9ec68fb034117851c => 0xc700285Ab555eeB5201BC00CFD4b2CC8DED90051 (2 / 2)
-
On the left side of the arrow is the salt, and on the right side is the address derived from it. Copy the salt and paste it as the value for the
saltfield of the deployment of the contract that you just mined the salt for. -
Restart the devnet (by killing the
pnpm startcommand and re-running it) and repeat the process until all contract addresses match the pattern.