Skip to content

SleepingShell/darkforest-noir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Noir implementation of the circuits involved in the Dark Forest game (https://zkga.me).

As a demonstration of the Noir language, this repository aims to adapt the zero knowledge verification in the smart contracts to ones generated by Noir.

After installing the needed dependencies, run genContracts.sh to generate the solidity verification of the circuits, and copy them to the contracts submodule with names based on their circuit.

Aspects of the game involving ZKPs

The goal of the dark forest project is to create a game in which there is a trustless state of the system, aka the objects and their owners inside the finite galaxy, where participants only have a partial view into the state of the game.

This is mostly achieved through its fog of war. Players must mine, similar to Proof of Work currencies, the locations of planets by sequencing through points in space. Similar to PoW, only certain points in space will contain planets (based on their rarity), and this calculation depends on the hash commitment of the point in space, and its corresponding Perlin value. Unlike PoW, the point that generated this hash (aka Location ID) is not revealed publicly (until the corresponding function to do so is called).

Using zero knowledge proofs, we can prove properties about a point in space, without revealing the actual (x,y) coordinates. Whenever a player initializes or moves to a planet, a proof is provided attesting to the valid values of the hash commitment and perlin value, which are provided to the publicly known state.

The power of this is that not only is a fog of war possible in a completely security-equal computing enviornment, but also that fog of war can be procedurally generated without having to store the state anywhere.

Perlin Noise

Perlin Noise is a common method in gaming for procedural generation. It is a function that creates smooth scaling of its output while still containing random generation. Points that are closer together will have closer perlin values.

The high level overview of Perlin scaling is that it will segment the defined space into a grid of set lengths. Each vertex of the grid will have a randomly directed gradient vector in order to add randomness to the output. Depending on how close a point is to the 4 gradients of the square it is in will determine its influence on the output value.

Noir Notes

The contracts have been modified to use Noir generated SNARKs.

Run ./genContracts.sh to compile the contract verifiers with nargo and copy them to the eth/contracts/verifiers folder

Because bb.js cannot be used in conjunction with Hardhat, the testing is done through vitest and connecting to a localhost provider. You can use either Hardhat Network or Anvil, I run the latter because it runs much faster.

After starting a node, navigate to the eth submodule and run

yarn hardhat:deploy
yarn test:snarks

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published