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(operator): Update SP1 and Risc0 Versions #1319

Closed
wants to merge 58 commits into from

Conversation

PatStiles
Copy link
Contributor

@PatStiles PatStiles commented Oct 24, 2024

Update SP1 and Risc0 verifier versions

closes #1205

This PR:

  • Bumps the risc0 and sp1 verifier versions of operators.
  • Provides retro-compatibility for each version. If proof verification for SP1 and Risc0 between the current and old ('_old') verifier versions fails within the operator it will try verifying using the older version of SP1/Risc0 before returning false.
  • Changes the prompt library in the quiz example from dialoguer -> inquire to accomadate a dependency conflict.

To Test:

Verify network bindings works on a local network:

  • make test_risc_zero_go_bindings_macos
  • make test_sp1_go_bindings_macos
  • run local testnet and confirm you can submit sp1 and risc0 proofs. via
    make batcher_send_risc0_task
    make batcher_send_sp1_task
  • confirm examples work:
    cd examples/zkquiz && make answer_quix
    cd examples/validating-public-input && make generate_risc_zero_fibonacci_proof

Verify Retro Compatiblility of Operator Verifiers:

To verify operator retro-compatibility we deploy the rest of infrastructure of Aligned and boot the retro-compatible operator. This tests that network retro-compatible operator can verify SP1/Risc0 proofs from both verifier versions.

Note:
Commands suffixed with _old indicate the deprecated version of the SP1/Risc0 verifier that is currently running on testnet

To test this have two repos of aligned_layer one set to testnet and one to 1205-bump-sp1-and-risc0-version.

In testnet repo:

go clean
go mod tidy
make go_deps
make deps
  • Then you must run anvil, aggregator and batcher:
make anvil_start_with_block_time
make aggregator_start
make batcher_start_local

In 1205-operator-sp1-risc0-update repo:

make deps
  • Then you can run operator
make operator_register_and_start
  • Send proof from the older SP1 and Risc0 versions from the testnet repo.
make batcher_send_burst_groth16
make batcher_send_sp1_burst
make batcher_send_risc0_burst

Observe the Risc0 proof verification failed. and SP1 proof verification failed. logs are emitted and the operator successfully verifying the proofs from the old SP1/Risc0 verifiers. If you send a proof from the latest version of SP1/Risc0 you should notice its verification fails in the batcher.

  • Keep the operator running on the 1205-operator-sp1-risc0-update repo.
  • In the testnet repo, kill the batcher.
  • Navigate to the 1205-bump-sp1-and-risc0-version and start the batcher within the repo.
  • Send proof from both the SP1 and Risc0 versions from the 1205-operator-sp1-risc0-update repo.
make batcher_send_sp1_burst
make batcher_send_risc0_burst

Observe the operator successfully verifying the proofs from the new SP1/Risc0 verifiers. If you send a proof from the older version of SP1/Risc0 you should notice its verification fails in the batcher.

Type of change

Please delete options that are not relevant.

  • New feature

Checklist

  • Linked to Github Issue
  • This change depends on code or research by an external entity
    • Acknowledgements were updated to give credit
  • Unit tests added
  • This change requires new documentation.
    • Documentation has been added/updated.
  • This change is an Optimization
    • Benchmarks added/run
  • Has a known issue

@@ -17,7 +17,7 @@ ifeq ($(OS),Darwin)
endif

ifeq ($(OS),Linux)
LD_LIBRARY_PATH += $(CURDIR)/operator/risc_zero/lib
LD_LIBRARY_PATH+=$(CURDIR)/operator/risc_zero_old/lib:$(CURDIR)/operator/risc_zero/lib
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that I pay more attention to this, the correct pattern isn't this here, it's:

Suggested change
LD_LIBRARY_PATH+=$(CURDIR)/operator/risc_zero_old/lib:$(CURDIR)/operator/risc_zero/lib
LD_LIBRARY_PATH=$(CURDIR)/operator/risc_zero_old/lib:$(CURDIR)/operator/risc_zero/lib:$(LD_LIBRARY_PATH)

Copy link
Collaborator

Choose a reason for hiding this comment

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

That is, you do not append a string (it will be separated by a space, while lookup paths are separated by colon), but instead prepend and separate with : from the originals.

Comment on lines +4 to +44
#[no_mangle]
pub extern "C" fn verify_risc_zero_receipt_old_ffi(
inner_receipt_bytes: *const u8,
inner_receipt_len: u32,
image_id: *const u8,
image_id_len: u32,
public_input: *const u8,
public_input_len: u32,
) -> bool {
if inner_receipt_bytes.is_null() || image_id.is_null() {
error!("Input buffer null");
return false;
}

if inner_receipt_len == 0 || image_id_len == 0 {
error!("Input buffer length zero size");
return false;
}

//NOTE: We allow the public input for risc0 to be empty.
let mut public_input_slice: &[u8] = &[];
if !public_input.is_null() && public_input_len > 0 {
public_input_slice =
unsafe { std::slice::from_raw_parts(public_input, public_input_len as usize) };
}

let inner_receipt_bytes =
unsafe { std::slice::from_raw_parts(inner_receipt_bytes, inner_receipt_len as usize) };

let image_id = unsafe { std::slice::from_raw_parts(image_id, image_id_len as usize) };

let mut image_id_array = [0u8; 32];
image_id_array.copy_from_slice(image_id);

if let Ok(inner_receipt) = bincode::deserialize::<InnerReceipt>(inner_receipt_bytes) {
let receipt = Receipt::new(inner_receipt, public_input_slice.to_vec());

return receipt.verify(image_id_array).is_ok();
}
false
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We would need to follow the try_catch behavior of the other lib.

Copy link
Collaborator

@MarcosNicolau MarcosNicolau left a comment

Choose a reason for hiding this comment

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

Risc0 and SP1 are being rejected by the batcher when doing batcher_send_risc0, this is because the test files have been updated to the newer versions and the batcher only accepts old versions of the proofs. Anyway, I modified it so that they point to the old files and both sp1 and risc0 are working well on the operator.

@PatStiles PatStiles closed this Oct 25, 2024
@JuArce JuArce deleted the 1205-operator-sp1-risc0-update branch January 2, 2025 15:15
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.

3 participants