Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Leo #6970

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add Leo #6970

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,9 @@
[submodule "vendor/grammars/latex.tmbundle"]
path = vendor/grammars/latex.tmbundle
url = https://github.com/textmate/latex.tmbundle
[submodule "vendor/grammars/leo-linguist"]
path = vendor/grammars/leo-linguist
url = https://github.com/ProvableHQ/leo-linguist.git
[submodule "vendor/grammars/linter-lilypond"]
path = vendor/grammars/linter-lilypond
url = https://github.com/nwhetsell/linter-lilypond
Expand Down
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,8 @@ vendor/grammars/latex.tmbundle:
- text.tex.latex
- text.tex.latex.beamer
- text.tex.latex.memoir
vendor/grammars/leo-linguist:
- source.leo
vendor/grammars/linter-lilypond:
- source.lilypond
vendor/grammars/liquid-tm-grammar:
Expand Down
9 changes: 9 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3784,6 +3784,15 @@ Lean 4:
tm_scope: source.lean4
ace_mode: text
language_id: 455147478
Leo:
type: programming
color: "#6814EC"
extensions:
- ".leo"
tm_scope: source.leo
ace_mode: text
wrap: true
language_id: 916034822
Less:
type: markup
color: "#1d365d"
Expand Down
50 changes: 50 additions & 0 deletions samples/Leo/fibonacci.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This program follows the license outlined, here: https://github.com/ProvableHQ/leo/blob/mainnet/LICENSE.md

program fibonacci.aleo {
// This calculates the n-th fibonacci number (up to 64th)
transition fibonacci(public n: u8) -> u128 {
assert(n <= 64u8);

let f0: u128 = 0u128;
let f1: u128 = 1u128;
let c: u8 = 0u8;

let z: u8 = reverse_bits(n);

for i:u8 in 0u8..8u8 {
if n > 0u8 {
let f2i1: u128 = f1 * f1 + f0 * f0;
let f2i: u128 = f0 * (2u128 * f1 - f0);
if z & 1u8.shl(c) == 0u8 {
f0 = f2i;
f1 = f2i1;
} else {
f0 = f2i1;
f1 = f2i + f2i1;
}
c = c + 1u8;
n = n >> 1u8;
}
}

return f0;
}

function reverse_bits(n: u8) -> u8 {
let reverse: u8 = 0u8;

for i:u8 in 0u8..8u8 {
if n > 0u8 {
reverse = reverse << 1u8;

if n & 1u8 == 1u8 {
reverse ^= 1u8;
}

n = n >> 1u8;
}
}

return reverse;
}
}
20 changes: 20 additions & 0 deletions samples/Leo/groups.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This program follows the license outlined, here: https://github.com/ProvableHQ/leo/blob/mainnet/LICENSE.md

program groups.aleo {
// This function takes a group coordinate as input `a` and performs several operations which should output the `0group`.
// Note that the operations can be called as associated functions on the `a` variable.

transition main(a: group) -> group {
// unary
let b: group = a.double(); // 2a
let c: group = b.neg(); // -2a

// binary
let d: group = (a * 2scalar).add(c);

// generator
let e: group = group::GEN;

return d + e;
}
}
30 changes: 30 additions & 0 deletions samples/Leo/twoadicity.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This program follows the license outlined, here: https://github.com/AleoHQ/leo/blob/mainnet/LICENSE.md

program twoadicity.aleo {
// This function calculates the number of powers of two ("twoadicity")
// in the prime factorization of the input number `n`.
transition main(public n: field) -> u8 {
let remaining_n: field = n;
let powers_of_two: u8 = 0u8;
// Since field ints are 253 bits or fewer, any number in the field
// will have at most 252 powers of two in its prime factoring.
for i:u8 in 0u8..252u8 {
if is_even_and_nonzero(remaining_n) {
remaining_n = remaining_n / 2field;
powers_of_two = powers_of_two + 1u8;
}
}
return powers_of_two;
}

/* We define the is_even predicate on fields as follows.
If n is even and nonzero, clearly n/2 < n.
If n is odd, n-p is a field-equivalent negative number that is even, and
(n-p)/2 is a field-equivalent negative number closer to 0, greater than n-p.
If we add p to both of these negative numbers, we have
n/2 = (n-p)/2 + p = (n+p)/2 is greater than n and still less than p.
*/
function is_even_and_nonzero (n: field) -> bool {
return n / 2field < n;
}
}
88 changes: 88 additions & 0 deletions samples/Leo/vote.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// This program follows the license outlined, here: https://github.com/AleoHQ/leo/blob/mainnet/LICENSE.md

program vote.aleo {
// Proposal details
struct ProposalInfo {
title: field,
content: field,
proposer: address,
}

// Proposal record records proposal info publicly
record Proposal {
owner: address,
id: field,
info: ProposalInfo,
}

// Save proposal info in public storage.
mapping proposals: field => ProposalInfo;

// Privacy tickets to vote
record Ticket {
owner: address,
pid: field,
}

// Count the total tickets issued for each proposal
mapping tickets: field => u64;

mapping agree_votes: field => u64;

mapping disagree_votes: field => u64;

// Propose a new proposal to vote on.
async transition propose(public info: ProposalInfo) -> (Proposal, Future) {
// Authenticate proposer.
assert_eq(self.caller, info.proposer);

// Generate a new proposal id.
let id: field = BHP256::hash_to_field(info.title);


// Return a new record for the proposal.
// Finalize the proposal id.
return (Proposal { owner: self.caller, id, info }, finalize_propose(id));
}
// Create a new proposal in the "tickets" mapping.
async function finalize_propose(public id: field) {
Mapping::set(tickets, id, 0u64);
}

// Create a new ticket to vote with.
async transition new_ticket(
public pid: field,
public voter: address,
) -> (Ticket, Future) {

// Finalize the proposal id for the ticket.
return (Ticket { owner: voter, pid }, finalize_new_ticket(pid));
}
// Create a new ticket on a proposal in the "tickets" mapping.
async function finalize_new_ticket(public pid: field) {
let current: u64 = Mapping::get_or_use(tickets, pid, 0u64);
Mapping::set(tickets, pid, current + 1u64);
}

// Vote privately to agree with a proposal.
async transition agree(ticket: Ticket) -> Future {
// Finalize this vote.
return finalize_agree(ticket.pid);
}
async function finalize_agree(public pid: field) {
// Publicly increment the number of agree votes.
let current: u64 = Mapping::get_or_use(agree_votes, pid, 0u64);
Mapping::set(agree_votes, pid, current + 1u64);
}

// Vote privately to disagree with a proposal.
async transition disagree(ticket: Ticket) -> Future {
// Finalize this vote.
return finalize_disagree(ticket.pid);
}
async function finalize_disagree(pid: field) {
// Publicly increment the number of disagree votes.
let current: u64 = Mapping::get_or_use(disagree_votes, pid, 0u64);
Mapping::set(disagree_votes, pid, current + 1u64);
}
}
1 change: 1 addition & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **Latte:** [textmate/php-smarty.tmbundle](https://github.com/textmate/php-smarty.tmbundle)
- **Lean:** [leanprover/vscode-lean](https://github.com/leanprover/vscode-lean)
- **Lean 4:** [leanprover/vscode-lean4](https://github.com/leanprover/vscode-lean4)
- **Leo:** [ProvableHQ/leo-linguist](https://github.com/ProvableHQ/leo-linguist)
- **Less:** [atom/language-less](https://github.com/atom/language-less)
- **Lex:** [Alhadis/language-grammars](https://github.com/Alhadis/language-grammars)
- **LigoLANG:** [pewulfman/Ligo-grammar](https://github.com/pewulfman/Ligo-grammar)
Expand Down
1 change: 1 addition & 0 deletions vendor/grammars/leo-linguist
Submodule leo-linguist added at 4f4d7d
Loading