Skip to content

Commit

Permalink
update prover_registry abi
Browse files Browse the repository at this point in the history
  • Loading branch information
amoylan2 committed Nov 3, 2024
1 parent 9b8409c commit dcf086c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 38 deletions.
File renamed without changes.
1 change: 0 additions & 1 deletion crates/tee/src/attestation_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ impl From<AttestationReport> for RegisterCall {
_report: value.report,
_data: ReportData {
addr: value.address,
teeType: value.tee_type,
referenceBlockHash: value.reference_block_hash,
referenceBlockNumber: value.reference_block_number,
},
Expand Down
42 changes: 5 additions & 37 deletions crates/tee/src/prover_registry.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use alloy::{
primitives::{Address, Bytes},
primitives::Address,
rpc::types::TransactionReceipt,
sol_types::SolEvent,
};
use ProverRegistryStub::{Poe, Proof, ProverRegistryStubErrors};
use ProverRegistryStub::ProverRegistryStubErrors;

use base::eth::{Eth, EthError};

Expand Down Expand Up @@ -43,11 +43,6 @@ impl ProverRegistry {
Self { eth, contract }
}

pub async fn chain_id(&self) -> Result<u64, RegistryError> {
let call = ProverRegistryStub::chainIDCall {};
Ok(self.eth.call(self.contract, &call).await?._0.to())
}

pub async fn attest_validity_seconds(&self) -> Result<u64, RegistryError> {
let call = ProverRegistryStub::attestValiditySecondsCall {};
Ok(self.eth.call(self.contract, &call).await?._0.to())
Expand Down Expand Up @@ -78,41 +73,14 @@ impl ProverRegistry {
log::info!("[register] waiting receipt for: {:?}", tx.tx_hash());
let receipt = tx.get_receipt().await.map_err(EthError::from)?;

let instance_add = Self::get_event::<InstanceAdded>(&receipt)
let instance_add = Self::get_event::<ProverRegistered>(&receipt)
.ok_or(RegistryError::MissingInstanceIdOnRegister)?;

Ok(Registration {
address: instance_add.id,
address: instance_add.prover,
valid_until: instance_add.validUntil.to(),
})
}

pub async fn get_poe_hash(&self, poe: Poe) -> Result<Bytes, RegistryError> {
use ProverRegistryStub::*;
let call = getSignedMsgCall { _poe: poe };
let ret = self.eth.call(self.contract, &call).await?;
Ok(ret._0)
}

pub async fn recover_old_instance(&self, proof: Proof) -> Result<Address, RegistryError> {
use ProverRegistryStub::*;
let call = recoverOldInstanceCall {
_poe: proof.poe,
_signature: proof.signature,
};
Ok(self.eth.call(self.contract, &call).await?._0)
}

pub async fn verify_proofs(&self, proofs: Vec<Proof>) -> Result<(), RegistryError> {
use ProverRegistryStub::*;

let call = verifyProofsCall { _proofs: proofs };
let tx = self.eth.transact(self.contract, &call).await?;
log::info!("[verify_proofs] waiting receipt for: {:?}", tx.tx_hash());
let receipt = tx.get_receipt().await.map_err(EthError::from)?;
log::info!("receipt: {:?}", receipt);
Ok(())
}
}

#[derive(Clone, Debug)]
Expand All @@ -124,5 +92,5 @@ pub struct Registration {
alloy::sol! {
#[derive(Debug, Default)]
ProverRegistryStub,
r#"[{"type":"constructor","inputs":[{"name":"_verifierAddr","type":"address","internalType":"address"},{"name":"_chainID","type":"uint256","internalType":"uint256"},{"name":"_attestValiditySeconds","type":"uint256","internalType":"uint256"},{"name":"_maxBlockNumberDiff","type":"uint256","internalType":"uint256"}],"stateMutability":"nonpayable"},{"type":"function","name":"attestValiditySeconds","inputs":[],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"type":"function","name":"attestedProvers","inputs":[{"name":"proverAddr","type":"address","internalType":"address"}],"outputs":[{"name":"addr","type":"address","internalType":"address"},{"name":"validUntil","type":"uint256","internalType":"uint256"},{"name":"teeType","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"type":"function","name":"attestedReports","inputs":[{"name":"reportHash","type":"bytes32","internalType":"bytes32"}],"outputs":[{"name":"used","type":"bool","internalType":"bool"}],"stateMutability":"view"},{"type":"function","name":"chainID","inputs":[],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"type":"function","name":"checkProver","inputs":[{"name":"_proverAddr","type":"address","internalType":"address"}],"outputs":[{"name":"","type":"tuple","internalType":"struct IProverRegistry.ProverInstance","components":[{"name":"addr","type":"address","internalType":"address"},{"name":"validUntil","type":"uint256","internalType":"uint256"},{"name":"teeType","type":"uint256","internalType":"uint256"}]}],"stateMutability":"view"},{"type":"function","name":"getSignedMsg","inputs":[{"name":"_poe","type":"tuple","internalType":"struct IProverRegistry.Poe","components":[{"name":"batchHash","type":"bytes32","internalType":"bytes32"},{"name":"prevStateRoot","type":"bytes32","internalType":"bytes32"},{"name":"newStateRoot","type":"bytes32","internalType":"bytes32"},{"name":"withdrawalRoot","type":"bytes32","internalType":"bytes32"}]}],"outputs":[{"name":"","type":"bytes","internalType":"bytes"}],"stateMutability":"view"},{"type":"function","name":"maxBlockNumberDiff","inputs":[],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"type":"function","name":"recoverOldInstance","inputs":[{"name":"_poe","type":"tuple","internalType":"struct IProverRegistry.Poe","components":[{"name":"batchHash","type":"bytes32","internalType":"bytes32"},{"name":"prevStateRoot","type":"bytes32","internalType":"bytes32"},{"name":"newStateRoot","type":"bytes32","internalType":"bytes32"},{"name":"withdrawalRoot","type":"bytes32","internalType":"bytes32"}]},{"name":"_signature","type":"bytes","internalType":"bytes"}],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"type":"function","name":"register","inputs":[{"name":"_report","type":"bytes","internalType":"bytes"},{"name":"_data","type":"tuple","internalType":"struct IProverRegistry.ReportData","components":[{"name":"addr","type":"address","internalType":"address"},{"name":"teeType","type":"uint256","internalType":"uint256"},{"name":"referenceBlockNumber","type":"uint256","internalType":"uint256"},{"name":"referenceBlockHash","type":"bytes32","internalType":"bytes32"}]}],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"verifier","inputs":[],"outputs":[{"name":"","type":"address","internalType":"contract AttestationVerifier"}],"stateMutability":"view"},{"type":"function","name":"verifyProofs","inputs":[{"name":"_proofs","type":"tuple[]","internalType":"struct IProverRegistry.Proof[]","components":[{"name":"poe","type":"tuple","internalType":"struct IProverRegistry.Poe","components":[{"name":"batchHash","type":"bytes32","internalType":"bytes32"},{"name":"prevStateRoot","type":"bytes32","internalType":"bytes32"},{"name":"newStateRoot","type":"bytes32","internalType":"bytes32"},{"name":"withdrawalRoot","type":"bytes32","internalType":"bytes32"}]},{"name":"signature","type":"bytes","internalType":"bytes"},{"name":"teeType","type":"uint256","internalType":"uint256"}]}],"outputs":[],"stateMutability":"view"},{"type":"event","name":"InstanceAdded","inputs":[{"name":"id","type":"address","indexed":true,"internalType":"address"},{"name":"validUntil","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"error","name":"BLOCK_NUMBER_MISMATCH","inputs":[]},{"type":"error","name":"BLOCK_NUMBER_OUT_OF_DATE","inputs":[]},{"type":"error","name":"ECDSAInvalidSignature","inputs":[]},{"type":"error","name":"ECDSAInvalidSignatureLength","inputs":[{"name":"length","type":"uint256","internalType":"uint256"}]},{"type":"error","name":"ECDSAInvalidSignatureS","inputs":[{"name":"s","type":"bytes32","internalType":"bytes32"}]},{"type":"error","name":"INVALID_BLOCK_NUMBER","inputs":[]},{"type":"error","name":"INVALID_PROVER_INSTANCE","inputs":[]},{"type":"error","name":"INVALID_REPORT","inputs":[]},{"type":"error","name":"INVALID_REPORT_DATA","inputs":[]},{"type":"error","name":"PROVER_ADDR_MISMATCH","inputs":[{"name":"","type":"address","internalType":"address"},{"name":"","type":"address","internalType":"address"}]},{"type":"error","name":"PROVER_INVALID_ADDR","inputs":[{"name":"","type":"address","internalType":"address"}]},{"type":"error","name":"PROVER_INVALID_INSTANCE_ID","inputs":[{"name":"","type":"uint256","internalType":"uint256"}]},{"type":"error","name":"PROVER_OUT_OF_DATE","inputs":[{"name":"","type":"uint256","internalType":"uint256"}]},{"type":"error","name":"PROVER_TYPE_MISMATCH","inputs":[]},{"type":"error","name":"REPORT_DATA_MISMATCH","inputs":[]},{"type":"error","name":"REPORT_USED","inputs":[]}]"#,
"abi/SGXVerifier.json"
}

0 comments on commit dcf086c

Please sign in to comment.