44# Colors for output
55GREEN=' \033[0;32m'
66YELLOW=' \033[1;33m'
7+ RED=' \033[0;31m' # Add this line
78NC=' \033[0m' # No Color
89
910echo -e " ${GREEN} Starting Tornado Cash Privacy Solution Transaction Script${NC} "
@@ -69,7 +70,12 @@ cd ../scripts
6970echo -e " ${YELLOW} Step 3: Building and deploying the program...${NC} "
7071cd ..
7172echo " Building the program..."
72- cargo build-bpf || { echo -e " ${RED} Error: Failed to build the program.${NC} " ; exit 1; }
73+ # Try the newer cargo build-sbf command first, fall back to cargo build-bpf if not available
74+ if command -v cargo build-sbf & > /dev/null; then
75+ cargo build-sbf || { echo -e " ${RED} Error: Failed to build the program.${NC} " ; exit 1; }
76+ else
77+ cargo build-bpf || { echo -e " ${RED} Error: Failed to build the program.${NC} " ; exit 1; }
78+ fi
7379
7480echo " Deploying the program..."
7581DEPLOY_OUTPUT=$( solana program deploy target/deploy/tornado_svm.so)
@@ -89,7 +95,7 @@ sed -i "s/YourProgramIdHere/$PROGRAM_ID/g" client/tornado-cli.js
8995# Step 4: Initialize a tornado instance
9096echo -e " ${YELLOW} Step 4: Initializing tornado instance...${NC} "
9197cd client
92- INIT_OUTPUT=$( node tornado-cli.js initialize --keypair " $WALLET_PATH " --denomination $DENOMINATION --height $MERKLE_TREE_HEIGHT )
98+ INIT_OUTPUT=$( npx ./ tornado-cli.js initialize --keypair " $WALLET_PATH " --denomination $DENOMINATION --height $MERKLE_TREE_HEIGHT )
9399TORNADO_INSTANCE=$( echo " $INIT_OUTPUT " | grep " Tornado instance created:" | awk ' {print $4}' )
94100
95101if [ -z " $TORNADO_INSTANCE " ]; then
@@ -105,7 +111,7 @@ sleep 5
105111
106112# Step 5: Generate a commitment
107113echo -e " ${YELLOW} Step 5: Generating commitment...${NC} "
108- COMMITMENT_OUTPUT=$( node tornado-cli.js generate-commitment)
114+ COMMITMENT_OUTPUT=$( npx ./ tornado-cli.js generate-commitment)
109115NOTE_PATH=$( echo " $COMMITMENT_OUTPUT " | grep " Note saved to" | awk ' {print $4}' )
110116COMMITMENT=$( echo " $COMMITMENT_OUTPUT " | grep " Commitment:" | awk ' {print $2}' )
111117
@@ -120,7 +126,7 @@ echo "Commitment: $COMMITMENT"
120126
121127# Step 6: Deposit funds
122128echo -e " ${YELLOW} Step 6: Depositing funds...${NC} "
123- DEPOSIT_OUTPUT=$( node tornado-cli.js deposit --keypair " $WALLET_PATH " --instance " $TORNADO_INSTANCE " --commitment " $COMMITMENT " --amount $DENOMINATION )
129+ DEPOSIT_OUTPUT=$( npx ./ tornado-cli.js deposit --keypair " $WALLET_PATH " --instance " $TORNADO_INSTANCE " --commitment " $COMMITMENT " --amount $DENOMINATION )
124130DEPOSIT_SIGNATURE=$( echo " $DEPOSIT_OUTPUT " | grep " Transaction signature:" | awk ' {print $3}' )
125131
126132if [ -z " $DEPOSIT_SIGNATURE " ]; then
@@ -137,13 +143,39 @@ sleep 10
137143
138144# Step 7: Get the Merkle tree account
139145echo -e " ${YELLOW} Step 7: Getting Merkle tree account...${NC} "
140- # Get the Merkle tree account using the seed
141- MERKLE_TREE_SEED=" merkle_tree${TORNADO_INSTANCE} 0"
142- MERKLE_TREE=$( solana address --keypair " $WALLET_PATH " --seed " $MERKLE_TREE_SEED " $PROGRAM_ID )
146+ # Get the Merkle tree account using find-program-address
147+ MERKLE_TREE=$( solana address find-program-address \
148+ --input " merkle_tree" \
149+ --input " $TORNADO_INSTANCE " \
150+ --input " 0" \
151+ --program-id " $PROGRAM_ID " | head -1)
143152
144153if [ -z " $MERKLE_TREE " ]; then
145154 echo -e " ${RED} Error: Failed to get Merkle tree account.${NC} "
146- exit 1
155+ # Try alternative method for older Solana CLI versions
156+ echo " Trying alternative method..."
157+ # In older versions, we need to use a different approach
158+ # We'll use the tornado-cli.js to get the Merkle tree account
159+ cd ../client
160+ MERKLE_TREE_OUTPUT=$( node -e "
161+ const { PublicKey } = require('@solana/web3.js');
162+ const programId = new PublicKey('$PROGRAM_ID ');
163+ const tornadoInstance = new PublicKey('$TORNADO_INSTANCE ');
164+ const seeds = [
165+ Buffer.from('merkle_tree', 'utf8'),
166+ tornadoInstance.toBuffer(),
167+ Buffer.from([0])
168+ ];
169+ const [merkleTreePubkey] = PublicKey.findProgramAddressSync(seeds, programId);
170+ console.log(merkleTreePubkey.toString());
171+ " )
172+ MERKLE_TREE=$MERKLE_TREE_OUTPUT
173+ cd ../scripts
174+
175+ if [ -z " $MERKLE_TREE " ]; then
176+ echo -e " ${RED} Error: Failed to get Merkle tree account using alternative method.${NC} "
177+ exit 1
178+ fi
147179fi
148180
149181echo " Merkle tree account: $MERKLE_TREE "
166198echo -e " ${YELLOW} Step 9: Generating proof for withdrawal...${NC} "
167199cd ../client
168200RECIPIENT=$( solana address)
169- PROOF_OUTPUT=$( node tornado-cli.js generate-proof --note " $NOTE_PATH " --root " $ROOT " --recipient " $RECIPIENT " )
201+ PROOF_OUTPUT=$( npx ./ tornado-cli.js generate-proof --note " $NOTE_PATH " --root " $ROOT " --recipient " $RECIPIENT " )
170202PROOF=$( echo " $PROOF_OUTPUT " | grep " Proof:" | awk ' {print $2}' )
171203NULLIFIER_HASH=$( echo " $PROOF_OUTPUT " | grep " Nullifier hash:" | awk ' {print $3}' )
172204
@@ -181,7 +213,7 @@ echo "Nullifier hash: $NULLIFIER_HASH"
181213
182214# Step 10: Withdraw funds
183215echo -e " ${YELLOW} Step 10: Withdrawing funds...${NC} "
184- WITHDRAW_OUTPUT=$( node tornado-cli.js withdraw --keypair " $WALLET_PATH " --instance " $TORNADO_INSTANCE " --proof " $PROOF " --root " $ROOT " --nullifier-hash " $NULLIFIER_HASH " --recipient " $RECIPIENT " )
216+ WITHDRAW_OUTPUT=$( npx ./ tornado-cli.js withdraw --keypair " $WALLET_PATH " --instance " $TORNADO_INSTANCE " --proof " $PROOF " --root " $ROOT " --nullifier-hash " $NULLIFIER_HASH " --recipient " $RECIPIENT " )
185217WITHDRAW_SIGNATURE=$( echo " $WITHDRAW_OUTPUT " | grep " Transaction signature:" | awk ' {print $3}' )
186218
187219if [ -z " $WITHDRAW_SIGNATURE " ]; then
0 commit comments