Skip to main content

SHA-1 Collision Challenge

The SHA-1 Collision Challenge is a core component of Mineable UTXOs on OP_NET. It provides a unique mechanism for miners to claim rewards by solving cryptographic puzzles, contributing to both the security and utility of the network.


Understanding the Collision Challenge

The challenge requires miners to find a solution that collides with a given preimage (preimage1) to produce the same SHA-1 hash. This solution, once found, allows the spender to unlock the associated UTXO funds.

Conditions for success

SHA1(solution) == SHA1(preimage1)

This mechanism transforms OP_NET into a dual-purpose platform, merging traditional transaction validation with cryptographic mining.


Bitcoin Script Example

Below is a simplified Bitcoin script enforcing a SHA-1 collision challenge.

OP_2DUP          # Duplicate top two items (preimage1, preimage2)
OP_EQUAL # Compare them. Push 1 if equal, else 0
OP_NOT # Ensure they are distinct
OP_VERIFY # Fail if not distinct
OP_SHA1 # Replace top stack item with SHA-1(preimage1)
OP_SWAP # Swap top two stack items
OP_SHA1 # Replace new top stack item with SHA-1(preimage2)
OP_EQUAL # Ensure both hashes are identical

P2SH Redeem Script Example:

OP_HASH160 <redeemScriptHash> OP_EQUAL
Redeem Script Details

The spender must reveal:

  1. The solution that collides with preimage1
  2. The redeem script itself

Solving the Collision Challenge

Here’s a step-by-step guide to solving the challenge and claiming rewards:

// Step 1: Prepare the solution (hash collision)
const solution = Buffer.from(
"abe4bbf04b207bffce16000fd1c3a21c019cdfbea51f86cef4789b848c0a7d5cedd3151f262c964e323c73ef2d31bee518252acec5b895543eeabc8c4059b393a582d7be38dac8b70bb437e6c01d1b4e8c61d2ba2a5b8ed3e3c0a9cf2683b78b3a479de9866e44adf5425976579483b3b4f325847ceabe4f5e18d2ad8e568c58",
"hex"
);

// Step 2: Initialize the transaction factory
const txFactory = new TransactionFactory();

// Step 3: Generate the redeem script for the mineable reward
const redeemScript = ChallengeGenerator.generateMineableReward(
preimage1,
network
);

// Step 4: Fetch UTXOs (unspent transaction outputs) for the specified amount
const utxos = await provider.utxoManager.getUTXOsForAmount({
address: redeemScript.address, // Address derived from the redeem script
amount: 100000000n, // Required amount in satoshis
optimize: false, // Disable optimization to fetch raw UTXOs
});

// Step 5: Prepare the last UTXO for the transaction
const lastUTXO = utxos[utxos.length - 1] as UTXO; // Select the last UTXO
lastUTXO.redeemScript = redeemScript.p2shOutputScript; // Attach the redeem script

// Step 6: Define transaction parameters for solving the challenge
const challengeSolutionParams: IChallengeSolutionTransactionParameters = {
challengeSolution: solution, // Provide the collision solution
from: redeemScript.address, // Address funding the transaction
utxos: [lastUTXO], // UTXOs to be used
amount: BigInt(minDust), // Minimum dust amount to send
to: address.p2tr(network), // Destination address (Pay-to-Taproot in this case)
feeRate: feeRate, // Fee rate for the transaction
priorityFee: 0n, // Additional priority fee (none in this example)
network: network, // Current network configuration
signer: wallet.keypair, // Signer for the transaction
};

// Step 7: Create the transaction to solve the challenge
const fundingTransaction = await txFactory.createChallengeSolution(
challengeSolutionParams
);

// Step 8: Broadcast the transaction to the network
const result = await Configs.RPC.sendRawTransaction({
hexstring: fundingTransaction.tx, // Serialized transaction in hex format
});

What’s Next?

Learn more about how to implement and optimize cross-chain mining for your network: