### 零知识证明 - zkHack mini挑战赛第一名

Trapdoor Tech获得zkHack mini挑战赛第一名 :)

https://www.zkhack.dev/mini.html

### 第一题：There's something in the AIR

https://www.zkhack.dev/puzzleM1.html

### 解题思路

• 证明者(prover)能产生 > 1 个的nullifier，并基于此构建证据(witness)
• 验证者(verifier)根据相应的公开输入和证据，无法分辨证明者伪造的nullifier

``````//! - A nullifier is computed by hashing a private key together with a hash of the topic - i.e.:
//!   hash(priv_key, hash(topic)) using the same Rp64_256 hash function.

let nullifier = priv_key.get_nullifier(topic);

/// Creates a nullifier for the provided topic against this private key.
///
/// A nullifier is computed simply as hash(key, topic).
pub fn get_nullifier(&self, topic: Digest) -> Digest {
let key: Digest = self.0.into();
Rescue::merge(&[key, topic])
}``````

``````// prover set the initial state
// -- nullifier section of the trace --
state[12] = Felt::new(8);
state[13] = Felt::ZERO;
state[14] = Felt::ZERO;
state[15] = Felt::ZERO;
state[16] = priv_key[0];
state[17] = priv_key[1];
state[18] = priv_key[2];
state[19] = priv_key[3];
state[20] = topic[0];
state[21] = topic[1];
state[22] = topic[2];
state[23] = topic[3];``````

``[12     13       14     15]   [ 16     17   18     19 ]   [   20   21 22   23 ]``

nullifier = [8 0, 0, 0, --- 私钥Priv_key----------, -----主题Topic------- ] -- 在执行到第 0 步时

``````result.agg_constraint(1, hash_init_flag, are_equal(E::from(8u8), next[0]));
result.agg_constraint(2, hash_init_flag, is_zero(next[1]));
result.agg_constraint(3, hash_init_flag, is_zero(next[2]));
result.agg_constraint(4, hash_init_flag, is_zero(next[3]));``````

### 答案

``````pub fn get_fake_nullifier(&self, topic: Digest) -> Digest {
let key: Digest = self.0.into();

let mut state = [Felt::ZERO; 12];
state[4..12].copy_from_slice(Digest::digests_as_elements(&[key, topic]));
state[0] = Felt::new(0 as u64);

// apply the Rescue permutation and return the first four elements of the state
Rescue::apply_permutation(&mut state);
Digest::new(state
[4..8].try_into().unwrap())
}``````

``````Prover.build_trace()
|state| {
......
// -- nullifier section of the trace --
state[12] = Felt::new(0);``````

### 第二题：Can you turn up the heat?

https://www.zkhack.dev/puzzleM2.html

• 发表于 2022-03-21 14:10
• 阅读 ( 675 )
• 学分 ( 1 )
• 分类：零知识

Star Li

80 篇文章, 6159 学分