Skip to content

Commit

Permalink
few updates (#159)
Browse files Browse the repository at this point in the history
* merged files

* merged space from develop

* updated tests

* single slot test with slot key verif

* formatting

* fixed more tests

* fixed more tests

* single slot strategy added

* merged quorum stuff

* revamped create proposal

* fixed create vote

* updated eth tx auth

* zodiac test fixes

* zodiac test revamp

* updates

* zodiac updates

* fixed single slot proof strat test

* Update README.md

* Update README.md

* fixed controller test

* fixed executor whitelist test

* fixed whitelist voting strategytest

* more merge fixes

* fix l1 tests

* Delete vanilla_space.ts

* Delete vanilla_authenticator.ts

* replaced hardcoded vals with random ones in tests

* increased timeout

* OZ naming convention

* OZ naming convention

* Delete vanilla.cairo

* Delete whitelist.cairo

* Delete vanilla.cairo

* Delete vanilla.cairo

* Delete test_words.cairo

* Delete test_array2d.cairo

* Delete space.cairo

* Update README.md

* Update README.md

* removed excess imports

* Delete contracts/starknet/authenticators directory

* Delete contracts/starknet/interfaces directory

* GA tests (#153)

* Bump ethers from 5.6.7 to 5.6.8 (#147)

Bumps [ethers](https://github.com/ethers-io/ethers.js/tree/HEAD/packages/ethers) from 5.6.7 to 5.6.8.
- [Release notes](https://github.com/ethers-io/ethers.js/releases)
- [Changelog](https://github.com/ethers-io/ethers.js/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ethers-io/ethers.js/commits/v5.6.8/packages/ethers)

---
updated-dependencies:
- dependency-name: ethers
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump typescript from 4.6.4 to 4.7.2 (#146)

Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.6.4 to 4.7.2.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](microsoft/TypeScript@v4.6.4...v4.7.2)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add starknet auth (#138)

* Update  to 0.8.1 and devnet 0.2.1; Format

* Add execute lib; Switch to authenticate method

* Add felt_to_uint256; Add starknet_tx auth

* Use felt instead of u256

* Add test for starknet tx auth

* Add starknet_tx_auth and starknet_account_auth; blocked by compilation on starknet_account_auth

* Remove starknet_account test; Rename starknet_account to starknet_sig

* Add comment about hash

* Update to 0.8.2

* Add voting_strategy_params_all to setup functions

* Bump npm from 8.10.0 to 8.11.0 (#149)

Bumps [npm](https://github.com/npm/cli) from 8.10.0 to 8.11.0.
- [Release notes](https://github.com/npm/cli/releases)
- [Changelog](https://github.com/npm/cli/blob/latest/CHANGELOG.md)
- [Commits](npm/cli@v8.10.0...v8.11.0)

---
updated-dependencies:
- dependency-name: npm
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* renaming tests

* renamed cairo contracts

* fixed starknet tx auth test

* formatting

* updated starknet hardhat

* fixed account import

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: pscott <30843220+pscott@users.noreply.github.com>

* Update tests.yml

* Delete contracts/starknet/authenticators directory

* Delete starknet_sig.cairo

* Delete starknet_tx.cairo

* Delete eth_tx_auth.ts

* Delete zodiac.ts

* Delete executor_whitelist.ts

* Delete starknet_tx_auth.ts

* Delete vanilla_authenticator.ts

* Delete test/starknet/shared directory

* updated Stark Tx auth test

* use lite mode for devnet

* add timeout for array 2d test

* increased timeouts

* fixed zodiac test

* fixed zodiac module test

* fixed hex equivlance issue

* Bump @types/node from 17.0.35 to 17.0.36 (#156) (#158)

Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 17.0.35 to 17.0.36.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* use general address type

* updated starknet tx auth test

* use felt to uint256 from cairo common

* updated setup

* deployment script

* formatting

* fixd vuln with execute import

* added deployment script to package.json

* updated readme

* automatic formatting for deployments json

* Update README.md

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: pscott <30843220+pscott@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 14, 2022
1 parent c42be8a commit 5eccb74
Show file tree
Hide file tree
Showing 29 changed files with 472 additions and 340 deletions.
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
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

0 comments on commit 5eccb74

Please sign in to comment.