Skip to content

Commit b64384a

Browse files
committed
feat: show error message on verification failure
1 parent 8ab1a62 commit b64384a

1 file changed

Lines changed: 27 additions & 8 deletions

File tree

src/verifier.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,26 @@ use crate::{
99
use crate::utils::load_vk_from_json;
1010

1111
#[cfg(not(feature = "std"))]
12-
use alloc::{string::String, vec::Vec};
12+
// ===== 💡 FIX: format 매크로를 가져옵니다. =====
13+
use alloc::{format, string::String, vec::Vec};
14+
// ===============================================
15+
16+
/// 검증 실패의 원인을 구체적으로 나타내는 오류 타입입니다.
17+
#[derive(Debug)]
18+
pub enum VerifyError {
19+
SumcheckFailed(String),
20+
ShplonkFailed(String),
21+
}
22+
23+
/// 디버깅 및 로깅을 위해 VerifyError를 String으로 변환할 수 있도록 합니다.
24+
impl From<VerifyError> for String {
25+
fn from(err: VerifyError) -> String {
26+
match err {
27+
VerifyError::SumcheckFailed(s) => format!("Sum-check failed: {}", s),
28+
VerifyError::ShplonkFailed(s) => format!("Shplonk failed: {}", s),
29+
}
30+
}
31+
}
1332

1433
pub struct UltraHonkVerifier {
1534
vk: crate::types::VerificationKey,
@@ -32,12 +51,12 @@ impl UltraHonkVerifier {
3251
&self.vk
3352
}
3453

35-
/// Top-level verify
54+
/// Top-level verify. 반환 타입을 String에서 구체적인 VerifyError로 변경했습니다.
3655
pub fn verify(
3756
&self,
3857
proof_bytes: &[u8],
3958
public_inputs_bytes: &[Vec<u8>],
40-
) -> Result<(), String> {
59+
) -> Result<(), VerifyError> {
4160
// 1) parse proof
4261
let proof = load_proof(proof_bytes);
4362

@@ -72,11 +91,11 @@ impl UltraHonkVerifier {
7291
self.vk.circuit_size,
7392
);
7493

75-
// 5) Sum-check
76-
verify_sumcheck(&proof, &tx, &self.vk)?;
94+
// 5) Sum-check: 실패 시 SumcheckFailed 오류를 반환합니다.
95+
verify_sumcheck(&proof, &tx, &self.vk).map_err(VerifyError::SumcheckFailed)?;
7796

78-
// 6) Shplonk (batch opening)
79-
verify_shplemini(&proof, &self.vk, &tx)?;
97+
// 6) Shplonk (batch opening): 실패 시 ShplonkFailed 오류를 반환합니다.
98+
verify_shplemini(&proof, &self.vk, &tx).map_err(VerifyError::ShplonkFailed)?;
8099

81100
Ok(())
82101
}
@@ -110,4 +129,4 @@ impl UltraHonkVerifier {
110129
}
111130
num * den.inverse()
112131
}
113-
}
132+
}

0 commit comments

Comments
 (0)