Skip to content

Commit

Permalink
pushing leo to git
Browse files Browse the repository at this point in the history
  • Loading branch information
Program-doctor committed Aug 22, 2024
0 parents commit 81c7ea1
Show file tree
Hide file tree
Showing 2,762 changed files with 201,677 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.'cfg(all(target_arch = "x86_64", target_os = "macos", not(feature = "noconfig)))']
rustflags = ["-C", "target-cpu=native"]
174 changes: 174 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
version: 2.1
commands:
setup_environment:
description: "Setup environment"
parameters:
cache_key:
type: string
default: leo-stable-linux-cache
steps:
- run: set -e
- setup_remote_docker
- run:
name: Prepare environment and install dependencies
command: |
export SCCACHE_CACHE_SIZE=200M
export WORK_DIR="$CIRCLE_WORKING_DIRECTORY/.cache/sccache"
export SCCACHE_DIR="$CIRCLE_WORKING_DIRECTORY/.cache/sccache"
mkdir -p "$CIRCLE_WORKING_DIRECTORY/.bin"
wget https://github.com/mozilla/sccache/releases/download/0.2.13/sccache-0.2.13-x86_64-unknown-linux-musl.tar.gz
tar -C "$CIRCLE_WORKING_DIRECTORY/.bin" -xvf sccache-0.2.13-x86_64-unknown-linux-musl.tar.gz
mv $CIRCLE_WORKING_DIRECTORY/.bin/sccache-0.2.13-x86_64-unknown-linux-musl/sccache $CIRCLE_WORKING_DIRECTORY/.bin/sccache
export PATH="$PATH:$CIRCLE_WORKING_DIRECTORY/.bin"
export RUSTC_WRAPPER="sccache"
rm -rf "$CIRCLE_WORKING_DIRECTORY/.cargo/registry"
sudo apt-get update && sudo apt-get install -y clang llvm-dev llvm pkg-config xz-utils make libssl-dev libssl-dev
- restore_cache:
keys:
- << parameters.cache_key >>

clear_environment:
description: "Clear environment"
parameters:
cache_key:
type: string
default: leo-stable-linux-cache
steps:
- run: (sccache -s||true)
- run: set +e
- save_cache:
key: << parameters.cache_key >>
paths:
- .cache/sccache
- .cargo

install_rust_nightly:
description: "Install Rust nightly toolchain"
steps:
- run: rustup toolchain install nightly-x86_64-unknown-linux-gnu

jobs:
check-style:
docker:
- image: cimg/rust:1.76
resource_class: xlarge
steps:
- checkout
- install_rust_nightly
- setup_environment:
cache_key: leo-fmt-cache
- run:
name: Check style
no_output_timeout: 35m
command: cargo +nightly fmt --all -- --check
- clear_environment:
cache_key: leo-fmt-cache

clippy:
docker:
- image: cimg/rust:1.76
resource_class: xlarge
steps:
- checkout
- setup_environment:
cache_key: leo-clippy-cache
- run:
name: Clippy
no_output_timeout: 35m
command: |
cargo clippy --workspace --all-targets -- -D warnings
cargo clippy --workspace --all-targets --all-features -- -D warnings
- clear_environment:
cache_key: leo-clippy-cache

leo-executable:
docker:
- image: cimg/rust:1.76
resource_class: xlarge
steps:
- checkout
- setup_environment:
cache_key: leo-executable-cache
- run:
name: Build and install Leo
no_output_timeout: 30m
command: cargo install --path . --root . --locked
- persist_to_workspace:
root: ~/
paths:
- project/
- clear_environment:
cache_key: leo-executable-cache

leo-new:
docker:
- image: cimg/rust:1.76
resource_class: xlarge
steps:
- attach_workspace:
at: /home/circleci/project/
- run:
name: leo new
command: |
export LEO=/home/circleci/project/project/bin/leo
timeout 30m ./project/.circleci/leo-new.sh
leo-clean:
docker:
- image: cimg/rust:1.76
resource_class: xlarge
steps:
- attach_workspace:
at: /home/circleci/project/
- run:
name: leo clean
command: |
export LEO=/home/circleci/project/project/bin/leo
./project/.circleci/leo-clean.sh
leo-example:
docker:
- image: cimg/rust:1.76
resource_class: xlarge
steps:
- attach_workspace:
at: /home/circleci/project/
- run:
name: leo example
command: |
export LEO=/home/circleci/project/project/bin/leo
./project/.circleci/leo-example.sh
test-examples:
docker:
- image: cimg/rust:1.76
resource_class: xlarge
steps:
- attach_workspace:
at: /home/circleci/project/
- run:
name: test examples example
command: |
export LEO=/home/circleci/project/project/bin/leo
export EXAMPLES=/home/circleci/project/project/examples
./project/.circleci/test-examples.sh
workflows:
version: 2
main-workflow:
jobs:
- check-style
- clippy
- leo-executable
- leo-new:
requires:
- leo-executable
- leo-clean:
requires:
- leo-executable
- leo-example:
requires:
- leo-executable
- test-examples:
requires:
- leo-executable
28 changes: 28 additions & 0 deletions .circleci/leo-clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Create a new Leo program named `foo`.
$LEO new foo || exit
ls -la
cd foo && ls -la

# Run `leo run`.
$LEO run main 0u32 1u32 || exit

# Assert that the 'build' folder exists.
if [ "$(ls -A build)" ]; then
echo "build is not empty"
else
echo "build is empty"
exit 1
fi

# Run `leo clean`
$LEO clean || exit

# Assert that the 'build' folder is empty.
if [ "$(ls -A build)" ]; then
echo "build is not empty"
exit 1
else
echo "build is empty"
exit 0
fi

35 changes: 35 additions & 0 deletions .circleci/leo-example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(
# Create a new Leo lottery example program.
$LEO example lottery || exit
ls -la
cd lottery && ls -la

# Run the script.
chmod +x ./run.sh || exit
export -f leo
./run.sh || exit
)

(
# Create a new Leo tictactoe example program.
$LEO example tictactoe || exit
ls -la
cd tictactoe && ls -la

# Run the script.
chmod +x ./run.sh || exit
export -f leo
./run.sh || exit
)

(
#Create a new Leo token example program.
$LEO example token || exit
ls -la
cd token && ls -la

# Run the script.
chmod +x ./run.sh || exit
export -f leo
./run.sh || exit
)
26 changes: 26 additions & 0 deletions .circleci/leo-new.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

echo "
Step 4: Downloading parameters. This may take a few minutes..."

# Create a new dummy Leo project.
$LEO new dummy || exit
cd dummy || exit

# Attempt to compile the dummy program until it passes.
# This is necessary to ensure that the universal parameters are downloaded.
declare -i DONE

DONE=1

while [ $DONE -ne 0 ]
do
$LEO build
DONE=$?
sleep 0.5
done

# Try to run `leo run`.
$LEO run main 0u32 1u32 || exit

# Remove the dummy program.
cd .. && rm -rf dummy
5 changes: 5 additions & 0 deletions .circleci/lottery/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.env
*.avm
*.prover
*.verifier
outputs/
19 changes: 19 additions & 0 deletions .circleci/lottery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# lottery.aleo

## Run Guide

To run this program, run:
```bash
leo run play

or

./run.sh
```

## Execute Guide

To execute this program, run:
```bash
leo execute play
```
28 changes: 28 additions & 0 deletions .circleci/lottery/build/main.aleo
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
program lottery.aleo;

record Ticket:
owner as address.private;


mapping num_winners:
key as u8.public;
value as u8.public;


function play:
cast self.caller into r0 as Ticket.record;
async play into r1;
output r0 as Ticket.record;
output r1 as lottery.aleo/play.future;

finalize play:
lte block.height 1000u32 into r0;
assert.eq r0 true;
rand.chacha into r1 as boolean;
assert.eq r1 true;
get.or_use num_winners[0u8] 0u8 into r2;
lt r2 5u8 into r3;
assert.eq r3 true;
add r2 1u8 into r4;
set r4 into num_winners[0u8];

6 changes: 6 additions & 0 deletions .circleci/lottery/build/program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"program": "lottery.aleo",
"version": "0.0.0",
"description": "",
"license": "MIT"
}
2 changes: 2 additions & 0 deletions .circleci/lottery/inputs/lottery.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// The program input for lottery/src/main.leo
[play]
1 change: 1 addition & 0 deletions .circleci/lottery/leo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package = []
6 changes: 6 additions & 0 deletions .circleci/lottery/program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"program": "lottery.aleo",
"version": "0.0.0",
"description": "",
"license": "MIT"
}
10 changes: 10 additions & 0 deletions .circleci/lottery/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
# First check that Leo is installed.
if ! command -v leo &> /dev/null
then
echo "leo is not installed."
exit
fi

# Run the lottery example
leo run play || exit
30 changes: 30 additions & 0 deletions .circleci/lottery/src/main.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// The 'lottery' program.
program lottery.aleo {

mapping num_winners: u8 => u8;

record Ticket {
owner: address,
}

async transition play() -> (Ticket, Future) {
let ticket: Ticket = Ticket {
owner: self.caller,
};
return (ticket, finalize_play());
}

async function finalize_play() {
// Check that the lottery has not expired.
assert(block.height <= 1000u32);

// Randomly select whether or not the ticket is a winner.
assert(ChaCha::rand_bool());

// Check that the maximum number of winners have not been reached.
let winners: u8 = num_winners.get_or_use(0u8, 0u8);
assert(winners < 5u8);
num_winners.set(0u8, winners + 1u8);

}
}
Loading

0 comments on commit 81c7ea1

Please sign in to comment.