Difficulty and Rewards
The XPower mining contract uses a probabilistic difficulty system with exponential rewards. Difficulty is measured in leading zero nibbles and the reward scales as a power of two.
Hash Function Specification
The miner constructs a 256-bit Keccak-256 hash over three concatenated components:
Where the three input components are:
| Component | Width | Source |
|---|---|---|
contractAddr XOR beneficiaryAddr | 160 bits (padded to 256) | address(this) ^ beneficiary |
blockHash | 256 bits | Avalanche block hash from init() |
data | 256 bits | Miner-supplied: 32 bytes containing the nonce |
The XOR of the contract address with the beneficiary address serves two purposes:
- Ties the hash to the specific contract — a nonce valid for one deployment is not valid for another
- Ties the hash to the intended recipient — prevents a miner from submitting the same nonce to benefit a different address
The data field is 32 bytes (256 bits), giving a search space of (beneficiary, blockHash) pair.
Why bytes20 Casting
The contract explicitly casts uint160(address(this)) ^ uint160(to) to bytes20 before concatenation. This ensures the XOR result occupies exactly 20 bytes in the hash preimage, with bytes.concat handling the conversion to a fixed-width bytes32.
Difficulty: Leading Zero Nibbles
Difficulty
The contract computes
In Solidity (XPower.sol:_zerosOf):
if (nonceHash > 0) {
return uint8(63 - (Math.log2(uint256(nonceHash)) >> 2));
}
return 64;Math.log2 returns the floor of the binary logarithm (position of the highest set bit). Dividing by 4 (>> 2) converts bits to nibbles. Subtracting from 63 gives the count of leading zero nibbles. A hash of zero would have
The contract requires nonceHash with no leading zero nibbles reverts with EmptyNonceHash.
Probability
For a uniformly random 256-bit hash, the probability that the first
Each nibble independently has a
Reward Formula
The XPOW reward for difficulty
In Solidity (XPower.sol:_amountOf):
function _amountOf(uint256 level) internal view returns (uint256) {
return (2 ** level - 1) * 10 ** decimals();
}Where decimals() returns 18, so the base unit is
| Reward (XPOW) | ||
|---|---|---|
| 1 | 1 | 1 |
| 2 | 3 | 3 |
| 3 | 7 | 7 |
| 4 | 15 | 15 |
| 5 | 31 | 31 |
| 6 | 63 | 63 |
| 7 | 127 | 127 |
| 8 | 255 | 255 |
The reward doubles plus one for each additional zero nibble. This creates a slight super-exponential relationship: doubling the difficulty (
Complete Difficulty-Reward Table
| Expected Hashes | Reward (XPOW) | |||
|---|---|---|---|---|
| 1 | 16 | 1 | 0.0625 | |
| 2 | 256 | 3 | 0.01171875 | |
| 3 | ~4K | 7 | 0.00170898 | |
| 4 | ~66K | 15 | 0.00022888 | |
| 5 | ~1M | 31 | 0.00002956 | |
| 6 | ~17M | 63 | 0.00000376 | |
| 7 | ~268M | 127 | 0.00000047 | |
| 8 | ~4.3B | 255 | 0.00000006 |
The last column shows each difficulty tier's contribution to the overall expected yield. The sum across all
The 50/50 Split
Every successful mint() call creates two identical mints:
_mint(owner(), amount); // treasury
_mint(to, amount); // beneficiaryThe owner() of the XPower contract is the MoeTreasury (set during deployment). This means each mining solution doubles the total XPOW supply, with exactly half flowing to the treasury that funds staking rewards.
Why Split?
The split serves multiple purposes:
- Protocol sustainability — The treasury accumulates XPOW to back APOW minting, funding the staking reward system indefinitely
- Incentive alignment — Stakers benefit from mining activity even if they don't mine themselves, creating a natural demand floor for XPOW
- No inflation-only token — Unlike pure mining tokens where miners are the only beneficiaries, the split ensures value flows to the entire ecosystem
Treasury to Staking Pipeline
The treasury half of each mining reward follows this path:
- Accumulation — XPOW is minted directly to
MoeTreasury's balance - Backing — Treasury XPOW backs APOW minting;
APower.mint()callsXPOW.transferFrom(treasury, APower, amount)to lock XPOW - Distribution — When stakers call
MoeTreasury.claim(), the treasury calculates(APR + APB) * age * denominationand callsAPower.mint(beneficiary, reward) - Rate limiting — APOW minting is rate-limited to ~1 token/minute (long-term mean), preventing treasury drain from batched claims
The treasury receives XPOW continuously (from mining) and releases APOW slowly (rate-limited), creating a natural buffer. See Rewards Overview for the full staking reward calculation.
Compound Difficulty
A miner searching for any valid solution experiences the union of all difficulty tiers. For a single hash attempt:
A randomly chosen hash has approximately a
Practical Implications
- Low difficulty (
) — 16 expected hashes, 1 XPOW reward (0.5 to beneficiary). Easily mined in-browser but requires frequent on-chain submissions, incurring gas costs - Medium difficulty (
) — ~66K expected hashes, 15 XPOW reward (7.5 to beneficiary). Balances hash effort against gas cost for most miners - High difficulty (
) — ~4.3B expected hashes, 255 XPOW reward (127.5 to beneficiary). Substantial computational investment; only viable with optimized mining software
The optimal target difficulty for a given miner depends on their hash rate, gas costs on Avalanche C-Chain, and the market value of XPOW.