aleonet / aleo-education Goto Github PK
View Code? Open in Web Editor NEWAleo Education
Aleo Education
Encountering occasional discrepancies in swap and bridge transactions between Seplia and Aleo platforms. Despite successfully completing the task, the Aleo account fails to reflect the expected outcome.
Little wonder how negligence and lack of full/proper knowledge can affect genuine productivity
Get yourself equip..
Some time bridge and swap problem
Some time
Seplia to aleo task done
But
Aleo account didn't show and
Hello,
While doing Aleo exercices I noticed something strange with the code which defines a "zero" point: https://github.com/AleoHQ/aleo-education/blob/d6013a0ba18377eaf86f645db00bf93e62287a7d/hangman/src/main.leo#L105-L106
The value used for y
is 0x1ae3a4617c510eac63b05c06ca1493b1a22d9f300f5138f1ef3622fba094800170b5d44300000008508c00000000001, which is the correct "base field modulus" of BLS12-377 (https://eips.ethereum.org/EIPS/eip-2539), but in Leo this value is truncated. When displaying the content of digest.y
in the program:
console.log("digest.y = {}", digest.y);
The output is:
digest.y = 9586122913090633729
This is because defining the number as field
takes the value modulo the "Main subgroup order" 0x12ab655e9a2ca55660b44d1e5c37b00159aa76fed00000010a11800000000001. This can be seen in the following Python code:
>>> base_field_modulus = 0x1ae3a4617c510eac63b05c06ca1493b1a22d9f300f5138f1ef3622fba094800170b5d44300000008508c00000000001
>>> subgroup_order = 0x12ab655e9a2ca55660b44d1e5c37b00159aa76fed00000010a11800000000001
>>> base_field_modulus % subgroup_order
9586122913090633729
More generally, the Point
circuit in hangman/src/main.leo
represents a point with coordinates modulo subgroup_order
instead of base_field_modulus
. This leads to two questions:
base_field_modulus
instead of subgroup_order
)?By the way, thanks for this educational content! It is a great way to learn about ZK-based systems such as Aleo.
I love aleo
I noticed that some parts of the code have incomplete logic flow or missing implementations, such as the valid_char function and parts of the guess_letter function.
Here's a revised version. Kindly review and let me know if there is anything you want me to add. I am looking forward for a meaningful contribution.
Please feel free to correct is I'm wrong.
circuit Hangman {
commitment: Point,
revealed: [char; 20],
used_guesses: [char; 10],
guesses_left: u32,
victory: bool,
// Function to check if a character is a lowercase English alphabet letter
function valid_char(c: char) -> bool {
const valid_chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
let is_valid_char = false;
for char in valid_chars {
if c == char {
is_valid_char = true;
break;
}
}
return is_valid_char;
}
// Function to initialize a new game of Hangman
function new_game(word: [char; 20], const word_length: u32) -> Self {
const digest: Point = Point { x: 0field, y: 258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177field };
const x: field = 7810607721416582242904415504650443951498042435501746664987470571546413371306field;
const y: field = 1867362672570137759132108893390349941423731440336755218616442213142473202417field;
let hasher = PedersenHash::new(digest, [x; 256], [y; 256]);
let hash: Point = hasher.hash([true; 256]);
let mut valid_word = true;
for char in word {
if !Hangman::valid_char(char) {
valid_word = false;
break;
}
}
if word_length > 20 {
valid_word = false;
}
if !valid_word {
return Self {
commitment: Point { x: 0field, y: 0field },
revealed: ['_'; 20],
used_guesses: ['_'; 10],
guesses_left: 0u32,
victory: false,
};
}
return Self {
commitment: hash,
revealed: ['_'; 20],
used_guesses: ['_'; 10],
guesses_left: 10u32,
victory: false,
};
}
// Function to handle a letter guess
function guess_letter(mut self, letter: char) -> Self {
let mut is_valid_guess = true;
// Check if the guessed letter is valid
if !Hangman::valid_char(letter) {
is_valid_guess = false;
}
// Check if the guessed letter has already been used
for used_letter in self.used_guesses {
if letter == used_letter {
is_valid_guess = false;
break;
}
}
// Update the game state based on the guess
if is_valid_guess {
let mut found_letter = false;
for (i, char) in self.revealed.iter_mut().enumerate() {
if letter == self.word[i] {
*char = letter;
found_letter = true;
}
}
if !found_letter {
self.guesses_left -= 1;
}
}
// Check for victory condition
if self.revealed.iter().all(|&c| c != '_') {
self.victory = true;
}
// Update used guesses
for (i, used_letter) in self.used_guesses.iter_mut().enumerate() {
if *used_letter == '_' {
*used_letter = letter;
break;
}
}
return self;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.