Skip to content

0zKillua/Battleship_v1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Background

OnChain Battleship - Complete MVP

A fully functional Battleship game implementation using Merkle proofs for verification without zero-knowledge proofs.

๐Ÿ“ฅ How to Download Everything

Method 1: Download Individual Files

Click on each file name below to download:

  • Smart Contract: ImprovedOnChainBattleship.sol
  • Package Config: package.json
  • Hardhat Config: hardhat.config.js
  • Deployment Script: deploy.js
  • Environment Template: .env.example

๐Ÿš€ Smart Contract Setup

1. Create Project Directory

mkdir onchain-battleship
cd onchain-battleship

2. Initialize Node.js Project

npm init -y

3. Install Dependencies

npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox
npm install @openzeppelin/contracts

4. Create Directory Structure

mkdir contracts
mkdir scripts
mkdir test

5. Move Files to Correct Locations

  • Move ImprovedOnChainBattleship.sol to contracts/
  • Move deploy.js to scripts/
  • Keep hardhat.config.js and package.json in root directory
  • Copy .env.example to .env and fill in your values

๐Ÿ”ง Environment Setup

1. Create .env File

cp .env.example .env

2. Fill in Your Values

PRIVATE_KEY=your_private_key_here
SEPOLIA_RPC_URL=https://rpc.sepolia.org
ETHERSCAN_API_KEY=your_etherscan_api_key_here

โš ๏ธ IMPORTANT: Never share your private key! Use a testnet wallet.

๐ŸŽฏ Deploy Contract

1. Compile Contract

npx hardhat compile

2. Deploy to Sepolia Testnet

npx hardhat run scripts/deploy.js --network sepolia

3. Verify Contract (Optional)

npx hardhat verify CONTRACT_ADDRESS --network sepolia

๐Ÿ“‹ Project Structure

onchain-battleship/
โ”œโ”€โ”€ contracts/
โ”‚   โ””โ”€โ”€ ImprovedOnChainBattleship.sol
โ”œโ”€โ”€ scripts/
โ”‚   โ””โ”€โ”€ deploy.js
โ”œโ”€โ”€ test/
โ”œโ”€โ”€ hardhat.config.js
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ .env.example
โ””โ”€โ”€ README.md

๐ŸŽฎ Frontend Usage

The frontend is completely standalone and works without any blockchain connection:

  1. Ship Placement: Drag and drop 5 ships onto your 10x10 grid
  2. Battle Phase: Click enemy grid squares to attack
  3. Visual Effects: See explosions for hits, splashes for misses
  4. Victory: Game ends when all ships are destroyed

๐Ÿ”’ Security Features

Smart Contract Security

  • ReentrancyGuard: Prevents reentrancy attacks
  • Pausable: Emergency stop functionality
  • Ownable: Owner controls for emergency situations
  • Input Validation: Coordinate and state validation
  • Timeout System: Prevents griefing attacks

Game Integrity

  • Merkle Proof Verification: All moves verified cryptographically
  • Anti-Cheat System: Economic penalties for invalid proofs
  • Timeout Mechanisms: 24-hour move timeout, 7-day reveal timeout
  • Slashing Logic: Cheaters forfeit their stakes

๐Ÿ’ฐ Game Economics

  • Stake: 0.1 ETH per game (perfect for testnet)
  • Winner Takes All: Winner receives both stakes (0.2 ETH total)
  • Slashing: Cheaters lose their stake to honest players
  • Timeouts: Non-responsive players forfeit their stakes

๐Ÿงช Testing

Run Tests

npx hardhat test

Local Development

npx hardhat node

๐ŸŒ Network Support

  • Sepolia Testnet: Recommended for testing
  • Goerli Testnet: Alternative testnet
  • Mainnet: Production deployment

๐Ÿ“– Game Rules

  1. Standard Battleship: 5 ships (Carrier:5, Battleship:4, Cruiser:3, Submarine:3, Destroyer:2)
  2. Turn-Based: Players alternate making guesses
  3. Merkle Proofs: All hits/misses verified cryptographically
  4. Win Condition: First to sink all opponent ships wins
  5. Anti-Cheat: Invalid proofs result in automatic loss

๐Ÿ†˜ Troubleshooting

Common Issues

  1. "Invalid private key": Make sure your private key is 64 characters (without 0x prefix)
  2. "Insufficient funds": Ensure your wallet has testnet ETH
  3. "Contract not found": Check if contract address is correct
  4. "Network error": Verify RPC URL is working

Get Testnet ETH

๐Ÿ“š Additional Resources

๐ŸŽฏ Next Steps

  1. Test Locally: Deploy to local hardhat network
  2. Testnet Deployment: Deploy to Sepolia testnet
  3. Frontend Integration: Connect frontend to deployed contract
  4. Security Audit: Professional security review
  5. Mainnet Launch: Production deployment

๐Ÿค Support

For questions or issues:

  1. Check the troubleshooting section
  2. Review Hardhat documentation
  3. Test on local network first
  4. Verify all environment variables are set correctly

Status: Ready for deployment and testing! ๐Ÿšขโš“

About

Implementation of Battleship game without using fancy ZK,FHE like tech. Only using Merkle Proofs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors