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

refactor: add validator witness + use reqwest blocking #180

Merged
merged 5 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion plonky2x/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ serde = { version = "1.0.187", features = ["derive"] }
serde_json = "1.0.103"
tokio = { version = "1", features = ["full"] }
anyhow = "1.0.75"
reqwest = { version = "0.11.4", features = ["json"] }
reqwest = { version = "0.11.4", features = ["blocking", "json"] }
array-macro = "2.1.5"
tracing = "0.1.37"
num-bigint = { version = "0.4", features = ["rand"] }
Expand Down
7 changes: 1 addition & 6 deletions plonky2x/src/frontend/eth/beacon/generators/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,27 +149,22 @@ impl<L: PlonkParameters<D>, const D: usize> SimpleGenerator<L::Field, D>
.block_on(async {
match &self.input {
BeaconBalanceInput::IndexConst(idx) => {
self.client
.get_validator_balance_v2(hex!(block_root), *idx)
.await
self.client.get_validator_balance_v2(hex!(block_root), *idx)
}
BeaconBalanceInput::IndexVariable(idx) => {
let idx = idx.get(witness);
self.client
.get_validator_balance_v2(hex!(block_root), idx.as_u64())
.await
}
BeaconBalanceInput::PubkeyConst(pubkey) => {
let pubkey = hex!(pubkey.0);
self.client
.get_validator_balance_by_pubkey_v2(hex!(block_root), pubkey)
.await
}
BeaconBalanceInput::PubkeyVariable(pubkey) => {
let pubkey = hex!(pubkey.get(witness));
self.client
.get_validator_balance_by_pubkey_v2(hex!(block_root), pubkey)
.await
}
}
})
Expand Down
1 change: 0 additions & 1 deletion plonky2x/src/frontend/eth/beacon/generators/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ impl<L: PlonkParameters<D>, const D: usize> SimpleGenerator<L::Field, D>
let result = rt.block_on(async {
self.client
.get_balances_root(hex!(block_root.as_bytes()).to_string())
.await
.expect("failed to get validators root")
});

Expand Down
1 change: 0 additions & 1 deletion plonky2x/src/frontend/eth/beacon/generators/historical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F, D>
let result = rt.block_on(async {
self.client
.get_historical_block(hex!(block_root.as_bytes()).to_string(), offset.as_u64())
.await
.expect("failed to get validators root")
});

Expand Down
1 change: 1 addition & 0 deletions plonky2x/src/frontend/eth/beacon/generators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod balance;
mod balances;
mod historical;
mod validator;
mod validator_witness;
mod validators;
mod withdrawal;
mod withdrawals;
Expand Down
3 changes: 0 additions & 3 deletions plonky2x/src/frontend/eth/beacon/generators/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,17 @@ impl<L: PlonkParameters<D>, const D: usize> SimpleGenerator<L::Field, D>
BeaconValidatorGeneratorInput::IndexConst(idx) => self
.client
.get_validator(hex!(block_root), *idx)
.await
.expect("failed to get validator"),
BeaconValidatorGeneratorInput::IndexVariable(idx) => {
let idx = idx.get(witness).as_u64();
self.client
.get_validator(hex!(block_root), idx)
.await
.expect("failed to get validator")
}
BeaconValidatorGeneratorInput::PubkeyVariable(pubkey) => {
let pubkey = hex!(pubkey.get(witness));
self.client
.get_validator_by_pubkey(hex!(block_root), pubkey)
.await
.expect("failed to get validator")
}
}
Expand Down
28 changes: 28 additions & 0 deletions plonky2x/src/frontend/eth/beacon/generators/validator_witness.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::env;

use serde::{Deserialize, Serialize};

use crate::frontend::eth::beacon::vars::BeaconValidatorVariable;
use crate::frontend::generator::simple::hint::Hint;
use crate::frontend::uint::uint64::U64Variable;
use crate::frontend::vars::ValueStream;
use crate::prelude::{Bytes32Variable, PlonkParameters};
use crate::utils::eth::beacon::BeaconClient;
use crate::utils::hex;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BeaconValidatorWitnessGenerator {}

impl<L: PlonkParameters<D>, const D: usize> Hint<L, D> for BeaconValidatorWitnessGenerator {
fn hint(&self, input_stream: &mut ValueStream<L, D>, output_stream: &mut ValueStream<L, D>) {
let client = BeaconClient::new(env::var("CONSENSUS_RPC_1").unwrap());
let header_root = input_stream.read_value::<Bytes32Variable>();
let validator_index = input_stream.read_value::<U64Variable>();

let response = client
.get_validator_witness(hex!(header_root), validator_index.as_u64())
.unwrap();

output_stream.write_value::<BeaconValidatorVariable>(response.validator);
}
}
1 change: 0 additions & 1 deletion plonky2x/src/frontend/eth/beacon/generators/validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ impl<L: PlonkParameters<D>, const D: usize> SimpleGenerator<L::Field, D>
let result = rt.block_on(async {
self.client
.get_validators_root(hex!(block_root.as_bytes()).to_string())
.await
.expect("failed to get validators root")
});

Expand Down
1 change: 0 additions & 1 deletion plonky2x/src/frontend/eth/beacon/generators/withdrawal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ impl<L: PlonkParameters<D>, const D: usize> SimpleGenerator<L::Field, D>
let result = rt.block_on(async {
self.client
.get_withdrawal(hex!(block_root.as_bytes()).to_string(), idx.as_u64())
.await
.expect("failed to get validators root")
});

Expand Down
1 change: 0 additions & 1 deletion plonky2x/src/frontend/eth/beacon/generators/withdrawals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ impl<L: PlonkParameters<D>, const D: usize> SimpleGenerator<L::Field, D>
let result = rt.block_on(async {
self.client
.get_withdrawals_root(hex!(block_root.as_bytes()).to_string())
.await
.expect("failed to get validators root")
});

Expand Down
Loading
Loading