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 pow #48

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7073a95
feat: serve worker.js as static file
DefiCake Nov 29, 2023
a38fba1
feat: add pow to worker
DefiCake Dec 1, 2023
4a6a0c4
feat: add POST /session endpoint to create a pow session
DefiCake Dec 1, 2023
c25b63e
chore: apply cargo fmt
DefiCake Dec 1, 2023
6561524
feat: add GET /session endpoint
DefiCake Dec 1, 2023
18eefe9
feat: add difficulty as configurable env var
DefiCake Dec 1, 2023
30b7dc6
chore: apply formatting
DefiCake Dec 1, 2023
9914b9e
docs: add documentation
DefiCake Dec 6, 2023
dbce71a
feat: protect POST session with captcha
DefiCake Dec 6, 2023
39d7d32
feat: state management, start and stop pow
DefiCake Dec 7, 2023
5a64922
refactor: improve pow resolution
DefiCake Dec 7, 2023
7f52a6b
feat: add error control
DefiCake Dec 7, 2023
615962d
chore: temporal disable of validation
DefiCake Dec 7, 2023
47612d3
chore: apply lint and fmt
DefiCake Dec 7, 2023
a977a4c
chore: add a fuel node v0.21 config and document its usage
DefiCake Dec 8, 2023
a65c1b8
feat: add pow validation at POST /dispense
DefiCake Dec 8, 2023
737c00d
chore: apply clippy suggestions
DefiCake Dec 8, 2023
5571e8c
chore: apply cargo fmt
DefiCake Dec 8, 2023
e0d21f0
chore: remove unused code
DefiCake Dec 8, 2023
fef9069
test: fix tests after rebase
DefiCake Mar 5, 2024
46bfb21
refactor: apply cargo fmt
DefiCake Mar 5, 2024
41a93b3
refactor: apply cargo clippy
DefiCake Mar 5, 2024
ad112cc
refactor: apply cargo fmt
DefiCake Mar 5, 2024
e74fd73
feat: stop once pow has found a valid nonce
DefiCake Mar 5, 2024
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
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"singleQuote": false,
"printWidth": 80,
"overrides": [
{
"files": ["**/*.html"],
"options": {
"printWidth": 120
}
}
]
}
63 changes: 63 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ fuel-types = "0.43.0"
fuels-accounts = "0.54.0"
fuels-core = "0.54.0"
handlebars = "4.2"
hex = "0.4.3"
lazy_static = "1.4"
memoize = "0.3.1"
num-bigint = "0.4"
rand = "0.8.5"
reqwest = { version = "0.11", features = ["json", "rustls-tls-webpki-roots"], default-features = false }
secrecy = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
sha2 = "0.10"
sha256 = "1.1.4"
tokio = { version = "1.0", features = ["full"] }
tower = { version = "0.4", features = ["buffer", "limit", "load-shed", "util", "timeout"] }
tower-http = { version = "0.2.5", features = ["cors", "trace", "set-header"] }
tower-http = { version = "0.2.5", features = ["cors", "trace", "set-header", "fs"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }

Expand Down
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
Faucet App
===
# Faucet App

[![build](https://github.com/FuelLabs/faucet/actions/workflows/ci.yml/badge.svg)](https://github.com/FuelLabs/faucet/actions/workflows/ci.yml)
[![discord](https://img.shields.io/badge/chat%20on-discord-orange?&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/xfpK4Pe)

A simple faucet app for dispensing tokens on a fuel network. It uses Google captcha for spam resistance
without requiring any social media based identification.

## Configuration

The faucet makes use of environment variables for configuration.

| Environment Variable | Description |
|----------------------|-------------------------------------------------------------------------|
| RUST_LOG | EnvFilter configuration for adjusting logging granularity. |
| HUMAN_LOGGING | If false, logs will be output as machine readable JSON. |
| CAPTCHA_SECRET | The secret key used for enabling Google captcha authentication. |
| CAPTCHA_KEY | The website key used for enabling Google captcha authentication. |
| WALLET_SECRET_KEY | A hex formatted string of the wallet private key that owns some tokens. |
| FUEL_NODE_URL | The GraphQL endpoint for connecting to fuel-core. |
| Environment Variable | Description |
| -------------------- | ----------------------------------------------------------------------------------------------- |
| RUST_LOG | EnvFilter configuration for adjusting logging granularity. |
| HUMAN_LOGGING | If false, logs will be output as machine readable JSON. |
| CAPTCHA_SECRET | The secret key used for enabling Google captcha authentication. |
| CAPTCHA_KEY | The website key used for enabling Google captcha authentication. |
| WALLET_SECRET_KEY | A hex formatted string of the wallet private key that owns some tokens. |
| FUEL_NODE_URL | The GraphQL endpoint for connecting to fuel-core. |
| PUBLIC_FUEL_NODE_URL | The public GraphQL endpoint for connecting to fuel-core. Ex.: https://node.fuel.network/graphql |
| SERVICE_PORT | The port the service will listen for http connections on. |
| DISPENSE_AMOUNT | Dispense amount on each faucet |
| MIN_GAS_PRICE | The minimum gas price to use in each transfer |
| SERVICE_PORT | The port the service will listen for http connections on. |
| DISPENSE_AMOUNT | Dispense amount on each faucet |
| MIN_GAS_PRICE | The minimum gas price to use in each transfer |
| POW_DIFFICULTY | Number of leading zeroes that a valid proof of work hash must have |

## Build and Run

Expand All @@ -29,3 +31,9 @@ To run locally, assuming environment variables have already been set:
```sh
cargo run
```

You will need a fuel node running. You can run one with the default configuration to make the faucet work:

```sh
fuel-core run --chain ./chain_config.json --db-type in-memory
```
8 changes: 6 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ use std::{env, fs, path::Path};

fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("index.html");
let html_dest_path = Path::new(&out_dir).join("index.html");
let page = include_bytes!("./static/index.html");
let minified = minify_html::minify(page, &Cfg::spec_compliant());
fs::write(dest_path, minified).expect("failed to save minified index page");
fs::write(html_dest_path, minified).expect("failed to save minified index page");

let worker_dest_path = Path::new(&out_dir).join("worker.js");
let worker_script = include_bytes!("./static/worker.js");
fs::write(worker_dest_path, worker_script).expect("failed to save worker script");

println!("cargo:rerun-if-changed=static");
}
160 changes: 160 additions & 0 deletions chain_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"chain_name": "local",
"block_gas_limit": 1000000000,
"initial_state": {
"coins": [
{
"owner": "0x5b96f1d44868f0fec7416a020fa4bbcdb511462e474b8d988f66210fd892468d",
"amount": "0xff00000000000000",
"asset_id": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
]
},
"consensus_parameters": {
"tx_params": {
"max_inputs": 255,
"max_outputs": 255,
"max_witnesses": 255,
"max_gas_per_tx": 100000000,
"max_size": 17825792
},
"predicate_params": {
"max_predicate_length": 1048576,
"max_predicate_data_length": 1048576,
"max_message_data_length": 1048576,
"max_gas_per_predicate": 100000000
},
"script_params": {
"max_script_length": 1048576,
"max_script_data_length": 1048576
},
"contract_params": {
"contract_max_size": 16777216,
"max_storage_slots": 255
},
"fee_params": { "gas_price_factor": 1000000000, "gas_per_byte": 4 },
"chain_id": 0,
"gas_costs": {
"add": 1,
"addi": 1,
"aloc": 1,
"and": 1,
"andi": 1,
"bal": 13,
"bhei": 1,
"bhsh": 1,
"burn": 132,
"cb": 1,
"cfei": 1,
"cfsi": 1,
"croo": 16,
"div": 1,
"divi": 1,
"eck1": 951,
"ecr1": 3000,
"ed19": 3000,
"eq": 1,
"exp": 1,
"expi": 1,
"flag": 1,
"gm": 1,
"gt": 1,
"gtf": 1,
"ji": 1,
"jmp": 1,
"jne": 1,
"jnei": 1,
"jnzi": 1,
"jmpf": 1,
"jmpb": 1,
"jnzf": 1,
"jnzb": 1,
"jnef": 1,
"jneb": 1,
"lb": 1,
"log": 9,
"lt": 1,
"lw": 1,
"mint": 135,
"mlog": 1,
"mod": 1,
"modi": 1,
"move": 1,
"movi": 1,
"mroo": 2,
"mul": 1,
"muli": 1,
"mldv": 1,
"noop": 1,
"not": 1,
"or": 1,
"ori": 1,
"poph": 2,
"popl": 2,
"pshh": 2,
"pshl": 2,
"ret_contract": 13,
"rvrt_contract": 13,
"sb": 1,
"sll": 1,
"slli": 1,
"srl": 1,
"srli": 1,
"srw": 12,
"sub": 1,
"subi": 1,
"sw": 1,
"sww": 67,
"time": 1,
"tr": 105,
"tro": 60,
"wdcm": 1,
"wqcm": 1,
"wdop": 1,
"wqop": 1,
"wdml": 1,
"wqml": 1,
"wddv": 1,
"wqdv": 2,
"wdmd": 3,
"wqmd": 4,
"wdam": 2,
"wqam": 3,
"wdmm": 3,
"wqmm": 3,
"xor": 1,
"xori": 1,
"call": { "LightOperation": { "base": 144, "units_per_gas": 214 } },
"ccp": { "LightOperation": { "base": 15, "units_per_gas": 103 } },
"csiz": { "LightOperation": { "base": 17, "units_per_gas": 790 } },
"k256": { "LightOperation": { "base": 11, "units_per_gas": 214 } },
"ldc": { "LightOperation": { "base": 15, "units_per_gas": 272 } },
"logd": { "LightOperation": { "base": 26, "units_per_gas": 64 } },
"mcl": { "LightOperation": { "base": 1, "units_per_gas": 3333 } },
"mcli": { "LightOperation": { "base": 1, "units_per_gas": 3333 } },
"mcp": { "LightOperation": { "base": 1, "units_per_gas": 2000 } },
"mcpi": { "LightOperation": { "base": 3, "units_per_gas": 2000 } },
"meq": { "LightOperation": { "base": 1, "units_per_gas": 2500 } },
"retd_contract": {
"LightOperation": { "base": 29, "units_per_gas": 62 }
},
"s256": { "LightOperation": { "base": 2, "units_per_gas": 214 } },
"scwq": { "LightOperation": { "base": 13, "units_per_gas": 5 } },
"smo": { "LightOperation": { "base": 209, "units_per_gas": 55 } },
"srwq": { "LightOperation": { "base": 47, "units_per_gas": 5 } },
"swwq": { "LightOperation": { "base": 44, "units_per_gas": 5 } },
"contract_root": { "LightOperation": { "base": 75, "units_per_gas": 1 } },
"state_root": { "LightOperation": { "base": 412, "units_per_gas": 1 } },
"new_storage_per_byte": 1,
"vm_initialization": {
"HeavyOperation": { "base": 2000, "gas_per_unit": 0 }
}
},
"base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000"
},
"consensus": {
"PoA": {
"signing_key": "22ec92c3105c942a6640bdc4e4907286ec4728e8cfc0d8ac59aad4d8e1ccaefb"
}
}
}
Loading
Loading