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

feat(sdk): add support program registration #1842

Merged
merged 9 commits into from
Dec 5, 2024

Conversation

mattstam
Copy link
Contributor

@mattstam mattstam commented Dec 5, 2024

Problem: uploading the elf and doing prover.setup(elf) to get the vk on every request is unnecessary.

Solution: the elf and vk are no longer sent every request, instead they are only sent if the program hasn't been registered in the network yet.

Previous SDK prove:

  1. upload the elf
  2. call RequestProof(program_uri, vk ...) , which returns request_id
  3. poll GetProofRequestStatus(request_id)

New SDK prove:

  1. call GetProgram(vk_hash) , which returns some metadata about an existing program (e.g. program_uri, name) or error if doesn't exist
    a. if error:
    i. upload the elf
    ii. call CreateProgram(vk_hash, vk, program_uri)
  2. call RequestProof(vk_hash, ...), which returns request_id (fails if vk_hash doesn't exist)
  3. poll GetProofRequestStatus(request_id)

Example output with registration, since the program doesn't exist yet:

2024-12-05T01:45:09.676237Z  INFO Client circuit version: v3.0.0    
vk: "0x00aa4ee3c793869d5023ae21800c827d39a23a8c594f07729dd6391b7091a89d"
2024-12-05T01:45:11.107286Z  WARN network_prover: close time.busy=8.44ms time.idle=2.58µs  
2024-12-05T01:45:11.407481Z  INFO Registered program 0x00aa4ee3c793869d5023ae21800c827d39a23a8c594f07729dd6391b7091a89d    
2024-12-05T01:45:11.407494Z  INFO Requesting proof with cycle limit: 100000000    
2024-12-05T01:45:11.556967Z  INFO Created request 0x1c1dafab91a6a7a829ab3d0faea0733b8136e2a6037e91024a526833ab7a023a in transaction 0xd0d15547d3c047ea8c62cdadd229ceb1329c6fa8f5c728decbaaa0581a3a123e    
2024-12-05T01:45:11.561052Z  INFO Proof request assigned, proving... 
generated proof
public values: 0xf4010000f404000086070000
proof: 0x090...

and then re-running it, it skips the registration:

2024-12-05T02:12:12.128586Z  INFO Client circuit version: v3.0.0    
vk: "0x00aa4ee3c793869d5023ae21800c827d39a23a8c594f07729dd6391b7091a89d"
2024-12-05T02:12:13.556157Z  WARN network_prover: close time.busy=10.9ms time.idle=2.92µs
2024-12-05T02:12:13.566362Z  INFO Requesting proof with cycle limit: 100000000    
2024-12-05T02:12:13.760741Z  INFO Created request 0x83d062654a3ef75c34b2338e32fb51e39586f6f498f29b6381f8c773725f3e30 in transaction 0x99c6b3bd36124c8289e95c36df0522d94f4623c995aebf9b6b99a6049bd07064    
2024-12-05T02:12:13.764281Z  INFO Proof request assigned, proving... 
generated proof
public values: 0xf4010000f404000086070000
proof: 0x090...

updated

prep test

proto

retry both

better msg

no-op

concurrent

more

better retries

proto

Added  method to the NetworkProver

workflow

update proto

compile

latest
Copy link

github-actions bot commented Dec 5, 2024

SP1 Performance Test Results

Branch: mattstam/sdk-network-v2-mergable
Commit: d365669
Author: mattstam

program cycles execute (mHz) core (kHZ) compress (KHz) time success
fibonacci 11291 0.16 2.66 0.45 25s
ssz-withdrawals 2757356 17.52 124.32 34.48 1m20s
tendermint 12593597 6.65 270.09 99.96 2m8s

@mattstam mattstam changed the title feat(sdk): support program registration in SDK feat(sdk): add support program registration Dec 5, 2024
@mattstam
Copy link
Contributor Author

mattstam commented Dec 5, 2024

error: rustc 1.79.0 is not supported by the following packages:
[email protected] requires rustc 1.81
[email protected] requires rustc 1.81
[email protected] requires rustc 1.81
[email protected] requires rustc 1.81
[email protected] requires rustc 1.81
[email protected] requires rustc 1.81
Either upgrade rustc or select compatible dependency versions with
cargo update <name>@<current-ver> --precise <compatible-ver>
where <compatible-ver> is the latest version supporting rustc 1.79.0

unrelated CI failing


/// Sets the fulfillment strategy for the client. By default, the strategy is set to `Hosted`.
pub fn with_strategy(&mut self, strategy: FulfillmentStrategy) {
self.strategy = strategy;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note: I will do other SDK improvements in a subsequent PR

@@ -95,6 +97,76 @@ impl NetworkClient {
Ok(res.into_inner().nonce)
}

/// Get the verifying key hash from a verifying key. The verifying key hash is used to identify
/// a program.
pub fn get_vk_hash(vk: &SP1VerifyingKey) -> Result<Vec<u8>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if we should use SP1VerifyingKeyHash([u32; 8]) or something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will keep this in mind

@mattstam mattstam merged commit 6c09a31 into dev Dec 5, 2024
12 of 13 checks passed
@mattstam mattstam deleted the mattstam/sdk-network-v2-mergable branch December 5, 2024 22:51
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.

2 participants