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

few updates #159

Merged
merged 79 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
73fce2f
merged files
Orland0x May 10, 2022
487d963
merged space from develop
Orland0x May 10, 2022
1e826de
updated tests
Orland0x May 11, 2022
ccc1515
single slot test with slot key verif
Orland0x May 11, 2022
dcd9914
formatting
Orland0x May 11, 2022
0170b1e
fixed more tests
Orland0x May 12, 2022
7441f0f
fixed more tests
Orland0x May 12, 2022
59d2ca0
single slot strategy added
Orland0x May 13, 2022
cc91a0d
merged quorum stuff
Orland0x May 13, 2022
51784ac
merged quorum stuff
Orland0x May 13, 2022
94d8501
revamped create proposal
Orland0x May 17, 2022
dd68dfb
fixed create vote
Orland0x May 17, 2022
7f02c23
updated eth tx auth
Orland0x May 18, 2022
d4400dc
zodiac test fixes
Orland0x May 18, 2022
63fb02b
zodiac test revamp
Orland0x May 19, 2022
1106d7d
updates
Orland0x May 20, 2022
37301d8
zodiac updates
Orland0x May 22, 2022
eaa6cde
fixed single slot proof strat test
Orland0x May 24, 2022
3443d3c
Update README.md
Orland0x May 24, 2022
300ed55
Update README.md
Orland0x May 24, 2022
27d9beb
fixed controller test
Orland0x May 24, 2022
a8760d1
fixed executor whitelist test
Orland0x May 24, 2022
af5c532
fixed whitelist voting strategytest
Orland0x May 24, 2022
8b02961
fixed merge conflicts
Orland0x May 24, 2022
b45a11b
more merge fixes
Orland0x May 24, 2022
6400a1b
fix l1 tests
Orland0x May 25, 2022
23f4108
Delete vanilla_space.ts
Orland0x May 25, 2022
a02c3bd
Delete vanilla_authenticator.ts
Orland0x May 25, 2022
d9b8619
replaced hardcoded vals with random ones in tests
Orland0x May 25, 2022
ed6f8a5
Merge branch 'revamp_tests' of https://github.com/snapshot-labs/sx-co…
Orland0x May 25, 2022
7421f19
increased timeout
Orland0x May 25, 2022
8d5fb73
OZ naming convention
Orland0x May 25, 2022
1352c11
OZ naming convention
Orland0x May 25, 2022
7c77e22
Delete vanilla.cairo
Orland0x May 25, 2022
e792671
Delete whitelist.cairo
Orland0x May 25, 2022
21a6098
Delete vanilla.cairo
Orland0x May 25, 2022
ad38925
Delete vanilla.cairo
Orland0x May 25, 2022
4b05e99
Delete test_words.cairo
Orland0x May 25, 2022
02bc63d
Delete test_array2d.cairo
Orland0x May 25, 2022
e5c2b97
Delete space.cairo
Orland0x May 26, 2022
5fa8803
Update README.md
Orland0x May 26, 2022
488a863
Update README.md
Orland0x May 26, 2022
3f9635e
removed excess imports
Orland0x May 26, 2022
e524317
Delete contracts/starknet/authenticators directory
Orland0x May 26, 2022
06de52c
Delete contracts/starknet/interfaces directory
Orland0x May 26, 2022
d856f47
GA tests (#153)
Orland0x May 27, 2022
9dac04b
merge
Orland0x May 27, 2022
a408138
Update tests.yml
Orland0x May 27, 2022
ab4e117
Delete contracts/starknet/authenticators directory
Orland0x May 27, 2022
a105e5e
Delete starknet_sig.cairo
Orland0x May 27, 2022
37d5f3a
Delete starknet_tx.cairo
Orland0x May 27, 2022
3998273
Delete eth_tx_auth.ts
Orland0x May 27, 2022
e52e9e0
Delete zodiac.ts
Orland0x May 27, 2022
d6c8d30
Delete executor_whitelist.ts
Orland0x May 27, 2022
6ce9682
Delete starknet_tx_auth.ts
Orland0x May 27, 2022
89e16b8
Delete vanilla_authenticator.ts
Orland0x May 27, 2022
7df1c96
Delete test/starknet/shared directory
Orland0x May 27, 2022
8a98927
updated Stark Tx auth test
Orland0x May 27, 2022
6dfa4a3
use lite mode for devnet
Orland0x May 27, 2022
ad682bb
add timeout for array 2d test
Orland0x May 27, 2022
f131271
increased timeouts
Orland0x May 27, 2022
952f349
fixed zodiac test
Orland0x May 30, 2022
d71c8c7
fixed zodiac module test
Orland0x May 30, 2022
f55d724
fixed hex equivlance issue
Orland0x May 30, 2022
ba863a0
Bump @types/node from 17.0.35 to 17.0.36 (#156) (#158)
Orland0x May 30, 2022
99637d0
use general address type
Orland0x May 30, 2022
d1332a4
Merge branch 'generalize_addresses' of https://github.com/snapshot-la…
Orland0x May 30, 2022
f9a3617
updated starknet tx auth test
Orland0x May 30, 2022
7bfc12c
use felt to uint256 from cairo common
Orland0x May 31, 2022
cfad2a3
updated setup
Orland0x May 31, 2022
c33da68
deployment script
Orland0x Jun 1, 2022
a70396b
fixed merge conflicts
Orland0x Jun 1, 2022
efd1010
formatting
Orland0x Jun 1, 2022
70a1836
fixd vuln with execute import
Orland0x Jun 1, 2022
fff98d7
added deployment script to package.json
Orland0x Jun 1, 2022
21227d2
updated readme
Orland0x Jun 1, 2022
468f9ef
automatic formatting for deployments json
Orland0x Jun 8, 2022
5aa0281
Merge branch 'develop' into generalize_addresses
Orland0x Jun 13, 2022
79bada3
Update README.md
Orland0x Jun 13, 2022
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
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ contracts
│ │ ├─ array2d.cairo — "For handling 2 dimensional arrays"
│ │ ├─ choice.cairo — "The set of choices one can make for a vote"
│ │ ├─ eth_address.cairo — "Ethereum address type"
│ │ ├─ felt_to_uint256.cairo — "Convert a felt to a uint256"
│ │ ├─ hash_array.cairo — "Wrapper function for pedersen hashing arrays"
│ │ ├─ proposal.cairo — "Proposal metadata type"
│ │ ├─ proposal_info.cairo — "Proposal vote data type"
Expand All @@ -43,17 +42,16 @@ contracts
│ └─ Space.cairo - "The core contract for Snapshot X"
└─ ethereum
├─ Interfaces
│ └─ IStarknetCore.sol — "Authenticate user via an Ethereum transaction"
│ └─ IStarknetCore.sol — "Interface of the StarkNet core contract"
├─ StarkNetCommit
│ └─ StarknetCommit.sol — "Authenticate user via an Ethereum transaction"
│ └─ StarknetCommit.sol — "Commits a hash to StarkNet required for Ethereum transaction authentication"
├─ ZodiacModule
│ ├─ ProposalRelayer.sol — "Authenticate user via an Ethereum transaction"
│ ├─ SnapshotXL1Executor.sol — "Authenticate user via an Ethereum transaction"
│ └─ deps.sol — "No authentication of users"
│ ├─ ProposalRelayer.sol — "Provides functionality for recieving proposal data from StarkNet"
│ └─ SnapshotXL1Executor.sol — "Execute proposal transactions using a Gnosis Safe"
└─ TestContracts
├─ MockStarknetMessaging.sol — "Authenticate user via an Ethereum transaction"
├─ NamedStorage.sol — "Authenticate user via an Ethereum transaction"
└─ StarknetMessaging.sol — "No authentication of users"
├─ MockStarknetMessaging.sol — "Mock StarkNet core contract for testing purposes"
├─ NamedStorage.sol — "Storage library"
└─ StarknetMessaging.sol — "StarkNet core contract"

```

Expand Down Expand Up @@ -84,6 +82,13 @@ yarn compile
# or yarn compile:l2 to just compile cairo contracts
```

### Deploy to Alpha Goerli:

```bash
yarn deploy:goerli
```
Will deploy an example space contract and a set of authenticators, voting strategies and execution strategies to the alpha goerli testnet.

### Testing

Tests are separated into three categories:
Expand Down
1 change: 0 additions & 1 deletion contracts/starknet/Authenticators/StarkSig.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
%lang starknet

from contracts.starknet.lib.execute import execute
from contracts.starknet.lib.felt_to_uint256 import felt_to_uint256
from starkware.starknet.common.syscalls import get_caller_address
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin
from starkware.cairo.common.math import assert_not_zero
Expand Down
1 change: 0 additions & 1 deletion contracts/starknet/Authenticators/StarkTx.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
%lang starknet
from contracts.starknet.lib.execute import execute
from contracts.starknet.lib.felt_to_uint256 import felt_to_uint256
from starkware.starknet.common.syscalls import get_caller_address
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin
from starkware.cairo.common.uint256 import uint256_eq
Expand Down
2 changes: 0 additions & 2 deletions contracts/starknet/Authenticators/Vanilla.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ from contracts.starknet.lib.execute import execute
func authenticate{syscall_ptr : felt*, range_check_ptr}(
target : felt, function_selector : felt, calldata_len : felt, calldata : felt*
) -> ():
# TODO: Actually verify the signature

# Call the contract
execute(target, function_selector, calldata_len, calldata)

Expand Down
4 changes: 2 additions & 2 deletions contracts/starknet/Interfaces/IVotingStrategy.cairo
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
%lang starknet

from contracts.starknet.lib.eth_address import EthAddress
from contracts.starknet.lib.general_address import Address
from starkware.cairo.common.uint256 import Uint256

@contract_interface
namespace IVotingStrategy:
func get_voting_power(
block : felt,
voter_address : EthAddress,
voter_address : Address,
params_len : felt,
params : felt*,
user_params_len : felt,
Expand Down
16 changes: 8 additions & 8 deletions contracts/starknet/Space.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ from starkware.cairo.common.math import (

from contracts.starknet.Interfaces.IVotingStrategy import IVotingStrategy
from contracts.starknet.Interfaces.IExecutionStrategy import IExecutionStrategy
from contracts.starknet.lib.eth_address import EthAddress
from contracts.starknet.lib.general_address import Address
from contracts.starknet.lib.proposal import Proposal
from contracts.starknet.lib.proposal_info import ProposalInfo
from contracts.starknet.lib.vote import Vote
Expand Down Expand Up @@ -88,7 +88,7 @@ func executed_proposals_store(proposal_id : felt) -> (executed : felt):
end

@storage_var
func vote_registry_store(proposal_id : felt, voter_address : EthAddress) -> (vote : Vote):
func vote_registry_store(proposal_id : felt, voter_address : Address) -> (vote : Vote):
end

@storage_var
Expand All @@ -102,7 +102,7 @@ end
@event
func proposal_created(
proposal_id : felt,
proposer_address : EthAddress,
proposer_address : Address,
proposal : Proposal,
metadata_uri_len : felt,
metadata_uri : felt*,
Expand All @@ -112,7 +112,7 @@ func proposal_created(
end

@event
func vote_created(proposal_id : felt, voter_address : EthAddress, vote : Vote):
func vote_created(proposal_id : felt, voter_address : Address, vote : Vote):
end

@event
Expand Down Expand Up @@ -392,7 +392,7 @@ end
# TODO: In the future we will need to transition to an array of `voter_address` because they might be different for different voting strategies.
func get_cumulative_voting_power{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
current_timestamp : felt,
voter_address : EthAddress,
voter_address : Address,
used_voting_strategies_len : felt,
used_voting_strategies : felt*,
user_voting_strategy_params_all : Immutable2DArray,
Expand Down Expand Up @@ -660,7 +660,7 @@ end

@external
func vote{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr : felt}(
voter_address : EthAddress,
voter_address : Address,
proposal_id : felt,
choice : felt,
used_voting_strategies_len : felt,
Expand Down Expand Up @@ -744,7 +744,7 @@ end

@external
func propose{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr : felt}(
proposer_address : EthAddress,
proposer_address : Address,
execution_hash : Uint256,
metadata_uri_len : felt,
metadata_uri : felt*,
Expand Down Expand Up @@ -988,7 +988,7 @@ end

@view
func get_vote_info{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr : felt}(
voter_address : EthAddress, proposal_id : felt
voter_address : Address, proposal_id : felt
) -> (vote : Vote):
return vote_registry_store.read(proposal_id, voter_address)
end
Expand Down
4 changes: 2 additions & 2 deletions contracts/starknet/VotingStrategies/SingleSlotProof.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from starkware.cairo.common.uint256 import Uint256, uint256_add
from starkware.cairo.common.math import unsigned_div_rem, assert_nn_le

from contracts.starknet.fossil.contracts.starknet.types import StorageSlot
from contracts.starknet.lib.eth_address import EthAddress
from contracts.starknet.lib.general_address import Address
from contracts.starknet.lib.slot_key import get_slot_key
from contracts.starknet.lib.words import words_to_uint256

Expand Down Expand Up @@ -44,7 +44,7 @@ func get_voting_power{
syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr, bitwise_ptr : BitwiseBuiltin*
}(
block : felt,
voter_address : EthAddress,
voter_address : Address,
params_len : felt,
params : felt*,
user_params_len : felt,
Expand Down
4 changes: 2 additions & 2 deletions contracts/starknet/VotingStrategies/Vanilla.cairo
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
%lang starknet

from starkware.cairo.common.uint256 import Uint256
from contracts.starknet.lib.eth_address import EthAddress
from contracts.starknet.lib.general_address import Address

# Returns a voting power of 1 for every address it is queried with.
@view
func get_voting_power{range_check_ptr}(
block : felt,
voter_address : EthAddress,
voter_address : Address,
params_len : felt,
params : felt*,
user_params_len : felt,
Expand Down
10 changes: 5 additions & 5 deletions contracts/starknet/VotingStrategies/Whitelist.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from starkware.cairo.common.uint256 import Uint256, uint256_check
from starkware.cairo.common.cairo_builtins import HashBuiltin
from contracts.starknet.lib.eth_address import EthAddress
from contracts.starknet.lib.general_address import Address

@storage_var
func whitelist(address : EthAddress) -> (voting_power : Uint256):
func whitelist(address : Address) -> (voting_power : Uint256):
end

@event
func whitelisted(address : EthAddress, voting_power : Uint256):
func whitelisted(address : Address, voting_power : Uint256):
end

func register_whitelist{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr : felt}(
Expand All @@ -18,7 +18,7 @@ func register_whitelist{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_
if _whitelist_len == 0:
return ()
else:
let address = EthAddress(_whitelist[0])
let address = Address(_whitelist[0])
# Add it to the whitelist
let voting_power = Uint256(_whitelist[1], _whitelist[2])

Expand Down Expand Up @@ -47,7 +47,7 @@ end
@view
func get_voting_power{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr : felt}(
block : felt,
voter_address : EthAddress,
voter_address : Address,
params_len : felt,
params : felt*,
user_params_len : felt,
Expand Down
2 changes: 0 additions & 2 deletions contracts/starknet/lib/execute.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
%lang starknet
from starkware.starknet.common.syscalls import call_contract

# Forwards `data` to `target` without verifying anything.
@external
func execute{syscall_ptr : felt*, range_check_ptr}(
target : felt, function_selector : felt, calldata_len : felt, calldata : felt*
) -> ():
Expand Down
23 changes: 0 additions & 23 deletions contracts/starknet/lib/felt_to_uint256.cairo

This file was deleted.

4 changes: 4 additions & 0 deletions contracts/starknet/lib/general_address.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generalized type used to represent addresses in Snapshot X. Eg Ethereum, Starknet, etc.
struct Address:
member value : felt
end
Comment on lines +1 to +4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be called lib/address ? I find it odd to have a filename be general_address and the actual object be Address ?

Copy link
Contributor Author

@Orland0x Orland0x Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm yeah its not ideal, just thought that people would assume its a Starknet address if its called address.cairo

1 change: 0 additions & 1 deletion contracts/starknet/lib/proposal.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from contracts.starknet.lib.eth_address import EthAddress
from starkware.cairo.common.uint256 import Uint256

struct Proposal:
Expand Down
23 changes: 9 additions & 14 deletions contracts/starknet/lib/slot_key.cairo
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.keccak import unsafe_keccak
from starkware.cairo.common.uint256 import Uint256
from starknet.lib.felt_to_uint256 import felt_to_uint256
from starkware.cairo.common.math import split_felt

# Returns the EVM slot key for mappings (key can be any value type)
# For more information, refer to the following repo:
# https://github.com/snapshot-labs/evm-slot-key-verification
# UNSAFE: This is not safe to use in production code due to unsafe keccak - waiting for safe version
func get_slot_key{bitwise_ptr : BitwiseBuiltin*, range_check_ptr}(
slot_index : felt, mapping_key : felt
) -> (slot_key : Uint256):
func get_slot_key{range_check_ptr}(slot_index : felt, mapping_key : felt) -> (slot_key : Uint256):
alloc_locals
let (encoded_array : felt*) = alloc()
let (slot_index_uint256) = felt_to_uint256(slot_index)
let (mapping_key_uint256) = felt_to_uint256(mapping_key)
encoded_array[0] = mapping_key_uint256.high
encoded_array[1] = mapping_key_uint256.low
encoded_array[2] = slot_index_uint256.high
encoded_array[3] = slot_index_uint256.low
let (low, high) = unsafe_keccak(encoded_array, 16 * 4)
let (slot_index_high, slot_index_low) = split_felt(slot_index)
let (mapping_key_high, mapping_key_low) = split_felt(mapping_key)
encoded_array[0] = mapping_key_high
encoded_array[1] = mapping_key_low
encoded_array[2] = slot_index_high
encoded_array[3] = slot_index_low
let (low, high) = unsafe_keccak(encoded_array, 64)
let slot_key = Uint256(low=low, high=high)
return (slot_key)
end
1 change: 0 additions & 1 deletion contracts/starknet/lib/vote.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
%lang starknet

from contracts.starknet.lib.eth_address import EthAddress
from starkware.cairo.common.uint256 import Uint256

struct Vote:
Expand Down
9 changes: 0 additions & 9 deletions deployments/goerli.json

This file was deleted.

33 changes: 33 additions & 0 deletions deployments/goerli1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"space": {
"address": "0x56f0102b537fae4a9f94c362473d7f03025e92af246502074d9f204c027058b",
"authenticators": {
"StarkTx": "0x327d3a82cf938e7dcef065db5d3f4c40d2b495b27912e352817cf3da41643f9",
"Vanilla": "0x28511c7039691e7298c92b753e28d79ebf8253acc0fa508bb159dd12adea0b6"
},
"controller": "0x0070d911463b2cb48de8bfec826483631cdc492a6c5798917651297769fc9d68",
"executionStrategies": {
"Vanilla": "0x5d4a61e5ea572b1e956c19ca76678336c2e0472a7988b0b5979fa18719b5652",
"zodiacRelayer": "0x5c512fbf7f4dc97bd2a68e7096968ce8ecd65d42583cbacaf3fdcc7a1800f80"
},
"maxVotingDuration": "0x7d0",
"minVotingDuration": "0x0",
"name": "Test space",
"proposalThreshold": "0x1",
"quorum": "0x1",
"votingStrategies": {
"SingleSlotProof": {
"address": "0x78f994cdf794bebd68027ef9e2ee0bf309983d87755efb4f5bded8d26980514",
"parameters": [
"0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9",
"0x0"
]
},
"Vanilla": {
"address": "0x61b900e2c3b8beb266e1fe9abe837a9b8276cac39509b3b25ad10a20767763a",
"parameters": [
]
}
}
}
}
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"test:l2:ci": "concurrently './scripts/chain-l2.sh' './scripts/test-l2.sh'",
"test:crosschain": "'./scripts/test-crosschain.sh'",
"test:crosschain:ci": "concurrently './scripts/chain.sh' './scripts/test-crosschain.sh'",
"deploy:goerli": "yarn hardhat run ./scripts/deployTestSpace.ts",
"chain:l1": "hardhat node",
"chain:l2": "starknet-devnet -p 8000 --lite-mode",
"chain": "concurrently 'yarn chain:l1' 'yarn chain:l2'",
Expand All @@ -22,7 +23,8 @@
"check-format:l2": "cairo-format -c --one_item_per_line contracts/starknet/**/*.cairo && cairo-format -c --one_item_per_line contracts/starknet/*.cairo",
"format:ts": "eslint . --ext .ts --fix",
"check-format:ts": "eslint . --ext .ts",
"format": "yarn format:l1 && yarn format:l2 && yarn format:ts",
"format:json": "json-format ./deployments/*.json",
"format": "yarn format:l1 && yarn format:l2 && yarn format:ts && yarn format:json",
"check-format": "yarn check-format:l1 && yarn check-format:l2 && yarn check-format:ts"
},
"dependencies": {
Expand All @@ -32,8 +34,10 @@
"concurrently": "^7.2.1",
"ethereumjs-util": "^7.1.5",
"install": "^0.13.0",
"npm": "^8.12.1",
"starknet": "^2.5.1",
"json-format-cli": "^1.1.1",
"npm": "^8.11.0",
"prettyjson": "^1.2.5",
"starknet": "^3.9.0",
"sx-api": "snapshot-labs/sx-api",
"wait-on": "^6.0.1",
"yargs": "^17.5.0"
Expand Down
Loading