Skip to content

Commit

Permalink
added command line to the creator
Browse files Browse the repository at this point in the history
  • Loading branch information
mm-zk committed Sep 1, 2024
1 parent 244e875 commit 4e110f1
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__/utils.cpython-310.pyc
/target
qr/target
sp1/elf/riscv32im-succinct-zkvm-elf
tmp/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ The goal is to create a QR code that contains a self-contained zk proof of some
Generate the .json file with all the data using the python creator file:

```shell
python3 online_creator.py 0xbe8d5c1eba50aec04e07d627fb2bfcf71cafd242c9e231681ffc5aba12cc385c
python3 online_creator.py transaction 0xbe8d5c1eba50aec04e07d627fb2bfcf71cafd242c9e231681ffc5aba12cc385c tmp/output_file.json
```

(or for NFT):
### Running (for NFT)

```shell
python3 online_creator.py nft 0x1f13941d0995e111675124af4b0f9bdcc70390c3 0xfac041bcf2c4b43319c2c0a39aba53f4cbe44fe5
python3 online_creator.py nft 0x1f13941d0995e111675124af4b0f9bdcc70390c3 0xfac041bcf2c4b43319c2c0a39aba53f4cbe44fe5 tmp/output_file.json
```

### Proving

This will result in the output.json file with necessary data.
This will result in the `output_file.json` file with necessary data.

Then you can verify it in sp1, by running (from the sp1/script directory):

Expand Down
Empty file removed config.json
Empty file.
3 changes: 0 additions & 3 deletions example.json

This file was deleted.

File renamed without changes.
File renamed without changes.
69 changes: 41 additions & 28 deletions online_creator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import sys
import json
from web3 import Web3
Expand Down Expand Up @@ -554,39 +555,51 @@ def parse_address_from_hex_to_bytes(addr_hex: str):


def main():
# Check if at least one argument is provided
if len(sys.argv) > 2:
command = sys.argv[1]
if command == "tx":
transaction_id = sys.argv[2]

file_path = "output.json"
if len(transaction_id) != 66 or transaction_id[:2] != "0x":
print("Please pass correct transaction id. For example 0xb07cf51bb1fb788e9ab4961af203ce1057cf40f2781007ff06e7c66b6fc814be")
return
data = prove_tx_inclusion_in_chain(transaction_id)

with open(file_path, 'w') as file:
json.dump(data, file, indent=4)

print("Stored result in output.json")
elif command == "nft":
nft_id = parse_address_from_hex_to_bytes(sys.argv[2])
nft_owner = parse_address_from_hex_to_bytes(sys.argv[3])

file_path = "output_nft.json"
parser = argparse.ArgumentParser(description='Milano - Proof witness creator')

# Command subparsers
subparsers = parser.add_subparsers(dest='command', required=True, help='Type of command')

# Subparser for the "transaction" command
parser_transaction = subparsers.add_parser('transaction', help='Prove a transaction')
parser_transaction.add_argument('transaction_id', type=str, help='Transaction ID')

# Subparser for the "NFT" command
parser_nft = subparsers.add_parser('nft', help='Prove an NFT ownership ')
parser_nft.add_argument('nft_address', type=str, help='NFT Address')
parser_nft.add_argument('owner', type=str, help='Owner of the NFT')

# Common argument for both commands
parser.add_argument('output_file', type=str, help='JSON file name to write the output to')

# Parse the arguments
args = parser.parse_args()

# Handle arguments based on the command
if args.command == 'transaction':
print(f"Handling transaction ID: {args.transaction_id}")
print(f"Output will be written to: {args.output_file}")
if len(args.transaction_id) != 66 or args.transaction_id[:2] != "0x":
print("Please pass correct transaction id. For example 0xb07cf51bb1fb788e9ab4961af203ce1057cf40f2781007ff06e7c66b6fc814be")
return
data = prove_tx_inclusion_in_chain(args.transaction_id)

data = prove_nft_ownership(nft_id, nft_owner)
with open(file_path, 'w') as file:
json.dump(data, file, indent=4)
with open(args.output_file, 'w') as file:
json.dump(data, file, indent=4)

elif args.command == 'nft':
print(f"Handling NFT at address: {args.nft_address} with owner: {args.owner}")
print(f"Output will be written to: {args.output_file}")
nft_id = parse_address_from_hex_to_bytes(args.nft_address)
nft_owner = parse_address_from_hex_to_bytes(args.owner)

else:
help()



data = prove_nft_ownership(nft_id, nft_owner)
with open(args.output_file, 'w') as file:
json.dump(data, file, indent=4)
else:
help()
print(f"INVALID COMMAND - {args.command}")


if __name__ == "__main__":
Expand Down

0 comments on commit 4e110f1

Please sign in to comment.