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

Integrate Scroll prover with Snarkify SDK #4

Merged
merged 27 commits into from
Aug 14, 2024
Merged

Conversation

Gigatron
Copy link

No description provided.

Comment on lines 24 to 39
let config: Config = Config::from_file("config.json".to_string()).map_err(|e| e.to_string())?;

if let Err(e) = AssetsDirEnvConfig::init() {
log::error!("AssetsDirEnvConfig init failed: {:#}", e);
std::process::exit(-2);
}

let prover = Prover::new(&config).map_err(|e| e.to_string())?;

log::info!(
"prover start successfully. name: {}, type: {:?}, publickey: {}, version: {}",
config.prover_name,
config.proof_type,
prover.get_public_key(),
version::get_version(),
);
Copy link
Author

Choose a reason for hiding this comment

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

@cyphersnake, Need some advice here. We want the prover to be reused across different reqeusts, so we woud like it to be stored as a static variable and lazily initialized. Chatgpt recommended to use

static PROVER: OnceCell<Prover> = OnceCell::new();

let prover = PROVER.get_or_init(|| {
  ...
})

but the compiler is giving many errors about thread-safty. In our use case we know that it is a single-threaded model, how should I rewrite the code to achieve my goal. Can you help take a look?

Choose a reason for hiding this comment

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

https://doc.rust-lang.org/std/macro.thread_local.html

use std::cell::RefCell;

struct Prover;

impl Prover {
    fn new() -> Self {
        Self
    }

    fn ping(&self) -> u8 {
        42
    }

    fn pong(&mut self) -> u8 {
        42
    }
}

thread_local! {
    static GLOBAL: RefCell<Prover> = RefCell::new(Prover::new());
}

fn main() {
    GLOBAL.with_borrow(|v| {
        v.ping();
    });

    GLOBAL.with_borrow_mut(|v| {
        v.pong();
    });
}

Let me know if that's not enough

Copy link
Author

Choose a reason for hiding this comment

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

Made the change as you suggested, and I think it works! Thanks!

@Gigatron Gigatron force-pushed the snarkify-gpu-deploy branch from 5b1430b to 9999b1e Compare July 30, 2024 01:21
@Gigatron Gigatron marked this pull request as ready for review July 30, 2024 03:27
@Gigatron Gigatron requested a review from ErdongChen61 July 30, 2024 03:28
prover/Dockerfile Outdated Show resolved Hide resolved
prover/README.md Outdated
@@ -0,0 +1,30 @@
## How-to run Snarkify prover locally
1. `make snarkify`
2. update `config.json` with right coordinator and l2geth endpoints

Choose a reason for hiding this comment

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

nit: better to list what are the endpoints for testnet and mainnet.

Choose a reason for hiding this comment

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

and why prover needs coordinator endpoint? My gut is that only relayer needs it.

Copy link
Author

Choose a reason for hiding this comment

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

It doesn't use coordinator endpoint, I'll remove this requirement for now.

@Gigatron Gigatron force-pushed the snarkify-gpu-deploy branch from b942567 to 42121d6 Compare August 14, 2024 13:42
@Gigatron Gigatron merged commit 030b5c2 into develop Aug 14, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants