Secure your ideas the moment they're conceived. ZK-Patent uses AI, Zero-Knowledge Proofs, and NFTs to create immutable, privacy-preserving timestamps for your intellectual property.
When you have a groundbreaking idea, you want to establish proof of prior art without revealing the idea itself. Publicly disclosing details can jeopardize your ability to patent it later, while keeping it secret offers no protection against others claiming it first.
ZK-Patent solves this dilemma by leveraging the power of modern cryptography and blockchain technology.
You can prove you had the idea at a specific time, without ever putting the idea on-chain. Innovate, protect, publish ā faster than ever.
PatentNFT
smart contract with the user's address and the ZK proof.Verifier
checks the proof's validity using on-chain verification.The system consists of two main smart contracts deployed on Ethereum:
Verifier.sol
)verifyProof(uint[2] _pA, uint[2][2] _pB, uint[2] _pC, uint[2] _pubSignals)
// Core verification function
function verifyProof(
uint[2] calldata _pA,
uint[2][2] calldata _pB,
uint[2] calldata _pC,
uint[2] calldata _pubSignals
) public view returns (bool)
PatentNFT.sol
)// Main minting function with ZK proof verification
function mintWithProof(
address to,
uint256[2] memory a,
uint256[2][2] memory b,
uint256[2] memory c,
uint256[2] memory input
) public onlyOwner
Contract Flow:
mintWithProof()
with proof parametersIdeaProven
event is emitted for indexingThis project relies on pre-compiled ZK-SNARK artifacts: a prover key (.zkey
), a WebAssembly circuit (.wasm
), and a Solidity verifier contract (Verifier.sol
). Here is the high-level process used to generate them.
The core of the ZK logic is in circuits/circuit.circom
. This circuit takes a private input (the preimage
of the idea), computes its Poseidon hash, and exposes the resulting hash as a public output. This allows us to prove we know the preimage
for a given public hash without revealing it.
First, compile the .circom
file. This generates the R1CS (Rank-1 Constraint System) file, which is a mathematical representation of the circuit, and the .wasm
file used for generating proofs.
# Create a directory for the output files
mkdir -p circuits/compiled
# Compile the circuit
circom circuits/circuit.circom --r1cs --wasm --sym -o circuits/compiled
To create a secure ZK-SNARK, we start with a "Powers of Tau" file from a trusted public ceremony. This is a universal setup that can be used for any circuit up to a certain size. We'll use a file that supports up to 2^20 constraints, which is more than sufficient.
# Download the .ptau file
curl -o circuits/powers_of_tau_28_hez_final_20.ptau https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_20.ptau
Next, we use snarkjs
to create the initial prover key (.zkey
) for our specific circuit using the .ptau
file.
snarkjs groth16 setup circuits/compiled/circuit.r1cs circuits/powers_of_tau_28_hez_final_20.ptau circuits/compiled/circuit_0000.zkey
For a production system, this .zkey
would need multiple contributions from different parties to be secure. For this project, a single contribution is sufficient to finalize the key.
snarkjs zkey contribute circuits/compiled/circuit_0000.zkey circuits/compiled/circuit_final.zkey --name="zk-patent 1st contribution" -v -e="some random text for entropy"
Finally, we export the verifier from our final .zkey
. This generates a Solidity smart contract (Verifier.sol
) that can verify proofs on-chain.
snarkjs zkey export solidityverifier circuits/compiled/circuit_final.zkey contracts/Verifier.sol
The generated Verifier.sol
is then deployed, and its address is passed to the constructor of the main PatentNFT.sol
contract. The circuit_final.zkey
and circuit.wasm
files are placed in circuits/compiled/
for the backend to use when generating proofs.
Follow these steps to set up and run the project locally.
git clone https://github.com/your-username/zk-patent.git
cd zk-patent
This command installs all necessary packages and creates the pnpm-lock.yaml
file, which is crucial for the Docker build step.
pnpm install
Create a .env
file in the root of the project by copying the example file:
cp .env.example .env
Now, open the .env
file and fill in the following values:
GEMINI_API_KEY
: Your API key for the Google Gemini AI service.SEPOLIA_RPC_URL
: Your RPC endpoint URL for the Sepolia testnet (e.g., from Alchemy or Infura).MINTER_PRIVATE_KEY
: The private key of the wallet that will pay the gas fees to mint the NFTs. This wallet must be the owner of the deployed smart contract.PATENT_NFT_CONTRACT_ADDRESS
: The address of your deployed PatentNFT
contract.CONTRACT_GENESIS_BLOCK
: The block number when your contract was deployed (for efficient event scanning).You're all set! Start the SvelteKit app:
pnpm run dev
Open your browser to http://localhost:5173
to use the application.
zk-patent/
āāā circuits/ # ZK circuit files
ā āāā circuit.circom # Core ZK circuit definition
ā āāā compiled/ # Compiled circuit artifacts
āāā contracts/ # Smart contracts
ā āāā PatentNFT.sol # Main NFT contract
ā āāā Verifier.sol # ZK proof verifier
āāā src/
ā āāā lib/
ā ā āāā components/ # Svelte components
ā ā āāā server/ # Server-side utilities
ā āāā routes/ # SvelteKit routes and API endpoints
āāā static/ # Static assets
We welcome contributions! This project uses prettier
for code formatting and eslint
for linting.
This project is equipped with Husky, which sets up Git hooks to automate quality checks. After you run pnpm install
, Husky is automatically configured.
When you make a commit, Husky will automatically:
prettier
to format your staged files.eslint
to check for any linting errors.commitlint
to ensure your commit message follows the Conventional Commits standard.If any of these checks fail, your commit will be aborted. This ensures that all code committed to the repository maintains a consistent style and quality.