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

Updated Verifiable Randomness Functions #481

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nandanpathakk
Copy link

Summary of Changes

  • Updated content to align with the guide.
  • Improved clarity in instructions and code examples.
  • Fixed grammatical errors.
  • Updated and corrected broken or outdated links.

Copy link
Collaborator

@mikemaccana mikemaccana left a comment

Choose a reason for hiding this comment

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

This has some good changes but what's bs-switchboard-solana?

@@ -301,35 +306,35 @@ context.

- `authority` - PDA derived from our program
- `vrf` -
[Account owned by the Switchboard program](https://docs.rs/switchboard-solana/latest/switchboard_solana/oracle_program/accounts/vrf/struct.VrfAccountData.html)
[Account owned by the Switchboard program](https://docs.rs/bs-switchboard-solana/latest/switchboard_solana/oracle_program/accounts/vrf/struct.VrfAccountData.html)
Copy link
Collaborator

@mikemaccana mikemaccana Oct 13, 2024

Choose a reason for hiding this comment

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

What is bs-switchboard-solana? It looks like an odd fork and its version is 0.0.0

Copy link
Collaborator

@mikemaccana mikemaccana left a comment

Choose a reason for hiding this comment

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

This is an excellent contribution, thanks @nandanpathakk ! You have an excellent eye for detail. While you didn't win this lesson, we'd love to get this in - there's a few small changes required but you're 95% of the way there. Please see the comments below and I'll get this in once they're done!

external data and service requests onchain. To learn more about Switchboard’s
Oracle network, please refer to our
composed of many individual oracles run by third parties, which provide external
data and service requests onchain. To learn more about Switchboard’s Oracle
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is an error in the old material, but 'oracle' is a concept and should be lowercase (I think people may be confused with the database company). Fix this everywhere please!


The `callback` field is of type
`[CallbackZC](https://github.com/switchboard-xyz/solana-sdk/blob/9dc3df8a5abe261e23d46d14f9e80a7032bb346c/rust/switchboard-solana/src/oracle_program/accounts/ecvrf.rs#L25)`.
[CallbackZC](https://github.com/switchboard-xyz/solana-sdk/blob/9dc3df8a5abe261e23d46d14f9e80a7032bb346c/rust/switchboard-solana/src/oracle_program/accounts/ecvrf.rs#L25).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Technically CallbackZC is code so you can use backticks.

@@ -218,24 +224,24 @@ pub struct CallbackZC {
}
```

This is how you define the Callback struct client side.
This is how you define the Callback structure on the client side.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Likewise Callback is code.

{ pubkey: clientState, isSigner: false, isWritable: true },
{ pubkey: vrfClientKey, isSigner: false, isWritable: true },
{ pubkey: vrfSecret.publicKey, isSigner: false, isWritable: true },
],
// use name of instruction
ixData: vrfIxCoder.encode("consumeRandomness", ""), // pass any params for instruction here
// Use name of instruction
Copy link
Collaborator

Choose a reason for hiding this comment

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

Indents are odd here (they were in the old lesson too)

@@ -401,9 +405,9 @@ pub fn handler(ctx: Context<ConsumeRandomness>) -> Result <()> {
// use the get_result method to fetch the randomness results
let result_buffer = vrf.get_result()?;

// check if result buff is all 0's
// check if result buff is all zeros
Copy link
Collaborator

Choose a reason for hiding this comment

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

indent needs fixing

method. This method returns the `current_round.result` field of the `vrf`
account SwitchboardDecimal format, which is essentially just a buffer of 32
random
[u8](https://github.com/switchboard-xyz/solana-sdk/blob/9dc3df8a5abe261e23d46d14f9e80a7032bb346c/rust/switchboard-solana/src/oracle_program/accounts/ecvrf.rs#L65C26-L65C26)
Copy link
Collaborator

Choose a reason for hiding this comment

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

See comments re backticks. Fix SwitchboardDecimal too.

@@ -451,7 +456,7 @@ is provided for you in
[the main branch of the lab Github repository](https://github.com/Unboxed-Software/michael-burry-escrow).

The repo contains a "Michael Burry" escrow program. This is a program that
allows a user to lock up some solana funds in escrow that cannot be withdrawn
Copy link
Collaborator

Choose a reason for hiding this comment

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

Euw gross. Glad you fixed this!

@@ -514,7 +519,7 @@ pub mod instructions;
pub mod state;
pub mod errors;

declare_id!("YOUR_KEY_HERE");
declare_id!("YOUR_KEY_HERE"); // Replace with your program key
Copy link
Collaborator

Choose a reason for hiding this comment

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

Honestly people can read code, they don't need the comment, maybe just:

Suggested change
declare_id!("YOUR_KEY_HERE"); // Replace with your program key
declare_id!("YOUR_PROGRAM_PUBLIC_KEY_HERE");

To make sure people know it's the public key (which should be obvious but this is training content and we should be explicit).

You could also tell people to run anchor keys sync if necessary.

with `AccountLoader`. We use this technique because VRF functions are very
account intensive, and we need to be mindful of the stack. If you'd like to
learn more about `zero_copy`, take a look at our
[Program Architecture lesson](/content/courses/program-optimization/program-architecture).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use .md. I know it's weird but see CONTRIBUTING.md

send it on it's way.
Now, we can work on the logic of this instruction. The goal is to gather all of
the required accounts and pass them to
[VrfRequestRandomness](https://github.com/switchboard-xyz/solana-sdk/blob/fbef37e4a78cbd8b8b6346fcb96af1e20204b861/rust/switchboard-solana/src/oracle_program/instructions/vrf_request_randomness.rs#L8)
Copy link
Collaborator

Choose a reason for hiding this comment

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

reminder to use backticks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants