Skip to content

Commit

Permalink
fix sgx aggregation for back compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: smtmfft <[email protected]>
  • Loading branch information
smtmfft committed Sep 23, 2024
1 parent fa6fe88 commit 1aaec18
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion host/src/server/api/v3/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
server::api::{v2, v3::Status},
Message, ProverState,
};
use tracing::{debug, info};

mod aggregate;
mod cancel;
Expand Down Expand Up @@ -111,10 +112,12 @@ async fn proof_handler(
if is_registered {
Ok(TaskStatus::Registered.into())
} else if is_success {
info!("All tasks are successful, aggregating proofs");
let mut proofs = Vec::with_capacity(tasks.len());
for (task, _req) in tasks {
for (task, req) in tasks {
let raw_proof = manager.get_task_proof(&task).await?;
let proof = serde_json::from_slice(&raw_proof)?;
debug!("req: {:?} gets proof: {:?}", req, proof);
proofs.push(proof);
}

Expand Down
14 changes: 13 additions & 1 deletion lib/src/protocol_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
},
CycleTracker,
};
use log::info;
use log::{debug, info};
use reth_evm_ethereum::taiko::ANCHOR_GAS_LIMIT;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -275,6 +275,18 @@ impl ProtocolInstance {
pub fn instance_hash(&self) -> B256 {
// packages/protocol/contracts/verifiers/libs/LibPublicInput.sol
// "VERIFY_PROOF", _chainId, _verifierContract, _tran, _newInstance, _prover, _metaHash
debug!(
"caclucate instance_hash from:

Check warning on line 279 in lib/src/protocol_instance.rs

View workflow job for this annotation

GitHub Actions / check-for-typos

"caclucate" should be "calculate".
chain_id: {:?}, verifier: {:?}, transition: {:?}, sgx_instance: {:?},
prover: {:?}, block_meta: {:?}, meta_hash: {:?}",
self.chain_id,
self.verifier_address,
self.transition.clone(),
self.sgx_instance,
self.prover,
self.block_metadata,
self.meta_hash(),
);
let data = (
"VERIFY_PROOF",
self.chain_id,
Expand Down
9 changes: 5 additions & 4 deletions provers/sgx/guest/src/one_shot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ pub async fn one_shot(global_opts: GlobalOpts, args: OneShotArgs) -> Result<()>
let sig = sign_message(&prev_privkey, pi_hash)?;

// Create the proof for the onchain SGX verifier
// 4(id) + 20(new) + 65(sig) = 89
const SGX_PROOF_LEN: usize = 89;
let mut proof = Vec::with_capacity(SGX_PROOF_LEN);
proof.extend(args.sgx_instance_id.to_be_bytes());
proof.extend(new_instance);
proof.extend(new_instance);
proof.extend(sig);
let proof = hex::encode(proof);

Expand Down Expand Up @@ -194,11 +194,11 @@ pub async fn aggregate(global_opts: GlobalOpts, args: OneShotArgs) -> Result<()>
for proof in input.proofs.iter() {
// TODO: verify protocol instance data so we can trust the old/new instance data
assert_eq!(
recover_signer_unchecked(&proof.proof.clone()[44..].try_into().unwrap(), &proof.input,)
recover_signer_unchecked(&proof.proof.clone()[24..].try_into().unwrap(), &proof.input,)
.unwrap(),
cur_instance,
);
cur_instance = Address::from_slice(&proof.proof.clone()[24..44]);
cur_instance = Address::from_slice(&proof.proof.clone()[4..24]);
}

// Current public key needs to match latest proof new public key
Expand All @@ -224,7 +224,8 @@ pub async fn aggregate(global_opts: GlobalOpts, args: OneShotArgs) -> Result<()>
let sig = sign_message(&prev_privkey, aggregation_hash.into())?;

// Create the proof for the onchain SGX verifier
const SGX_PROOF_LEN: usize = 89;
const SGX_PROOF_LEN: usize = 109;
// 4(id) + 20(old) + 20(new) + 65(sig) = 109
let mut proof = Vec::with_capacity(SGX_PROOF_LEN);
proof.extend(args.sgx_instance_id.to_be_bytes());
proof.extend(old_instance);
Expand Down

0 comments on commit 1aaec18

Please sign in to comment.