Skip to content

Instantly share code, notes, and snippets.

View a-moreira's full-sized avatar

Arthur Franco a-moreira

View GitHub Profile
@a-moreira
a-moreira / merkle.rs
Created November 21, 2023 15:43
A minimal Merkle tree implementation with proof checking
//! This is minimal Merkle tree implementation with proof checking
use std::{
collections::hash_map::DefaultHasher,
hash::{Hash, Hasher},
};
/// We'll use Rust's built-in hashing which returns a u64 type.
/// This alias just helps us understand when we're treating the number as a hash
type HashValue = u64;
@a-moreira
a-moreira / no_std-guide.md
Created February 26, 2023 05:45 — forked from tdelabro/no_std-guide.md
How to easely port a crate to `no_std`?

What is Rust's standard library?

One of the Rust programming language promises is "zero-cost abstraction". Therefore the language itself is pretty conservative about what it incorporates. Types that are basics in other languages, such as string, or features, such as async, cannot be part of the language itself because they are costly abstractions. The user may not need them at all, or he may prefer other alternative implementations. To make those types and functions available nonetheless, they are available as part of the Rust standard library, known as std. Part of this library, known as the prelude is imported by default in each .rs file so you don't have to repeat yourself too much.

Why would you want a no_std version of your crate?

Most of the time having this standard library available is not a problem because you run your code on a pretty standard environment: your own computer or a Linux server somewhere in the cloud. However, somet

@a-moreira
a-moreira / Lottery.sol
Last active May 9, 2021 18:39
simple Lottery prototype in Solidity
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
contract Lottery {
struct lotteryPot { // to be sent to Compound ?
uint256 amount;
address[] ticketOwners;
}
uint256 ticketPrice = 1000000000000000000; // 1 ETH == 1e18 Wei
uint256 public totalTickets = 100;