Skip to content

Commit

Permalink
Update to scarb 2.6.4 (#620)
Browse files Browse the repository at this point in the history
* update scarb version; use openzeppelin's components; fix failing events in tests

* get tests to work; fix erc20votes deployer serializing error

* update scarb to 2.6.4

* update cairo version

* remove python installation and cairo installation from CI

* remove requirements.txt

* update forge dependencies

* set safe-contracts to v1.4.0

* update solidity libraries and tests

* update openzeppelin hardat-upgrades

* remove test stark-sig-auth
  • Loading branch information
pscott authored Jul 3, 2024
1 parent 2fb4857 commit 1b748c6
Show file tree
Hide file tree
Showing 67 changed files with 481 additions and 680 deletions.
26 changes: 4 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,8 @@ jobs:
- name: Install Yarn dependencies
run: yarn install

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install Python dependencies
run: |
sudo apt install -y libgmp3-dev
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Install Cairo
run: curl -L https://github.com/starkware-libs/cairo/releases/download/v2.2.0/release-x86_64-unknown-linux-musl.tar.gz > cairo.tar.gz

- name: Extract Cairo
run: tar -xvf cairo.tar.gz

- name: Install Scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: 0.7.0
run: curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.6.5

- name: Check Cairo formatting
working-directory: ./starknet
Expand All @@ -115,5 +96,6 @@ jobs:
- name: Compile Cairo contracts for Hardhat tests
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
# - name: run Hardhat tests
# run: yarn test:l1-execution; yarn test:eth-sig-auth; yarn test:stark-sig-auth; yarn test:eth-tx-auth
# we removed the above line because l1 <--> l2 communication is not yet implemented
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ cairo_project.toml

ethereum/broadcast/

artifacts/
starknet-artifacts/
typechain-types/

build/
cache/
out/
Expand Down
3 changes: 2 additions & 1 deletion ethereum/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
src = 'src'
out = 'out'
libs = ['lib']
solc = "0.8.20"
solc = "0.8.24"
evm_version = 'cancun'

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
2 changes: 1 addition & 1 deletion ethereum/lib/openzeppelin-contracts
2 changes: 1 addition & 1 deletion ethereum/lib/openzeppelin-contracts-upgradeable
2 changes: 1 addition & 1 deletion ethereum/lib/zodiac
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ contract L1AvatarExecutionStrategy is SimpleQuorumExecutionStrategy {
uint256[] memory _starknetSpaces,
uint256 _quorum
) public initializer {
__Ownable_init();
transferOwnership(_owner);
__Ownable_init(_owner);
__SpaceManager_init(_starknetSpaces);
__SimpleQuorumExecutionStrategy_init(_quorum);
target = _target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ contract L1AvatarExecutionStrategyMockMessaging is SimpleQuorumExecutionStrategy
uint256[] memory _starknetSpaces,
uint256 _quorum
) public initializer {
__Ownable_init();
transferOwnership(_owner);
__Ownable_init(_owner);
__SpaceManager_init(_starknetSpaces);
__SimpleQuorumExecutionStrategy_init(_quorum);
target = _target;
Expand Down
21 changes: 12 additions & 9 deletions ethereum/test/L1AvatarExecutionStrategy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {L1AvatarExecutionStrategy} from "../src/execution-strategies/L1AvatarExe
import {L1AvatarExecutionStrategyFactory} from "../src/execution-strategies/L1AvatarExecutionStrategyFactory.sol";
import {TRUE, FALSE} from "../src/types.sol";

import {Ownable} from "openzeppelin-contracts/contracts/access/Ownable.sol";
import {Initializable} from "openzeppelin-contracts/contracts/proxy/utils/Initializable.sol";

/// @dev Tests for Setters on the L1 Avatar Execution Strategy
abstract contract L1AvatarExecutionStrategySettersTest is Test {
error InvalidSpace();
Expand Down Expand Up @@ -57,7 +60,7 @@ abstract contract L1AvatarExecutionStrategySettersTest is Test {
function testUnauthorizedSetTarget() public {
address newTarget = address(0xbeef);
vm.prank(unauthorized);
vm.expectRevert("Ownable: caller is not the owner");
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, unauthorized));
avatarExecutionStrategy.setTarget(newTarget);
}

Expand All @@ -73,7 +76,7 @@ abstract contract L1AvatarExecutionStrategySettersTest is Test {
function testUnauthorizedSetStarknetCore() public {
address newStarknetCore = address(0xbeef);
vm.prank(unauthorized);
vm.expectRevert("Ownable: caller is not the owner");
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, unauthorized));
avatarExecutionStrategy.setStarknetCore(newStarknetCore);
}

Expand All @@ -89,7 +92,7 @@ abstract contract L1AvatarExecutionStrategySettersTest is Test {
function testUnauthorizedSetExecutionRelayer() public {
uint256 newExecutionRelayer = 3;
vm.prank(unauthorized);
vm.expectRevert("Ownable: caller is not the owner");
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, unauthorized));
avatarExecutionStrategy.setExecutionRelayer(newExecutionRelayer);
}

Expand All @@ -105,7 +108,7 @@ abstract contract L1AvatarExecutionStrategySettersTest is Test {
function testUnauthorizedSetQuorum() public {
uint256 newQuorum = 3;
vm.prank(unauthorized);
vm.expectRevert("Ownable: caller is not the owner");
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, unauthorized));
avatarExecutionStrategy.setQuorum(newQuorum);
}

Expand All @@ -119,12 +122,12 @@ abstract contract L1AvatarExecutionStrategySettersTest is Test {
function testUnauthorizedTransferOwnership() public {
address newOwner = address(0xbeef);
vm.prank(unauthorized);
vm.expectRevert("Ownable: caller is not the owner");
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, unauthorized));
avatarExecutionStrategy.transferOwnership(newOwner);
}

function testDoubleInitialization() public {
vm.expectRevert("Initializable: contract is already initialized");
vm.expectRevert(Initializable.InvalidInitialization.selector);
address[] memory spaces = new address[](1);
spaces[0] = address(this);

Expand Down Expand Up @@ -159,7 +162,7 @@ abstract contract L1AvatarExecutionStrategySettersTest is Test {
function testUnauthorizedEnableSpace() public {
uint256 space_ = 2;
vm.prank(unauthorized);
vm.expectRevert("Ownable: caller is not the owner");
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, unauthorized));
avatarExecutionStrategy.enableSpace(space_);
}

Expand All @@ -181,11 +184,11 @@ abstract contract L1AvatarExecutionStrategySettersTest is Test {

function testUnauthorizedDisableSpace() public {
vm.prank(unauthorized);
vm.expectRevert("Ownable: caller is not the owner");
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, unauthorized));
avatarExecutionStrategy.disableSpace(space);
}

function testGetStrategyType() external {
function testGetStrategyType() external view {
assertEq(avatarExecutionStrategy.getStrategyType(), "SimpleQuorumL1Avatar");
}
}
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const config: HardhatUserConfig = {
},
},
{
version: '0.8.20',
version: '0.8.24',
settings: {
optimizer: {
enabled: true,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sx",
"version": "1.0.0",
"description": "Cairo 1 implementation of the Snapshot X Protocol",
"repository": "https://github.com/snapshot-labs/sx-starknet-2.git",
"repository": "https://github.com/snapshot-labs/sx-starknet.git",
"author": "Snapshot Labs",
"license": "MIT",
"main": "index.js",
Expand Down Expand Up @@ -38,7 +38,7 @@
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.2.1",
"@openzeppelin/contracts": "^5.0.2",
"@openzeppelin/hardhat-upgrades": "^3.1.0",
"@openzeppelin/hardhat-upgrades": "^3.2.0",
"axios": "^1.5.0",
"chai": "^4.3.7",
"concurrently": "^7.0.0",
Expand Down
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/chain-l2.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
starknet-devnet --seed 42 --verbose --sierra-compiler-path "${STARKNET_SIERRA_COMPILE_PATH}" --compiler-args '--allowed-libfuncs-list-file ./audited_cairo_libfuncs.json --add-pythonic-hints' --lite-mode
starknet-devnet --seed 42
exit 0
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.13.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git#592095f1cc344b50c269252a09626c678342301f"

[[package]]
name = "sx"
version = "0.1.0"
dependencies = [
"openzeppelin",
]
2 changes: 1 addition & 1 deletion starknet/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ casm-add-pythonic-hints = true
build-external-contracts = ["openzeppelin::account::account::Account", "openzeppelin::account::interface::AccountABI"]

[dependencies]
openzeppelin = { git = "https://github.com/snapshot-labs/openzeppelin-cairo-contracts.git", branch = "feat/erc20votes-#631-frozen" }
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", version = "0.13.0" }
starknet = ">=2.2.0"

[scripts]
Expand Down
4 changes: 2 additions & 2 deletions starknet/src/authenticators/eth_sig.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ mod EthSigAuthenticator {
use starknet::{ContractAddress, EthAddress};
use sx::interfaces::{ISpaceDispatcher, ISpaceDispatcherTrait};
use sx::types::{Strategy, IndexedStrategy, Choice, UserAddress};
use sx::utils::{EIP712, LegacyHashEthAddress, LegacyHashUsedSalts, ByteReverse};
use sx::utils::{EIP712, LegacyHashEthAddress, ByteReverse};

#[storage]
struct Storage {
_used_salts: LegacyMap::<(EthAddress, u256), bool>
}

#[external(v0)]
#[abi(embed_v0)]
impl EthSigAuthenticator of IEthSigAuthenticator<ContractState> {
fn authenticate_propose(
ref self: ContractState,
Expand Down
3 changes: 1 addition & 2 deletions starknet/src/authenticators/eth_tx.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ mod EthTxAuthenticator {
use starknet::{ContractAddress, EthAddress, Felt252TryIntoEthAddress, EthAddressIntoFelt252,};
use sx::interfaces::{ISpaceDispatcher, ISpaceDispatcherTrait};
use sx::types::{UserAddress, Strategy, IndexedStrategy, Choice};
use sx::utils::LegacyHashFelt252EthAddress;
use sx::utils::constants::{PROPOSE_SELECTOR, VOTE_SELECTOR, UPDATE_PROPOSAL_SELECTOR};

#[storage]
Expand All @@ -78,7 +77,7 @@ mod EthTxAuthenticator {
_commits: LegacyMap::<(felt252, EthAddress), bool>
}

#[external(v0)]
#[abi(embed_v0)]
impl EthTxAuthenticator of IEthTxAuthenticator<ContractState> {
fn authenticate_propose(
ref self: ContractState,
Expand Down
2 changes: 1 addition & 1 deletion starknet/src/authenticators/stark_sig.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ mod StarkSigAuthenticator {
_used_salts: LegacyMap::<(ContractAddress, felt252), bool>
}

#[external(v0)]
#[abi(embed_v0)]
impl StarkSigAuthenticator of IStarkSigAuthenticator<ContractState> {
fn authenticate_propose(
ref self: ContractState,
Expand Down
2 changes: 1 addition & 1 deletion starknet/src/authenticators/stark_tx.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod StarkTxAuthenticator {
#[storage]
struct Storage {}

#[external(v0)]
#[abi(embed_v0)]
impl StarkTxAuthenticator of IStarkTxAuthenticator<ContractState> {
fn authenticate_propose(
ref self: ContractState,
Expand Down
12 changes: 7 additions & 5 deletions starknet/src/execution_strategies/eth_relayer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod EthRelayerExecutionStrategy {
use starknet::{info, syscalls, EthAddress};
use sx::interfaces::IExecutionStrategy;
use sx::types::{Proposal, ProposalStatus};
use starknet::SyscallResultTrait;

#[storage]
struct Storage {}
Expand All @@ -20,7 +21,7 @@ mod EthRelayerExecutionStrategy {
/// * votes_against - The number of votes against the proposal.
/// * votes_abstain - The number of votes abstaining from the proposal.
/// * payload - An array containing the serialized L1 execution strategy address and the L1 execution hash.
#[external(v0)]
#[abi(embed_v0)]
impl EthRelayerExecutionStrategy of IExecutionStrategy<ContractState> {
fn execute(
ref self: ContractState,
Expand All @@ -43,9 +44,9 @@ mod EthRelayerExecutionStrategy {

// Decode payload into L1 execution strategy and L1 (keccak) execution hash
let mut payload = payload.span();
let (l1_execution_strategy, l1_execution_hash) = Serde::<(
EthAddress, u256
)>::deserialize(ref payload)
let (l1_execution_strategy, l1_execution_hash) = Serde::<
(EthAddress, u256)
>::deserialize(ref payload)
.unwrap();

// Serialize the payload to be sent to the L1 execution strategy
Expand All @@ -58,7 +59,8 @@ mod EthRelayerExecutionStrategy {
votes_abstain.serialize(ref l1_payload);
l1_execution_hash.serialize(ref l1_payload);

syscalls::send_message_to_l1_syscall(l1_execution_strategy.into(), l1_payload.span());
syscalls::send_message_to_l1_syscall(l1_execution_strategy.into(), l1_payload.span())
.unwrap_syscall();
}

fn get_strategy_type(self: @ContractState) -> felt252 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod NoExecutionSimpleMajorityExecutionStrategy {
#[storage]
struct Storage {}

#[external(v0)]
#[abi(embed_v0)]
impl NoExecutionSimpleMajorityExecutionStrategy of IExecutionStrategy<ContractState> {
fn execute(
ref self: ContractState,
Expand Down
Loading

0 comments on commit 1b748c6

Please sign in to comment.