-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from brolag/feature/fix-challenge-2
feat: correct downloadable files and verify logic for Challenge #2
- Loading branch information
Showing
3 changed files
with
86 additions
and
16 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
packages/nextjs/public/challenges/challenge_2/files/KnightsKnaves.circom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
pragma circom 2.1.6; | ||
|
||
template KnightsKnaves() { | ||
signal input A_is_knight; // 1 if A is a knight, 0 if A is a knave | ||
signal input B_is_knight; // 1 if B is a knight, 0 if B is a knave | ||
|
||
// Intermediate signals for A's statement | ||
signal A_statement_part1; | ||
signal A_statement_part2; | ||
|
||
// A says "B is a knave" | ||
A_statement_part1 <== A_is_knight * (1 - B_is_knight); | ||
A_statement_part2 <== (1 - A_is_knight) * B_is_knight; | ||
signal A_statement_valid; | ||
A_statement_valid <== A_statement_part1 + A_statement_part2; | ||
|
||
// Intermediate signals for B's statement | ||
signal B_statement_part1; | ||
signal B_statement_part2; | ||
signal B_statement_part1_1; | ||
signal B_statement_part1_2; | ||
signal B_statement_part1_3; | ||
signal B_statement_part2_1; | ||
signal B_statement_part2_2; | ||
signal B_statement_part2_3; | ||
|
||
// If B is a knight (1), then A and B must be of opposite types | ||
//B_statement_part1 <== B_is_knight * (A_is_knight * (1 - B_is_knight) + (1 - A_is_knight) * B_is_knight); | ||
B_statement_part1_1 <== A_is_knight * (1 - B_is_knight); | ||
B_statement_part1_2 <== (1 - A_is_knight) * B_is_knight; | ||
B_statement_part1_3 <== (B_statement_part1_1 + B_statement_part1_2); | ||
B_statement_part1 <== B_is_knight * B_statement_part1_3; | ||
|
||
// If B is a knave (0), then A and B must be of the same type | ||
//B_statement_part2 <== (1 - B_is_knight) * (A_is_knight * B_is_knight + (1 - A_is_knight) * (1 - B_is_knight)); | ||
B_statement_part2_1 <== A_is_knight * B_is_knight; | ||
B_statement_part2_2 <== (1 - A_is_knight) * (1 - B_is_knight); | ||
B_statement_part2_3 <== B_statement_part2_1 + B_statement_part2_2; | ||
B_statement_part2 <== (1 - B_is_knight) * B_statement_part2_3; | ||
|
||
signal B_statement_valid; | ||
B_statement_valid <== B_statement_part1 + B_statement_part2; | ||
|
||
// Enforce that both statements must be valid | ||
signal output is_consistent; | ||
is_consistent <== A_statement_valid * B_statement_valid; | ||
|
||
// Enforce that is_consistent must be 1 | ||
// This makes sure the circuit will only accept valid proofs | ||
is_consistent * (is_consistent - 1) === 0; // This ensures is_consistent is either 0 or 1 | ||
is_consistent === 1; // This ensures is_consistent is 1 | ||
|
||
} | ||
|
||
component main = KnightsKnaves(); |
41 changes: 28 additions & 13 deletions
41
packages/nextjs/public/challenges/challenge_2/statement.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
const Challenge2Content = () => ( | ||
<div className="w-full max-w-[64rem] p-4 bg-gray-700 rounded-lg mb-6 font-play shadow-lg"> | ||
<div className="mb-4"> | ||
<h3 className="text-white text-xl font-bold">Statements</h3> | ||
<ul className="text-gray-300"> | ||
<li>- Knights always tell the truth.</li> | ||
<li>- Knaves always lie.</li> | ||
</ul> | ||
<div className="w-full max-w-[64rem] p-4 bg-gray-700 rounded-lg mb-6 font-play shadow-lg"> | ||
<div className="mb-4"> | ||
<h3 className="text-white text-xl font-bold">Puzzle: Knights and Knaves</h3> | ||
<p className="text-gray-300"> | ||
This is a classic logic puzzle involving two characters, A and B. Each character is either a knight, who always tells the truth, or a knave, who always lies. Your task is to determine who is the knight and who is the knave based on their statements. | ||
</p> | ||
</div> | ||
<div className="mb-4"> | ||
<h4 className="text-white text-lg font-bold">Rules</h4> | ||
<ul className="text-gray-300"> | ||
<li>- Knights always tell the truth.</li> | ||
<li>- Knaves always lie.</li> | ||
</ul> | ||
</div> | ||
<div className="mb-4"> | ||
<h4 className="text-white text-lg font-bold">Statements</h4> | ||
<ul className="text-gray-300"> | ||
<li>Character A: "B is a knave.</li> | ||
<li>Character B: "A and I are of opposite types.</li> | ||
</ul> | ||
</div> | ||
<div className="mb-4"> | ||
<h4 className="text-white text-lg font-bold">Task</h4> | ||
<p className="text-gray-300"> | ||
Write a circuit in Circom that receives the selected value for each character and that the circuit can identify whether the selection of characters is correct or not. The circuit must be compiled using the Groth16 protocol. | ||
</p> | ||
</div> | ||
</div> | ||
<div className="mb-4"> | ||
<p className="text-gray-300">Character A: B is a knave.</p> | ||
<p className="text-gray-300">Character B: A and I are of opposite types.</p> | ||
</div> | ||
</div> | ||
); | ||
); | ||
|
||
export default Challenge2Content; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters