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

Productionalization updates #51

Merged
merged 58 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
fdbbaaf
new cargo project
piniom Jan 12, 2024
f85b6e3
first tests and build script
piniom Jan 15, 2024
b34f648
test gcd basic
piniom Jan 17, 2024
361e03b
extract verifying key converter
piniom Jan 22, 2024
eb5106f
verify signature tests
piniom Jan 23, 2024
4fe33e0
add a test
piniom Jan 23, 2024
5a20952
move types to mod.rs
piniom Jan 23, 2024
4528b0e
add ecdsa tests
piniom Jan 23, 2024
0cffae1
enable memory inspection
piniom Jan 24, 2024
c9ba75b
expand auth data
piniom Jan 24, 2024
c4a016c
extract test
piniom Jan 25, 2024
cb52146
cargo clippy
piniom Jan 25, 2024
b60452b
change local dependency to the git one
piniom Jan 25, 2024
0377dff
revert assertion removal
piniom Jan 29, 2024
ea105c6
split parser and extractor
piniom Jan 25, 2024
4fcaee7
refactor expand auth data
piniom Jan 25, 2024
db78b40
prelude
piniom Jan 25, 2024
d307cbd
add session folder
piniom Jan 25, 2024
a085f3d
signature proof tests
piniom Jan 25, 2024
da01cc0
signature deserialization
piniom Jan 25, 2024
9732dbf
rename new_ to new
piniom Jan 28, 2024
4df1a2c
session proptests
piniom Jan 31, 2024
4e2b396
move felt strategy to a separate file
piniom Jan 31, 2024
ef9e435
helpers prop test
piniom Jan 31, 2024
68b6d9e
verify ecdsa prop test
piniom Jan 31, 2024
e97befb
cargo fmt
piniom Jan 31, 2024
9694669
verify signature prop test
piniom Jan 31, 2024
9f5349e
expand auth data prop test
piniom Jan 31, 2024
cceaa59
remove python folder
piniom Jan 31, 2024
068a981
remove auth gen tests
piniom Jan 31, 2024
c5ab07c
remove session gen tests
piniom Jan 31, 2024
5da59af
update readme
piniom Jan 31, 2024
2fa4fa7
update args runner version
piniom Feb 27, 2024
d4ed08a
fix compile errors
piniom Feb 26, 2024
d9b1ec8
remove most warnings
piniom Feb 27, 2024
3052b97
fix the failing test by reverting the dependency update
piniom Feb 27, 2024
03144f4
remove more warnings
piniom Feb 27, 2024
0cd0fad
bump tool versions
piniom Feb 27, 2024
2f938f1
remove devnet runner test
piniom Feb 28, 2024
b7fd26b
bump merkle_tree version and update test
piniom Feb 28, 2024
a0789d4
change hashing to reflext alexandria fix
piniom Feb 28, 2024
6da9eaf
use a function from std lib when checking point bounds
piniom Feb 28, 2024
a22e7f6
cargo clippy
piniom Mar 11, 2024
a9f7adf
working with transaction waiter
piniom Mar 11, 2024
d3807b2
rewrite transaction waiter
piniom Mar 11, 2024
8938c95
cargo clippy
piniom Mar 11, 2024
82d90e7
update wasm sleep mechanics and remove features
piniom Mar 11, 2024
c816554
dont include tokio as a dep when building for wasm32
piniom Mar 11, 2024
75aab91
update readme
piniom Mar 11, 2024
7f01886
readme better account-sdk compilation command
piniom Mar 13, 2024
1cab85a
add build script
piniom Mar 13, 2024
1c1942c
update dependencies
piniom Mar 13, 2024
0c7e87e
katana, starknet and abigen update
piniom Mar 15, 2024
410fae6
store the compiled class artifact in the git repo
piniom Mar 17, 2024
a46f3d0
make cargo clippy happy
piniom Mar 18, 2024
88831ae
update readme
piniom Mar 18, 2024
26efc79
Update build script
piniom Mar 18, 2024
16dfdbd
Merge pull request #49 from cartridge-gg/feat/5/6/tweaks
tarrencev Mar 18, 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
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scarb 2.4.3
starknet-foundry 0.14.0
scarb 2.5.4
starknet-foundry 0.18.0
python 3.9.18
dojo 0.4.4
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["crates/account_sdk"]
members = ["crates/account_sdk", "crates/webauthn/tests"]

[workspace.package]
edition = "2021"
Expand All @@ -10,10 +10,10 @@ version = "0.1.0"
anyhow = "1"
async-trait = "0.1"
base64 = "0.21"
cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.1.8", features = [
"abigen-rs",
cainome = { git = "https://github.com/piniom/cainome", tag="v0.2.4-expand", features = [
"abigen-rs", "expand-expr"
] }
cairo-lang-starknet = "2.4"
cairo-lang-starknet = "2.4.0"
futures = "0.3"
lazy_static = "1"
p256 = "0.13"
Expand All @@ -23,12 +23,12 @@ serde = "1"
serde_json = "1"
sha2 = "0.10"
starknet = "0.8"
starknet-crypto = "0.6"
starknet-crypto = "0.6.1"
thiserror = "1"
tokio = { version = "1", features = ["macros"] }
toml = "0.8"
u256-literal = "1"
url = "2"
wasm-bindgen = "0.2"
webauthn-authenticator-rs = { version = "0.4" }
webauthn-rs-proto = "0.4"
account-sdk = { path = "crates/account_sdk" }
tokio = { version = "1", features = ["macros", "time"] }
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ config := --account katana-0 \
# Build files helpers.
build := ./target/dev/cartridge_account_
sierra := .contract_class.json
artifacts := ./target/abi/
compiled := .compiled_contract_class.json
store := ./crates/account_sdk/compiled/

# Contract params for deploy.
test_pubkey = 0x1234
katana_0 = 0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973

generate_artifacts:
scarb --manifest-path ./crates/cartridge_account/Scarb.toml build
mkdir -p ${artifacts}
mkdir -p ${store}

jq .abi ${build}Account${sierra} > ${artifacts}account.abi.json
jq .abi ${build}ERC20${sierra} > ${artifacts}erc20.abi.json
jq . ${build}Account${sierra} > ${store}account${sierra}
jq . ${build}ERC20${sierra} > ${store}erc20${sierra}

cp ${build}Account${compiled} ${store}account${compiled}

deploy-katana:
@set -x; \
Expand Down
57 changes: 25 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ The project consists of several subfolders located in the ```crates``` directory

- **account_sdk** - a rust project to export and test functions for interacting with the custom account contract.
- **cartidge_account** - a cairo project with a custom account contract.
- **test_gen_scripts** - a python library to programatically generate cryptographic cairo tests.
- **webauthn** - cairo components to use in contracts.

The project has a global rust workspace.
Expand All @@ -17,14 +16,33 @@ The project has a global rust workspace.

This is a rust project, that will eventually be compiled to wasm. It's purpose is to export and test functions for interacting with the custom account contract. The testing framework implemented within uses [dojo/katana](https://github.com/dojoengine/dojo) underneath. Each test starts its own katana network, deploys a contract and performs operations on it. Naturally, you must have `katana` installed to run the tests. You can specify the path to the `katana` executable in the `account_sdk/KatanaConfig.toml` file. Note that if you have `dojo` installed and in `PATH` the path can remain simply as `katana`.

### Running the tests

To run the tests you first have to compile (to sierra and casm) the contract in the `cartidge_account` folder:
### Compiling the cairo code

To build rust you first have to compile cairo. Run

```bash
make
```

in the root directory.

### Commiting changes

The compiled account is stored in the git repository in the `crates/account_sdk/compiled/` folder. To make sure that the tests are run against the most reacent version of the code run `make` in the root repository. The `make` command should also be run before commiting any changes to ensure a valid state of the compiled code.

### Building for web assembly

After you've compiled the cairo code you can compile rust to wasm using

```bash
cargo build -p account-sdk --target wasm32-unknown-unknown --release
```

## Running the tests

Note, that to run the tests you first have to [compile](#compiling-the-cairo-code) (to sierra and casm) the contract in the `cartidge_account` folder.

StarkNet Foundry tests:

```bash
Expand All @@ -45,39 +63,14 @@ cargo test

The scarb builds the contract and saves the compiled code in the `cartridge_account/target` folder. The tests then fetch (at compile time) the comipled code and deploy it to the local network. Note that obviously the contract needs to be recompiled for any changes to be applied in the compiled code.

## src
## webauthn

This is a cairo project with backend methods that will allow for various authentication methods in the custom contact.
Written based on [this specification](https://www.w3.org/TR/webauthn/).

### Running the tests

Some of the tests are auto-generated using python scripts.
See the `test_gen_scripts` for details.
The tests in `src/tests/` which end in `_gen_test.cairo` are auto-generated and might be changed by the python script. You can write your tests manually, but make sure the name of the test file doesn't end in `_gen_test.cairo`, and you place the import "`use ...;`" below the auto-generated imports in `src/tests.cairo`.

To run the tests:

```shell
scarb test
```

To again generate the tests:

```shell
python test_gen_scripts/main.py
```

## test_gen_scripts

This is a python library to programatically generate cryptographic cairo tests.

### Python Enviroment

Use pyenv to have specific version of python easily.
We use python3.9

```sh
pip install -r requirements.txt
python test_gen_scripts/main.py
You can run scarb test to run a few hand-written tests inside each ```auth``` and ```session``` crates. The bulk of the tests are located in the ```tests``` directory. These tests are written in rust and use property based testing provided by the [proptest](https://docs.rs/proptest/latest/proptest/) crate and use [cairo args runner](https://github.com/neotheprogramist/cairo-args-runner) to interface with and call cairo functions. To run these tests ```cd``` to the ```crates/webauthn/tests``` directory and run:
```bash
cargo test
```
12 changes: 6 additions & 6 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ edition = "2023_10"
version = "0.1.0"

[workspace.dependencies]
alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria", rev = "085f17c87cf6d168032ef5840c39b8e18012284f" }
alexandria_encoding = { git = "https://github.com/keep-starknet-strange/alexandria", rev = "085f17c87cf6d168032ef5840c39b8e18012284f" }
alexandria_merkle_tree = { git = "https://github.com/keep-starknet-strange/alexandria", rev = "085f17c87cf6d168032ef5840c39b8e18012284f" }
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts", tag = "v0.8.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.14.0" }
starknet = "2.4.3"
alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria", tag="cairo-v2.5.4" }
alexandria_encoding = { git = "https://github.com/keep-starknet-strange/alexandria", tag="cairo-v2.5.4" }
alexandria_merkle_tree = { git = "https://github.com/keep-starknet-strange/alexandria", tag="cairo-v2.5.4" }
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts", tag = "v0.9.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.18.0" }
starknet = "2.5.3"
webauthn_auth = { path = "crates/webauthn/auth" }
webauthn_session = { path = "crates/webauthn/session" }
12 changes: 9 additions & 3 deletions crates/account_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib"]
crate-type = ["lib"]

[dependencies]
anyhow.workspace = true
Expand All @@ -25,10 +25,16 @@ sha2.workspace = true
starknet.workspace = true
starknet-crypto.workspace = true
thiserror.workspace = true
tokio.workspace = true
toml.workspace = true
u256-literal.workspace = true
url.workspace = true
wasm-bindgen.workspace = true
webauthn-authenticator-rs.workspace = true
webauthn-rs-proto.workspace = true

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio.workspace = true

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = "0.3.69"
web-sys = "0.3.69"
wasm-bindgen-futures = "0.4.42"

Large diffs are not rendered by default.

Loading
Loading