Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Economic Model, Verifier Update and Cleanup #19

Merged
merged 48 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
a7f0121
clean up
xlassix Nov 22, 2024
840d942
Add NFT_CONTRACT_ID to .env.example file
xlassix Nov 22, 2024
62cea40
added cleanup
xlassix Nov 22, 2024
bfcc631
Fix panic message format for invalid payload check
xlassix Nov 22, 2024
2bf8320
containerized
xlassix Nov 23, 2024
afa344d
containerise
xlassix Nov 24, 2024
6976b5e
Add port 8007 to Dockerfile for bitte_plugin
xlassix Nov 25, 2024
6e292a7
Update app service configuration in docker-compose.yml
xlassix Nov 25, 2024
3a09c32
Remove submodule "src/verity" and update submodule URL
xlassix Nov 25, 2024
2f55e7d
Update .env.example with new variables and values
xlassix Nov 25, 2024
b0cf9fe
Update path for verity-verifier in Cargo.toml
xlassix Nov 25, 2024
e3f1d7d
feature: helper clean up
xlassix Nov 27, 2024
0441670
Fix typo in NEAR_CONTRACT_ADDRESS value in .env.example
xlassix Nov 27, 2024
07b96b1
use fixtures over inputs for zkaf - remove dormant/unused files. upda…
rsoury Nov 28, 2024
2464621
Update test job to run plugin tests instead of helper tests
xlassix Nov 27, 2024
054e0b2
Add new Cargo.toml paths to linkedProjects in settings
xlassix Nov 28, 2024
20e6bf4
corrected git_actions
xlassix Nov 28, 2024
2b04f11
Update Dockerfile names for bitte_plugin and near_indexer
xlassix Nov 28, 2024
82f2b94
Refactor cargo test command in rust.yml workflow
xlassix Nov 28, 2024
615f4ba
Update open_api_handler.rs description for reward transaction
xlassix Nov 28, 2024
9b142f3
Update project setup and configuration steps
xlassix Nov 28, 2024
2b80fd1
Add environment variables to README files
xlassix Nov 28, 2024
dee23a9
Add function to add prefix if needed in tweet notifications
xlassix Nov 28, 2024
c303c18
Add rustup to install rust toolchain components
xlassix Nov 28, 2024
1cf60dc
Update rust components in GitHub Actions workflow
xlassix Nov 28, 2024
2f99079
Update rustup command in workflow file
xlassix Nov 28, 2024
f06e1ab
Update cargo-near version to 0.10.2 in rust workflow
xlassix Nov 28, 2024
7980406
Update cargo-make version to 0.35.1 in rust workflow
xlassix Nov 28, 2024
20aa301
Update cargo-near version to 0.9.0 in Rust workflow
xlassix Nov 29, 2024
4c0a523
Update Cargo dependencies for Rust workflow
xlassix Nov 29, 2024
f28de85
Add PublicMetric and MintRequestStatus enums. Set cost_per_metric. <5…
xlassix Dec 4, 2024
20a03fa
Refactor minting logic for mint_tweet_request
xlassix Dec 4, 2024
5bab0af
Update cost_per_metric comment in set_cost_per_metric function
xlassix Dec 4, 2024
3ad037a
Add price_per_point field and update min_deposit logic
xlassix Dec 4, 2024
5f4e175
Add functionality to preserve mint request data
xlassix Dec 4, 2024
e48a1a6
Update MintRequestStatus and handling of claimable funds
xlassix Dec 5, 2024
45c6772
Refactor claim_funds method parameters and logic
xlassix Dec 5, 2024
39ec97e
Update README with Bitte Plugin setup instructions
xlassix Dec 5, 2024
672ab2a
Update README.md with new section title and content
xlassix Dec 5, 2024
a2916b4
complete
xlassix Dec 10, 2024
1b0fae0
Add script to set NFT account in verifier contract
xlassix Dec 10, 2024
b258699
Update cargo dependencies and remove commented out sections
xlassix Dec 10, 2024
bd3258b
Add User struct to metadata extraction function
xlassix Dec 10, 2024
c76b1b5
Update withdrawal calculation in CancelMintRequest event
xlassix Dec 10, 2024
dd62d1b
Add Unsuccessful status handling in is_tweet_available() method
xlassix Dec 10, 2024
5541234
Update dependencies and add cancel contract call endpoint
xlassix Dec 10, 2024
1900abb
Update verity-client URL and add anyhow dependency
xlassix Dec 10, 2024
bd28e55
Update Verity client and verifier versions
xlassix Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**/target/
.git/
.gitignore
.vscode/
*.rs.bk
.idea/
docs/
src/zkaf/
src/contracts
18 changes: 9 additions & 9 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ jobs:
packages: libudev-dev # dependency for cargo-near
version: 1.0

- name: run near_nft test
run: |
ls
cd ./src/contracts/nft/
cargo install cargo-make cargo-near
cargo make test

- name: run helper test
- name: run plugin test
run: |
ls
cd ./src/helper/
cargo test --lib
cd ./src/bitte_plugin/
cargo test


- name: run near_nft test
run: |
rustup update
cd ./src/contracts/nft/
cargo install cargo-make@0.35.1
cargo make test

6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
[submodule "src/verity"]
path = src/verity
url = git@github.com:usherlabs/verity.git
[submodule "src/zkaf/methods/verity"]
path = src/zkaf/methods/verity
url = https://github.com/usherlabs/verity.git
20 changes: 12 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
{
"rust-analyzer.linkedProjects": [
"./src/near_nft/Cargo.toml",
"./src/near_verifier/contract/Cargo.toml",
"./src/near_verifier/integration-tests/Cargo.toml",
"./src/notary/Cargo.toml",
"./src/twitter/Cargo.toml",
"./src/verifier/Cargo.toml",
"./src/contract/nft/Cargo.toml",
"./src/contract/verifier/contract/Cargo.toml",
"./src/contract/nft/nft/Cargo.toml",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No such folder as src/contract/
It's src/contracts/
Please get better at picking up minor matters like this.

"./src/contract/verifier/integration-tests/Cargo.toml",
"./src/zkaf/Cargo.toml",
"./src/bitte_plugin/Cargo.toml",
"./src/helper/Cargo.toml",
"./src/near_indexer/Cargo.toml",
],
"rust-analyzer.check.extraEnv": {
"RISC0_SKIP_BUILD": "1",
}
},
"rust-analyzer.procMacro.enable": true,
"rust-analyzer.server.path": null,
"rust-analyzer.cargo.unsetTest": [
"clap",
"clap_derive",
"clap-derive"
]
}
94 changes: 45 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,48 @@
# X (Twitter) NFTs

1. Configure X (Twitter) API v2 Keys and Conversation/Tweet ID in `./src/twitter/.env`
2. Start the Notary Server - *This server runs locally for testing purposes, but will be offered by Usher Labs' decentralised data security network for production environments.*
```shell
./start_notary_server.sh
```
3. Generate Twitter TLS Proof
```shell
./generate_twitter_proof.sh
```

## ZKAF Near/Aurora Testing Guide
1. clone [verity]() and run notary and prover. see [more](https://github.com/usherlabs/verity)
2. configure and run [Bitte Plugin](./src/bitte_plugin/README.md)
3. configure and run [orchestrator](./src/near_indexer/README.md)

## Full Guide

**TL;DR**
**TL;DR**

To run the repo:
1. Install dependencies
1. First, [install Rust](https://www.rust-lang.org/tools/install) and [Foundry](https://book.getfoundry.sh/getting-started/installation), and then restart your terminal.

```sh
# Install Rust
curl https://sh.rustup.rs -sSf | sh
# Install Foundry
curl -L https://foundry.paradigm.xyz | bash
```
2. Install the [necessary tool-chain to build the program](https://dev.risczero.com/api/zkvm/install)
3. Install Docker

2. Navigate to the `zkaf` directory
Moved into X (Twitter) NFTs — https://github.com/usherlabs/x-twitter-nfts/blob/f6c7fb0448408eda30ba0c0402014e94a5c0b868/src/zkaf

1. Install dependencies

1. First, [install Rust](https://www.rust-lang.org/tools/install) and [Foundry](https://book.getfoundry.sh/getting-started/installation), and then restart your terminal.

```sh
# Install Rust
curl https://sh.rustup.rs -sSf | sh
# Install Foundry
curl -L https://foundry.paradigm.xyz | bash
```

2. Install the [necessary tool-chain to build the program](https://dev.risczero.com/api/zkvm/install)
3. Install Docker

2. Navigate to the `bitte_plugin` directory
3. Create environment variables
See all requires env variables: [.env.sample](https://github.com/usherlabs/x-twitter-nfts/blob/f6c7fb0448408eda30ba0c0402014e94a5c0b868/src/zkaf/.env.sample)

4. To deterministically build the ZK Circuit / Guest, Docker must be running — [Learn more](https://dev.risczero.com/terminology#deterministic-builds)
See all requires env variables: [.env.sample](./src/bitte_plugin/.env.sample)

4. Run the `bitte_plugin` [see](./src/bitte_plugin/README.md)

6. Navigate to the `near_indexer` directory

5. Run the publisher to generate and verify the proof.
7. Create environment variables
See all requires env variables: [.env.sample](./src/near_indexer/.env.sample)

```shell
cargo run --bin publisher
```
8. To set up Near indexer [see](./src/near_indexer/README.md)

## ZKAF Near/Aurora Testing Guide

### Important Note

Building the guest code generates a unique identifier called the `image_id` , Which is used as a unique identifier for the program. In order to ensure your build is determinisitic i.e to ensure that you build the same guest code as initially intended, make sure the `RISC0_USE_DOCKER` flag is set to true. This would ensure the proofs generated are compatible with the verifiers deployed.


```jsx
# RISC0 Parameters
export RISC0_USE_DOCKER=true
Expand All @@ -62,7 +58,7 @@ These contracts, along with the ZK circuit can be found in the `zkaf` folder. an

### Aurora

The Aurora contract which handles the proof verification on-chain would be deployed first, then the contract address obtained upon deployment will be used as a parameter to deploy the near contract. Then all the variables used would be filled in here: https://github.com/usherlabs/twitter_notary/blob/f6c7fb0448408eda30ba0c0402014e94a5c0b868/src/zkaf/.env.sh.sample in order to generate and verify the proof on-chain.
The Aurora contract which handles the proof verification on-chain would be deployed first, then the contract address obtained upon deployment will be used as a parameter to deploy the near contract. Then all the variables used would be filled in here: https://github.com/usherlabs/twitter_notary/blob/f6c7fb0448408eda30ba0c0402014e94a5c0b868/src/zkaf/.env.sh.sample in order to generate and verify the proof on-chain.

### Testing the Aurora Contract

Expand All @@ -75,7 +71,7 @@ forge test
#### Deploying the contract

```jsx
export ETH_WALLET_PRIVATE_KEY="0x7a9dbc66cd59075f19a3d8d72e2bc04acceb7be9411c469e44dd310342a70eab"
export ETH_WALLET_PRIVATE_KEY="0x7a9dbc66cd59075f19a3d8d72e2bc04acceb7be9411c469e44dd310342a70eab"

forge script script/Deploy.s.sol --rpc-url https://aurora-testnet.drpc.org --broadcast --legacy
```
Expand All @@ -88,17 +84,17 @@ The near contract is responsible for checking if a proof has been verified on th

#### Prerequisites:

- [ ] A near testnet account (https://testnet.mynearwallet.com/)
- [ ] Install system dependency for rust-cli package
- [ ] A near testnet account (https://testnet.mynearwallet.com/)
- [ ] Install system dependency for rust-cli package

```bash
sudo apt install -y pkg-config libusb-1.0-0-dev libftdi1-dev
sudo apt-get install libudev-dev
```

- [ ] Near Rust CLI (https://docs.near.org/tools/near-cli-rs)
- [ ] Login to near on the CLI by running `sh login.sh`
- [ ] Get some near testnet tokens at https://near-faucet.io/
- [ ] Near Rust CLI (https://docs.near.org/tools/near-cli-rs)
- [ ] Login to near on the CLI by running `sh login.sh`
- [ ] Get some near testnet tokens at https://near-faucet.io/

#### Deployment

Expand Down Expand Up @@ -150,10 +146,10 @@ export NEAR_CONTRACT_ACCOUNT_ID="usherzkaf.testnet" //replace with near account

# BONSAI parameters
export BONSAI_API_KEY="" # provided with your api key
export BONSAI_API_URL="https://api.bonsai.xyz/"
export BONSAI_API_URL="https://api.bonsai.xyz/"

# FORGE parameters
export ETH_WALLET_PRIVATE_KEY= //EVM PK aith some aurora eth
export ETH_WALLET_PRIVATE_KEY= //EVM PK aith some aurora eth
```

#### `env.sample`
Expand Down Expand Up @@ -230,16 +226,16 @@ In this case, we attach the callback we had previously implemented and have it h

```rust
pub struct TokenMetadata {
pub title: Option<String>,
pub title: Option<String>,
pub description: Option<String>,
pub media: Option<String>,
pub media: Option<String>,
pub media_hash: Option<Base64VecU8>,
pub copies: Option<u64>,
pub issued_at: Option<String>,
pub expires_at: Option<String>,
pub starts_at: Option<String>,
pub updated_at: Option<String>,
pub extra: Option<String>,
pub extra: Option<String>,
pub reference: Option<String>,
pub reference_hash: Option<Base64VecU8>,
}
Expand All @@ -258,4 +254,4 @@ TokenMetadata.extra = tweet.public_metrics // {"retweet_count": 2, "reply_count"
- The output of the Zero-Knowledge (ZK) proof generation is a hash, specifically a SHA-256 hash of the serialized Token Metadata representation.
- Subsequently, a verification step is executed on the NEAR blockchain to ensure the equality between `sha256(token_metadata)` and `zk_journal_output`. This validation process confirms the authenticity of the payload by matching it against the immutable output of the ZK process, which inherently carries a singular, unchangeable identity.
- To ensure token uniqueness, the `token_id` of the Non-Fungible Token (NFT) is determined by the `TokenMetadata.title`, which corresponds to the tweet's identifier. This approach guarantees that each NFT is exclusively linked to a single tweet, thus eliminating duplication.
- The `TokenMetadata.extra` field encompasses tweet-specific metrics, which can be utilised in the derivation of pricing algorithms for the NFT.
- The `TokenMetadata.extra` field encompasses tweet-specific metrics, which can be utilised in the derivation of pricing algorithms for the NFT.
4 changes: 0 additions & 4 deletions disabled.Cargo.toml

This file was deleted.

66 changes: 66 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: '3.8'

services:
postgres_db:
image: postgres:16
hostname: postgres
restart: always
container_name: verity-near-indexer-pg
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
PGDATA: /var/lib/postgresql/data/pgdata
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 15s
timeout: 10s
retries: 5
ports:
- "5432:5432"
networks:
- xnfts-network
volumes:
- postgres-near-indexer:/var/lib/postgresql/data

app:
build:
dockerfile: ./src/near_indexer/.indexer.dockerfile
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency between this Dockerfile and the Dockerfile elsewhere.

Consistency keeps maintainability.

context: .
container_name: verity-near-indexer-app
environment:
DATABASE_URL: ${DATABASE_URL}
RUST_LOG: debug
RUST_BACKTRACE: 1
networks:
- xnfts-network
depends_on:
postgres_db:
condition: service_healthy
volumes:
- .:/app
command: >
sh -c "
sea-orm-cli migrate up --migration-dir ./src/near_indexer/migration &&
indexer
"

bitte_plugin:
build:
dockerfile: ./src/bitte_plugin/Dockerfile
context: .
container_name: verity-near-bitte-app
env_file:
- ./src/bitte_plugin/.env
ports:
- "8007:8007"
volumes:
- .:/bitte_plugin
command: >
sh -c "bitte_plugin"
volumes:
postgres-near-indexer:

networks:
xnfts-network:
driver: bridge
6 changes: 0 additions & 6 deletions generate_twitter_proof.sh

This file was deleted.

3 changes: 0 additions & 3 deletions src/bitte_plugin/.env.example

This file was deleted.

5 changes: 5 additions & 0 deletions src/bitte_plugin/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
THIRDWEB_CLIENT_ID=xxxxxxxxxxx
TWEET_BEARER=XXXXXXXXXXXXXXXXXX
ACCOUNT_ID=hello_world.near
NEAR_CONTRACT_ADDRESS="xxxxxxxxxxxxxxx.testnet"
HOST_URL=""
1 change: 1 addition & 0 deletions src/bitte_plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env.local
.env
/*.json
!/package.json
Loading
Loading