That is precisely the right question to ask, and it delves deep into the field of cryptanalysis.
The answer is: Yes, the security of Keccak degrades gradually as you reduce the number of rounds, and there is no single "magic number" of rounds that is suddenly secure. Security is a spectrum, not a binary switch.
The official Keccak permutation (Keccak-f[1600]
) used in SHA-3 and Ethereum has 24 rounds. This number was not chosen arbitrarily. It was selected to provide a very large security margin against all known cryptanalytic attacks.
Let's break down what "security" means here and how it degrades.
Cryptographers have developed various techniques to "break" hash functions. For a permutation like Keccak's, "breaking" could mean:
- Preimage Attack: Given a hash output
H
, find an input messagem
such thatHash(m) = H
. (This is what our "insecure circuit" attacker was trying to do on a reduced-round version). - Collision Attack: Find two different messages,
m1
andm2
, such thatHash(m1) = Hash(m2)
. - Distinguishing Attack: Differentiate the permutation from a truly random permutation. If you can tell it's not random, you might be able to exploit that non-randomness.
The designers of Keccak and other cryptographers have published extensive analyses showing how many rounds they can successfully attack. Here's a simplified overview:
- 1-3 Rounds: Trivial to analyze and reverse. An attacker could find preimages with a pen and paper.
- 4-6 Rounds: Still very weak. Practical collision and preimage attacks can be mounted on a standard laptop in seconds or minutes.
- 7-9 Rounds: The difficulty increases significantly. Attacks become theoretical or require massive computational resources (e.g., a state-level actor). The best published collision attack on Keccak is for 7 rounds.
- 10-12 Rounds: At this point, no practical attacks are known. Attacks are purely theoretical, requiring more computation than exists on Earth. However, the security margin is still considered too low for a cryptographic standard.
- 12-23 Rounds: There are no known attacks, practical or theoretical, that are better than a brute-force search.
- 24 Rounds: This is the full specification. The number of rounds was chosen to be roughly double the number of rounds that cryptanalysts could "break" at the time of standardization. This large buffer is the security margin. It provides confidence that even if new, more powerful attack techniques are discovered, the full-round function will remain secure.
This brings us back to your question. If you are computing the final N
rounds inside the circuit, how large does N
need to be?
- If N = 2: As we established, this is dangerously insecure. Finding a preimage for 2 rounds is feasible.
- If N = 4: Still highly insecure.
- If N = 6: On the edge of being practically attackable. You would not want to build a system on this.
- If N = 8: We are now entering the territory where practical attacks are not known. However, this is considered a very low security margin. A new cryptanalytic breakthrough could put it at risk.
- If N = 12 (i.e.,
startRound = 12
): This is often cited as a reasonable "floor" for security. You are asking an attacker to find a preimage for a 12-round permutation, for which no attack better than brute force is known. This is a common choice in ZK applications that need to balance security with performance. For example, the original Semaphore protocol used 12 rounds for its Poseidon hash. - If N = 24 (i.e.,
startRound = 0
): This is the full Keccak hash, offering maximum security but no constraint savings.
You are making a direct trade-off:
startRound (Prover's work) |
24 - startRound (Circuit's work) |
Constraint Cost | Security Level |
---|---|---|---|
22 | 2 | Lowest | Insecure. Feasible to find preimages for the last 2 rounds. |
20 | 4 | Very Low | Insecure. Feasible to find preimages for the last 4 rounds. |
18 | 6 | Low | Highly Risky. Near the edge of practical attacks. Do not use. |
12 | 12 | Medium | Good. Considered a strong security floor. No known practical/theoretical attacks. |
0 | 24 | Highest | Maximum. Full Keccak security. |
Recommendation:
If you need to use this technique, a startRound
of 20 or 22 is not secure. You are slicing off too few rounds for the in-circuit portion.
A much safer and more standard choice would be to set startRound = 12
. This splits the work roughly in half, providing significant constraint savings while still requiring the attacker to break a 12-round Keccak permutation inside the circuit, which is believed to be computationally infeasible. You save constraints without making a dangerous compromise on security.