-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add function verify_proof_and_register
- Loading branch information
Showing
12 changed files
with
4,125 additions
and
21 deletions.
There are no files selected for viewing
Submodule navori
updated
44 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
with open("data", "r") as r: | ||
for num in r.readlines(): | ||
print(f"\"{num[0:-1]}\",") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod types; | ||
pub mod verify_proof_and_register; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod verify_proof_and_register; |
58 changes: 58 additions & 0 deletions
58
src/contracts_caller/gps/types/verify_proof_and_register.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use std::str::FromStr; | ||
|
||
use aptos_sdk::move_types::u256::U256; | ||
use serde::Deserialize; | ||
|
||
#[derive(Debug)] | ||
pub struct VerifyProofAndRegisterData { | ||
pub proof_params: Vec<U256>, | ||
pub proof: Vec<U256>, | ||
pub task_metadata: Vec<U256>, | ||
pub cairo_aux_input: Vec<U256>, | ||
pub cairo_verifier_id: U256, | ||
pub pre_registered_facts: Vec<U256>, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct VerifyProofAndRegisterDataJson { | ||
pub proof_params: Vec<String>, | ||
pub proof: Vec<String>, | ||
pub task_metadata: Vec<String>, | ||
pub cairo_aux_input: Vec<String>, | ||
pub cairo_verifier_id: String, | ||
pub pre_registered_facts: Vec<String>, | ||
} | ||
|
||
impl From<VerifyProofAndRegisterDataJson> for VerifyProofAndRegisterData { | ||
fn from(value: VerifyProofAndRegisterDataJson) -> Self { | ||
VerifyProofAndRegisterData { | ||
proof_params: value | ||
.proof_params | ||
.iter() | ||
.map(|x| U256::from_str(x).unwrap()) | ||
.collect(), | ||
proof: value | ||
.proof | ||
.iter() | ||
.map(|x| U256::from_str(x).unwrap()) | ||
.collect(), | ||
task_metadata: value | ||
.task_metadata | ||
.iter() | ||
.map(|x| U256::from_str(x).unwrap()) | ||
.collect(), | ||
cairo_aux_input: value | ||
.cairo_aux_input | ||
.iter() | ||
.map(|x| U256::from_str(x).unwrap()) | ||
.collect(), | ||
cairo_verifier_id: U256::from_str(value.cairo_verifier_id.as_str()).unwrap(), | ||
pre_registered_facts: value | ||
.pre_registered_facts | ||
.iter() | ||
.map(|x| U256::from_str(x).unwrap()) | ||
.collect(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use std::fs; | ||
use std::str::FromStr; | ||
|
||
use aptos_sdk::move_types::value::MoveValue; | ||
use aptos_sdk::rest_client::aptos_api_types::MoveType; | ||
use log::debug; | ||
|
||
use crate::config::AppConfig; | ||
use crate::contracts_caller::gps::types::verify_proof_and_register::{ | ||
VerifyProofAndRegisterData, VerifyProofAndRegisterDataJson, | ||
}; | ||
use crate::contracts_caller::transaction_helper::{get_event_from_transaction, send_tx}; | ||
|
||
pub async fn verify_proof_and_register( | ||
config: &AppConfig, | ||
data: &VerifyProofAndRegisterData, | ||
) -> anyhow::Result<()> { | ||
let module_name = "gps_statement_verifier"; | ||
debug!("pre_registered_facts"); | ||
send_tx( | ||
config, | ||
"fact_registry", | ||
"register_facts", | ||
&vec![MoveValue::Vector( | ||
data.pre_registered_facts | ||
.iter() | ||
.map(|v| MoveValue::U256(*v)) | ||
.collect(), | ||
)], | ||
) | ||
.await?; | ||
debug!("prepush_task_metadata"); | ||
send_tx( | ||
config, | ||
module_name, | ||
"prepush_task_metadata", | ||
&vec![MoveValue::Vector( | ||
data.task_metadata | ||
.iter() | ||
.map(|v| MoveValue::U256(*v)) | ||
.collect(), | ||
)], | ||
) | ||
.await?; | ||
debug!("prepush_data_to_verify_proof_and_register"); | ||
send_tx( | ||
config, | ||
module_name, | ||
"prepush_data_to_verify_proof_and_register", | ||
&vec![ | ||
MoveValue::Vector( | ||
data.proof_params | ||
.iter() | ||
.map(|v| MoveValue::U256(*v)) | ||
.collect(), | ||
), | ||
MoveValue::Vector(data.proof.iter().map(|v| MoveValue::U256(*v)).collect()), | ||
MoveValue::Vector( | ||
data.cairo_aux_input | ||
.iter() | ||
.map(|v| MoveValue::U256(*v)) | ||
.collect(), | ||
), | ||
MoveValue::U256(data.cairo_verifier_id), | ||
], | ||
) | ||
.await?; | ||
let mut time = 0; | ||
loop { | ||
time += 1; | ||
debug!("verify_proof_and_register {}", time); | ||
let tx = send_tx(config, module_name, "verify_proof_and_register", &vec![]).await?; | ||
let event = get_event_from_transaction( | ||
&tx, | ||
MoveType::from_str(&format!( | ||
"{}::{}::VparFinished", | ||
config.module_address, module_name | ||
))?, | ||
); | ||
if event.is_ok() { | ||
break; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
// #[cfg(test)] | ||
pub fn sample_data(test_num: isize) -> anyhow::Result<VerifyProofAndRegisterData> { | ||
let data = serde_json::from_str::<VerifyProofAndRegisterDataJson>( | ||
fs::read_to_string(format!( | ||
"src/data_samples/gps/verify_proof_and_register_{}.json", | ||
test_num | ||
))? | ||
.as_str(), | ||
)?; | ||
Ok(VerifyProofAndRegisterData::from(data)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod memory_page_fact_registry; | ||
pub mod gps; | ||
pub mod transaction_helper; | ||
pub mod types; | ||
pub mod verify_fri; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.