Consider the following three stage interactive zero knowledge proof
- The prover sends some information $a$ to the verifier.
- The verifier picks a challenge $c\in \{0 ,1\}$
- Depending on the challenge, the prover responds with $r(c)$ that convinces the verifier of his knowledge.
Each round can be won with probability $\frac{1}{2}$ by a malicious prover and so we must play this for $k$ rounds till $\frac{1}{2^k}$ is sufficiently small.
The Fiat Shamir transformation replaces the challenge generation with a random oracle that generates $c$ instead. Let $i$ be the round number (we play $k$ rounds). Typically, one can use a hash function $c_i = H(p_{i-1}, a_{i-1})$ for this purpose, where $p_{i-1}$ is some input generated from prior rounds and $a_{i-1}$ is the previous round's commitment. The prover then generates a transcript of the following form after many rounds
$$T = \{a_i, c_i = H(p_{i-1}, a_{i-1}), r_i\}$$
It is not clear to me why this is secure. In each round, the dishonest prover can simply keep trying different $a_{i-1}$ until $H(p_{i-1}, a_{i-1})$ is the challenge he is prepared to meet. Since $c\in\{0,1\}$ (i.e. the range of $H$ is just $\{0,1\}$), this does not take him many tries. The prover will only include such challanges (which he is prepared to meet) in the transcript.
What exactly is the correct Fiat Shamir transformation that prevents this attack by a dishonest prover?