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

feat: session key authentication #607

Open
wants to merge 41 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
cbb8539
feat: session key authenticator interfaces
Mar 14, 2024
a423df4
feat: session key base library
Mar 14, 2024
9f5b355
feat: session key core logic impl
Mar 25, 2024
bb7a297
feat: eth sig session key propose no sig verification
Mar 25, 2024
fdb2c76
feat: session key eip712 sig verification
Mar 27, 2024
46570f1
fix: added salt to session key eip712 sigs
Mar 28, 2024
8044beb
fix: added owner check on session revoke
Mar 28, 2024
2517653
feat: authorize and revoke with owner sig entry points
Mar 28, 2024
af55414
feat: session key sig verification
Apr 4, 2024
c905369
feat: added session key sig verification to propose
Apr 4, 2024
25bd3fc
feat: verify revoke session via session signature
Apr 4, 2024
555563e
feat: revoke session via signature
Apr 4, 2024
c75e20d
feat: authenticate vote and update proposal via eth sig session key
Apr 11, 2024
741445c
feat: eth tx session key authenticator
Apr 11, 2024
aa541ad
refactor: moved all duplicated code in session key lib
Apr 11, 2024
93f7cf7
feat: stark sig and tx session key functionality
Apr 18, 2024
66e5646
feat: stark sig session key auth entry points
Apr 18, 2024
c609d30
feat: stark tx session key auth entry points
Apr 18, 2024
c9c7471
chore: delete mock file
Orland0x Apr 19, 2024
31001ce
feat: session key eip712 typehashes
Apr 25, 2024
d123e45
feat: session key eip712 types
Apr 25, 2024
dce5363
chore: eth sig session key test base
Apr 25, 2024
f5e53e2
chore: added script to package.json
Apr 25, 2024
64beec1
chore: revoke with session sig ts types
May 8, 2024
a1cb0d3
chore: test all entrypoints on eth sig session key
May 8, 2024
1f41dc4
chore: remove commented tests
May 8, 2024
2c31882
feat: UserAddress Into felt impl
May 15, 2024
ab985e7
feat: stark sig session key typehashes
May 15, 2024
6504cc0
chore: invalid sig testing eth sig sk auth
May 15, 2024
c5f1f0c
fix: typos
May 15, 2024
0c25649
chore: eth tx sk auth test
May 15, 2024
b89bd4b
feat: session key auth typehash strk
May 29, 2024
8c09072
fix: typehashes
May 29, 2024
67fff81
chore: stark sig sk test
May 29, 2024
38f9213
chore: actually use invalid signer in eth sig sk test
May 29, 2024
d7de3a1
chore: formatting
May 30, 2024
ff716fe
feat: constructor for stark tx sk auth
May 30, 2024
a7dffd2
chore: stark tx sk test
May 30, 2024
3df1f8a
chore: add tests to CI
May 30, 2024
167422d
chore all all sk tests to CI
May 30, 2024
7a7d853
Merge branch 'develop' into feat_session_key_authentication
Orland0x May 30, 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
10 changes: 6 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: SX-Starknet Workflow
env:
STARKNET_SIERRA_COMPILE_PATH: ./cairo/bin/starknet-sierra-compile
OBJC_DISABLE_INITIALIZE_FORK_SAFETY: YES
ADDRESS: "0x347be35996a21f6bf0623e75dbce52baba918ad5ae8d83b6f416045ab22961a"
PUBLIC_KEY: "0x674efe292c3c1125108916d6128bd6d1db4528db07322a84177551067aa2bef"
PK: "0xbdd640fb06671ad11c80317fa3b1799d"
ADDRESS: '0x347be35996a21f6bf0623e75dbce52baba918ad5ae8d83b6f416045ab22961a'
PUBLIC_KEY: '0x674efe292c3c1125108916d6128bd6d1db4528db07322a84177551067aa2bef'
PK: '0xbdd640fb06671ad11c80317fa3b1799d'

on:
push:
Expand Down Expand Up @@ -116,4 +116,6 @@ jobs:
run: yarn hardhat starknet-build

- name: run Hardhat tests
run: yarn test:l1-execution; yarn test:eth-sig-auth; yarn test:stark-sig-auth; yarn test:eth-tx-auth
run:
yarn test:l1-execution; yarn test:eth-sig-auth; yarn test:stark-sig-auth; yarn test:eth-tx-auth;
yarn test:eth-sig-sk-auth; yarn test:stark-sig-sk-auth; yarn test:eth-tx-sk-auth; yarn test:stark-tx-sk-auth
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"test:stark-sig-auth": "bash './scripts/stark-sig-auth-test.sh'",
"test:eth-sig-auth": "bash './scripts/eth-sig-auth-test.sh'",
"test:eth-tx-auth": "bash './scripts/eth-tx-auth-test.sh'",
"test:eth-sig-sk-auth": "bash './scripts/eth-sig-sk-auth-test.sh'",
"test:eth-tx-sk-auth": "bash './scripts/eth-tx-sk-auth-test.sh'",
"test:stark-sig-sk-auth": "bash './scripts/stark-sig-sk-auth-test.sh'",
"test:stark-tx-sk-auth": "bash './scripts/stark-tx-sk-auth-test.sh'",
"test:l1-execution": "bash './scripts/l1-avatar-execution-test.sh'"
},
"devDependencies": {
Expand Down
15 changes: 15 additions & 0 deletions scripts/eth-sig-sk-auth-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

kill -9 $(lsof -t -i:5050)
yarn chain:l2 &
sleep 10 &&
yarn hardhat test tests/eth-sig-sk-auth.test.ts
if [ $? -eq 0 ]
then
kill -9 $(lsof -t -i:5050)
exit 0
else
kill -9 $(lsof -t -i:5050)
echo "Tests failed"
exit 1
fi
18 changes: 18 additions & 0 deletions scripts/eth-tx-sk-auth-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

kill -9 $(lsof -t -i:8545)
kill -9 $(lsof -t -i:5050)
yarn chain &
sleep 10 &&
yarn hardhat test tests/eth-tx-sk-auth.test.ts --network 'ethereumLocal' --starknet-network 'starknetLocal'
if [ $? -eq 0 ]
then
kill -9 $(lsof -t -i:8545)
kill -9 $(lsof -t -i:5050)
exit 0
else
kill -9 $(lsof -t -i:8545)
kill -9 $(lsof -t -i:5050)
echo "Tests failed"
exit 1
fi
15 changes: 15 additions & 0 deletions scripts/stark-sig-sk-auth-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

kill -9 $(lsof -t -i:5050)
yarn chain:l2 &
sleep 10 &&
yarn hardhat test tests/stark-sig-sk-auth.test.ts
if [ $? -eq 0 ]
then
kill -9 $(lsof -t -i:5050)
exit 0
else
kill -9 $(lsof -t -i:5050)
echo "Tests failed"
exit 1
fi
15 changes: 15 additions & 0 deletions scripts/stark-tx-sk-auth-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

kill -9 $(lsof -t -i:5050)
yarn chain:l2 &
sleep 10 &&
yarn hardhat test tests/stark-tx-sk-auth.test.ts
if [ $? -eq 0 ]
then
kill -9 $(lsof -t -i:5050)
exit 0
else
kill -9 $(lsof -t -i:5050)
echo "Tests failed"
exit 1
fi
14 changes: 14 additions & 0 deletions starknet/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "openzeppelin"
version = "0.7.0-rc.0"
source = "git+https://github.com/snapshot-labs/openzeppelin-cairo-contracts.git?branch=feat%2Ferc20votes-%23631-frozen#e9d17922f938cc62c7dabaf13d700e7290b7c274"

[[package]]
name = "sx"
version = "0.1.0"
dependencies = [
"openzeppelin",
]
Binary file added starknet/src/.DS_Store
Binary file not shown.
211 changes: 211 additions & 0 deletions starknet/src/authenticators/eth_sig_session_key.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
use starknet::{ContractAddress, EthAddress};
use sx::types::{Strategy, IndexedStrategy, Choice};

#[starknet::interface]
trait IEthSigSessionKeyAuthenticator<TContractState> {
fn authenticate_propose(
ref self: TContractState,
signature: Array<felt252>,
space: ContractAddress,
author: EthAddress,
metadata_uri: Array<felt252>,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
salt: felt252,
session_public_key: felt252
);

fn authenticate_vote(
ref self: TContractState,
signature: Array<felt252>,
space: ContractAddress,
voter: EthAddress,
proposal_id: u256,
choice: Choice,
user_voting_strategies: Array<IndexedStrategy>,
metadata_uri: Array<felt252>,
session_public_key: felt252
);

fn authenticate_update_proposal(
ref self: TContractState,
signature: Array<felt252>,
space: ContractAddress,
author: EthAddress,
proposal_id: u256,
execution_strategy: Strategy,
metadata_uri: Array<felt252>,
salt: felt252,
session_public_key: felt252
);

fn register_with_owner_sig(
ref self: TContractState,
r: u256,
s: u256,
v: u32,
owner: EthAddress,
session_public_key: felt252,
session_duration: u32,
salt: u256,
);

fn revoke_with_owner_sig(
ref self: TContractState,
r: u256,
s: u256,
v: u32,
owner: EthAddress,
session_public_key: felt252,
salt: u256,
);

fn revoke_with_session_key_sig(
ref self: TContractState,
signature: Array<felt252>,
owner: EthAddress,
session_public_key: felt252,
salt: felt252
);
}

#[starknet::contract]
mod EthSigSessionKeyAuthenticator {
use super::IEthSigSessionKeyAuthenticator;
use starknet::{ContractAddress, EthAddress};
use sx::interfaces::{ISpaceDispatcher, ISpaceDispatcherTrait};
use sx::types::{Strategy, IndexedStrategy, Choice, UserAddress};
use sx::utils::{EIP712, SessionKey, LegacyHashEthAddress, LegacyHashUsedSalts, ByteReverse};

#[storage]
struct Storage {}

#[external(v0)]
impl EthSigSessionKeyAuthenticator of IEthSigSessionKeyAuthenticator<ContractState> {
fn authenticate_propose(
ref self: ContractState,
signature: Array<felt252>,
space: ContractAddress,
author: EthAddress,
metadata_uri: Array<felt252>,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
salt: felt252,
session_public_key: felt252
) {
let mut state = SessionKey::unsafe_new_contract_state();
SessionKey::InternalImpl::authenticate_propose(
ref state,
signature,
space,
UserAddress::Ethereum(author),
metadata_uri,
execution_strategy,
user_proposal_validation_params,
salt,
session_public_key
);
}

fn authenticate_vote(
ref self: ContractState,
signature: Array<felt252>,
space: ContractAddress,
voter: EthAddress,
proposal_id: u256,
choice: Choice,
user_voting_strategies: Array<IndexedStrategy>,
metadata_uri: Array<felt252>,
session_public_key: felt252
) {
let mut state = SessionKey::unsafe_new_contract_state();
SessionKey::InternalImpl::authenticate_vote(
ref state,
signature,
space,
UserAddress::Ethereum(voter),
proposal_id,
choice,
user_voting_strategies,
metadata_uri,
session_public_key
);
}

fn authenticate_update_proposal(
ref self: ContractState,
signature: Array<felt252>,
space: ContractAddress,
author: EthAddress,
proposal_id: u256,
execution_strategy: Strategy,
metadata_uri: Array<felt252>,
salt: felt252,
session_public_key: felt252
) {
let mut state = SessionKey::unsafe_new_contract_state();
SessionKey::InternalImpl::authenticate_update_proposal(
ref state,
signature,
space,
UserAddress::Ethereum(author),
proposal_id,
execution_strategy,
metadata_uri,
salt,
session_public_key
);
}


fn register_with_owner_sig(
ref self: ContractState,
r: u256,
s: u256,
v: u32,
owner: EthAddress,
session_public_key: felt252,
session_duration: u32,
salt: u256,
) {
let mut state = SessionKey::unsafe_new_contract_state();
SessionKey::InternalImpl::register_with_owner_eth_sig(
ref state, r, s, v, owner, session_public_key, session_duration, salt
);
}

fn revoke_with_owner_sig(
ref self: ContractState,
r: u256,
s: u256,
v: u32,
owner: EthAddress,
session_public_key: felt252,
salt: u256,
) {
let mut state = SessionKey::unsafe_new_contract_state();
SessionKey::InternalImpl::revoke_with_owner_eth_sig(
ref state, r, s, v, owner, session_public_key, salt
);
}

fn revoke_with_session_key_sig(
ref self: ContractState,
signature: Array<felt252>,
owner: EthAddress,
session_public_key: felt252,
salt: felt252
) {
let mut state = SessionKey::unsafe_new_contract_state();
SessionKey::InternalImpl::revoke_with_session_key_sig(
ref state, signature, UserAddress::Ethereum(owner), session_public_key, salt
);
}
}

#[constructor]
fn constructor(ref self: ContractState, name: felt252, version: felt252,) {
let mut state = SessionKey::unsafe_new_contract_state();
SessionKey::InternalImpl::eth_sig_initializer(ref state, name, version);
}
}
Loading
Loading