A step-by-step tutorial to find and attack your first contract on BattleChain
This tutorial walks you through finding an attackable contract, verifying its Safe Harbor terms, and executing a legal attack. By the end, you’ll understand the complete whitehat workflow.
Prerequisites: Familiarity with smart contract security and Solidity.
Query the AttackRegistry to check if a contract is attackable:
// Check if a specific contract is in attack modebool isAttackable = attackRegistry.isTopLevelContractUnderAttack(targetContract);if (isAttackable) { // This contract can be legally attacked under Safe Harbor}
To find contracts to attack, monitor for AgreementStateChanged events:
event AgreementStateChanged(address indexed agreementAddress, ContractState newState);// newState = 3 (UNDER_ATTACK) means contracts are attackable// newState = 4 (PROMOTION_REQUESTED) means still attackable during 3-day delay
// Verify contract is in the agreement's scopebool inScope = agreement.isContractInScope(targetContract);require(inScope, "Contract not in scope - no Safe Harbor protection!");// Verify agreement is valid (created by official factory)bool validAgreement = safeHarborRegistry.isAgreementValid(agreementAddr);require(validAgreement, "Invalid agreement!");
// Get the asset recovery address for BattleChainstring memory recoveryAddrStr = agreement.getAssetRecoveryAddress("eip155:325");// Parse to address (you'll need a helper for this)address recoveryAddress = parseAddress(recoveryAddrStr);