From 082c97cb95d8647227f478254114d9b1ff470665 Mon Sep 17 00:00:00 2001 From: Orlando Date: Mon, 28 Aug 2023 13:59:20 +0100 Subject: [PATCH] chore: formatting --- ethereum/src/deps.sol | 10 +- .../L1AvatarExecutionStrategy.sol | 9 +- .../SimpleQuorumExecutionStrategy.sol | 2 +- .../StarknetSpaceManager.sol | 4 +- ethereum/src/mocks/IStarknetMessaging.sol | 62 ++++---- .../src/mocks/IStarknetMessagingEvents.sol | 8 +- ...L1AvatarExecutionStrategyMockMessaging.sol | 7 +- ethereum/src/mocks/MockStarknetMessaging.sol | 22 +-- ethereum/src/mocks/NamedStorage.sol | 132 +++++++++--------- ethereum/src/mocks/StarknetMessaging.sol | 106 ++++++-------- .../execution_strategies/eth_relayer.cairo | 2 - 11 files changed, 164 insertions(+), 200 deletions(-) diff --git a/ethereum/src/deps.sol b/ethereum/src/deps.sol index 1488951c..12bc9767 100644 --- a/ethereum/src/deps.sol +++ b/ethereum/src/deps.sol @@ -2,8 +2,8 @@ pragma solidity ^0.8.19; -import '@gnosis.pm/safe-contracts/contracts/GnosisSafeL2.sol'; -import '@gnosis.pm/safe-contracts/contracts/proxies/GnosisSafeProxyFactory.sol'; -import '@gnosis.pm/zodiac/contracts/factory/ModuleProxyFactory.sol'; -import '@gnosis.pm/zodiac/contracts/guard/Guardable.sol'; -import '@gnosis.pm/zodiac/contracts/core/Module.sol'; \ No newline at end of file +import "@gnosis.pm/safe-contracts/contracts/GnosisSafeL2.sol"; +import "@gnosis.pm/safe-contracts/contracts/proxies/GnosisSafeProxyFactory.sol"; +import "@gnosis.pm/zodiac/contracts/factory/ModuleProxyFactory.sol"; +import "@gnosis.pm/zodiac/contracts/guard/Guardable.sol"; +import "@gnosis.pm/zodiac/contracts/core/Module.sol"; diff --git a/ethereum/src/execution-strategies/L1AvatarExecutionStrategy.sol b/ethereum/src/execution-strategies/L1AvatarExecutionStrategy.sol index c52fa32f..b1d838f9 100644 --- a/ethereum/src/execution-strategies/L1AvatarExecutionStrategy.sol +++ b/ethereum/src/execution-strategies/L1AvatarExecutionStrategy.sol @@ -57,7 +57,8 @@ contract L1AvatarExecutionStrategy is SimpleQuorumExecutionStrategy { uint256[] memory _starknetSpaces, uint256 _quorum ) { - bytes memory initParams = abi.encode(_owner, _target, _starknetCore, _executionRelayer, _starknetSpaces, _quorum); + bytes memory initParams = + abi.encode(_owner, _target, _starknetCore, _executionRelayer, _starknetSpaces, _quorum); setUp(initParams); } @@ -70,7 +71,7 @@ contract L1AvatarExecutionStrategy is SimpleQuorumExecutionStrategy { address _starknetCore, uint256 _executionRelayer, uint256[] memory _starknetSpaces, - uint256 _quorum + uint256 _quorum ) = abi.decode(initParams, (address, address, address, uint256, uint256[], uint256)); __Ownable_init(); transferOwnership(_owner); @@ -146,7 +147,7 @@ contract L1AvatarExecutionStrategy is SimpleQuorumExecutionStrategy { payload[6] = proposal.executionStrategy; payload[7] = proposal.authorAddressType; payload[8] = proposal.author; - payload[9] = proposal.activeVotingStrategies & (2 ** 128 - 1); + payload[9] = proposal.activeVotingStrategies & (2 ** 128 - 1); payload[10] = proposal.activeVotingStrategies >> 128; payload[11] = votesFor & (2 ** 128 - 1); @@ -180,4 +181,4 @@ contract L1AvatarExecutionStrategy is SimpleQuorumExecutionStrategy { function getStrategyType() external pure override returns (string memory) { return "SimpleQuorumL1Avatar"; } -} \ No newline at end of file +} diff --git a/ethereum/src/execution-strategies/SimpleQuorumExecutionStrategy.sol b/ethereum/src/execution-strategies/SimpleQuorumExecutionStrategy.sol index 5aae5c64..177d70b6 100644 --- a/ethereum/src/execution-strategies/SimpleQuorumExecutionStrategy.sol +++ b/ethereum/src/execution-strategies/SimpleQuorumExecutionStrategy.sol @@ -9,7 +9,7 @@ import {StarknetSpaceManager} from "./StarknetSpaceManager.sol"; /// @title Simple Quorum Base Execution Strategy abstract contract SimpleQuorumExecutionStrategy is IExecutionStrategy, StarknetSpaceManager { event QuorumUpdated(uint256 newQuorum); - + /// @notice The quorum required to execute a proposal using this strategy. uint256 public quorum; diff --git a/ethereum/src/execution-strategies/StarknetSpaceManager.sol b/ethereum/src/execution-strategies/StarknetSpaceManager.sol index a547a252..713c3e64 100644 --- a/ethereum/src/execution-strategies/StarknetSpaceManager.sol +++ b/ethereum/src/execution-strategies/StarknetSpaceManager.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.19; import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; -import { TRUE, FALSE } from "../types.sol"; +import {TRUE, FALSE} from "../types.sol"; /// @title Space Manager /// @notice Manages a whitelist of Spaces that are authorized to execute transactions via this contract. @@ -32,7 +32,7 @@ contract StarknetSpaceManager is OwnableUpgradeable { /// @notice Enable a space. /// @param space Address of the space. function enableSpace(uint256 space) public onlyOwner { - if (space == 0 || (spaces[space] != FALSE)) revert InvalidSpace(); + if (space == 0 || (spaces[space] != FALSE)) revert InvalidSpace(); spaces[space] = TRUE; emit SpaceEnabled(space); } diff --git a/ethereum/src/mocks/IStarknetMessaging.sol b/ethereum/src/mocks/IStarknetMessaging.sol index 4d1a7521..99562e6a 100644 --- a/ethereum/src/mocks/IStarknetMessaging.sol +++ b/ethereum/src/mocks/IStarknetMessaging.sol @@ -5,33 +5,30 @@ import "./IStarknetMessagingEvents.sol"; interface IStarknetMessaging is IStarknetMessagingEvents { /** - Sends a message to an L2 contract. - This function is payable, the payed amount is the message fee. - - Returns the hash of the message and the nonce of the message. - */ - function sendMessageToL2( - uint256 toAddress, - uint256 selector, - uint256[] calldata payload - ) external payable returns (bytes32, uint256); - - /** - Consumes a message that was sent from an L2 contract. - - Returns the hash of the message. - */ - function consumeMessageFromL2(uint256 fromAddress, uint256[] calldata payload) + * Sends a message to an L2 contract. + * This function is payable, the payed amount is the message fee. + * + * Returns the hash of the message and the nonce of the message. + */ + function sendMessageToL2(uint256 toAddress, uint256 selector, uint256[] calldata payload) external - returns (bytes32); + payable + returns (bytes32, uint256); /** - Starts the cancellation of an L1 to L2 message. - A message can be canceled messageCancellationDelay() seconds after this function is called. + * Consumes a message that was sent from an L2 contract. + * + * Returns the hash of the message. + */ + function consumeMessageFromL2(uint256 fromAddress, uint256[] calldata payload) external returns (bytes32); - Note: This function may only be called for a message that is currently pending and the caller - must be the sender of the that message. - */ + /** + * Starts the cancellation of an L1 to L2 message. + * A message can be canceled messageCancellationDelay() seconds after this function is called. + * + * Note: This function may only be called for a message that is currently pending and the caller + * must be the sender of the that message. + */ function startL1ToL2MessageCancellation( uint256 toAddress, uint256 selector, @@ -40,15 +37,12 @@ interface IStarknetMessaging is IStarknetMessagingEvents { ) external returns (bytes32); /** - Cancels an L1 to L2 message, this function should be called messageCancellationDelay() seconds - after the call to startL1ToL2MessageCancellation(). - - Note that the message fee is not refunded. - */ - function cancelL1ToL2Message( - uint256 toAddress, - uint256 selector, - uint256[] calldata payload, - uint256 nonce - ) external returns (bytes32); + * Cancels an L1 to L2 message, this function should be called messageCancellationDelay() seconds + * after the call to startL1ToL2MessageCancellation(). + * + * Note that the message fee is not refunded. + */ + function cancelL1ToL2Message(uint256 toAddress, uint256 selector, uint256[] calldata payload, uint256 nonce) + external + returns (bytes32); } diff --git a/ethereum/src/mocks/IStarknetMessagingEvents.sol b/ethereum/src/mocks/IStarknetMessagingEvents.sol index 13b3e0fc..0de21704 100644 --- a/ethereum/src/mocks/IStarknetMessagingEvents.sol +++ b/ethereum/src/mocks/IStarknetMessagingEvents.sol @@ -16,11 +16,7 @@ interface IStarknetMessagingEvents { ); // An event that is raised when a message from L2 to L1 is consumed. - event ConsumedMessageToL1( - uint256 indexed fromAddress, - address indexed toAddress, - uint256[] payload - ); + event ConsumedMessageToL1(uint256 indexed fromAddress, address indexed toAddress, uint256[] payload); // An event that is raised when a message from L1 to L2 is consumed. event ConsumedMessageToL2( @@ -48,4 +44,4 @@ interface IStarknetMessagingEvents { uint256[] payload, uint256 nonce ); -} \ No newline at end of file +} diff --git a/ethereum/src/mocks/L1AvatarExecutionStrategyMockMessaging.sol b/ethereum/src/mocks/L1AvatarExecutionStrategyMockMessaging.sol index 7445ef82..0300240e 100644 --- a/ethereum/src/mocks/L1AvatarExecutionStrategyMockMessaging.sol +++ b/ethereum/src/mocks/L1AvatarExecutionStrategyMockMessaging.sol @@ -57,7 +57,8 @@ contract L1AvatarExecutionStrategyMockMessaging is SimpleQuorumExecutionStrategy uint256[] memory _starknetSpaces, uint256 _quorum ) { - bytes memory initParams = abi.encode(_owner, _target, _starknetCore, _executionRelayer, _starknetSpaces, _quorum); + bytes memory initParams = + abi.encode(_owner, _target, _starknetCore, _executionRelayer, _starknetSpaces, _quorum); setUp(initParams); } @@ -70,7 +71,7 @@ contract L1AvatarExecutionStrategyMockMessaging is SimpleQuorumExecutionStrategy address _starknetCore, uint256 _executionRelayer, uint256[] memory _starknetSpaces, - uint256 _quorum + uint256 _quorum ) = abi.decode(initParams, (address, address, address, uint256, uint256[], uint256)); __Ownable_init(); transferOwnership(_owner); @@ -146,7 +147,7 @@ contract L1AvatarExecutionStrategyMockMessaging is SimpleQuorumExecutionStrategy payload[6] = proposal.executionStrategy; payload[7] = proposal.authorAddressType; payload[8] = proposal.author; - payload[9] = proposal.activeVotingStrategies & (2 ** 128 - 1); + payload[9] = proposal.activeVotingStrategies & (2 ** 128 - 1); payload[10] = proposal.activeVotingStrategies >> 128; payload[11] = votesFor & (2 ** 128 - 1); diff --git a/ethereum/src/mocks/MockStarknetMessaging.sol b/ethereum/src/mocks/MockStarknetMessaging.sol index 937fec9a..466bf234 100644 --- a/ethereum/src/mocks/MockStarknetMessaging.sol +++ b/ethereum/src/mocks/MockStarknetMessaging.sol @@ -9,22 +9,16 @@ contract MockStarknetMessaging is StarknetMessaging { } /** - Mocks a message from L2 to L1. - */ - function mockSendMessageFromL2( - uint256 fromAddress, - uint256 toAddress, - uint256[] calldata payload - ) external { - bytes32 msgHash = keccak256( - abi.encodePacked(fromAddress, toAddress, payload.length, payload) - ); + * Mocks a message from L2 to L1. + */ + function mockSendMessageFromL2(uint256 fromAddress, uint256 toAddress, uint256[] calldata payload) external { + bytes32 msgHash = keccak256(abi.encodePacked(fromAddress, toAddress, payload.length, payload)); l2ToL1Messages()[msgHash] += 1; } /** - Mocks consumption of a message from L1 to L2. - */ + * Mocks consumption of a message from L1 to L2. + */ function mockConsumeMessageToL2( uint256 fromAddress, uint256 toAddress, @@ -32,9 +26,7 @@ contract MockStarknetMessaging is StarknetMessaging { uint256[] calldata payload, uint256 nonce ) external { - bytes32 msgHash = keccak256( - abi.encodePacked(fromAddress, toAddress, nonce, selector, payload.length, payload) - ); + bytes32 msgHash = keccak256(abi.encodePacked(fromAddress, toAddress, nonce, selector, payload.length, payload)); require(l1ToL2Messages()[msgHash] > 0, "INVALID_MESSAGE_TO_CONSUME"); l1ToL2Messages()[msgHash] = 0; diff --git a/ethereum/src/mocks/NamedStorage.sol b/ethereum/src/mocks/NamedStorage.sol index 6424e409..bc75fe30 100644 --- a/ethereum/src/mocks/NamedStorage.sol +++ b/ethereum/src/mocks/NamedStorage.sol @@ -6,88 +6,88 @@ pragma solidity ^0.8.19; New types of storage variables should be added here upon need. */ library NamedStorage { - function bytes32ToUint256Mapping(string memory tag_) - internal - pure - returns (mapping(bytes32 => uint256) storage randomVariable) - { - bytes32 location = keccak256(abi.encodePacked(tag_)); - assembly { - randomVariable.slot := location + function bytes32ToUint256Mapping(string memory tag_) + internal + pure + returns (mapping(bytes32 => uint256) storage randomVariable) + { + bytes32 location = keccak256(abi.encodePacked(tag_)); + assembly { + randomVariable.slot := location + } } - } - function bytes32ToAddressMapping(string memory tag_) - internal - pure - returns (mapping(bytes32 => address) storage randomVariable) - { - bytes32 location = keccak256(abi.encodePacked(tag_)); - assembly { - randomVariable.slot := location + function bytes32ToAddressMapping(string memory tag_) + internal + pure + returns (mapping(bytes32 => address) storage randomVariable) + { + bytes32 location = keccak256(abi.encodePacked(tag_)); + assembly { + randomVariable.slot := location + } } - } - function addressToBoolMapping(string memory tag_) - internal - pure - returns (mapping(address => bool) storage randomVariable) - { - bytes32 location = keccak256(abi.encodePacked(tag_)); - assembly { - randomVariable.slot := location + function addressToBoolMapping(string memory tag_) + internal + pure + returns (mapping(address => bool) storage randomVariable) + { + bytes32 location = keccak256(abi.encodePacked(tag_)); + assembly { + randomVariable.slot := location + } } - } - function getUintValue(string memory tag_) internal view returns (uint256 retVal) { - bytes32 slot = keccak256(abi.encodePacked(tag_)); - assembly { - retVal := sload(slot) + function getUintValue(string memory tag_) internal view returns (uint256 retVal) { + bytes32 slot = keccak256(abi.encodePacked(tag_)); + assembly { + retVal := sload(slot) + } } - } - function setUintValue(string memory tag_, uint256 value) internal { - bytes32 slot = keccak256(abi.encodePacked(tag_)); - assembly { - sstore(slot, value) + function setUintValue(string memory tag_, uint256 value) internal { + bytes32 slot = keccak256(abi.encodePacked(tag_)); + assembly { + sstore(slot, value) + } } - } - function setUintValueOnce(string memory tag_, uint256 value) internal { - require(getUintValue(tag_) == 0, 'ALREADY_SET'); - setUintValue(tag_, value); - } + function setUintValueOnce(string memory tag_, uint256 value) internal { + require(getUintValue(tag_) == 0, "ALREADY_SET"); + setUintValue(tag_, value); + } - function getAddressValue(string memory tag_) internal view returns (address retVal) { - bytes32 slot = keccak256(abi.encodePacked(tag_)); - assembly { - retVal := sload(slot) + function getAddressValue(string memory tag_) internal view returns (address retVal) { + bytes32 slot = keccak256(abi.encodePacked(tag_)); + assembly { + retVal := sload(slot) + } } - } - function setAddressValue(string memory tag_, address value) internal { - bytes32 slot = keccak256(abi.encodePacked(tag_)); - assembly { - sstore(slot, value) + function setAddressValue(string memory tag_, address value) internal { + bytes32 slot = keccak256(abi.encodePacked(tag_)); + assembly { + sstore(slot, value) + } } - } - function setAddressValueOnce(string memory tag_, address value) internal { - require(getAddressValue(tag_) == address(0x0), 'ALREADY_SET'); - setAddressValue(tag_, value); - } + function setAddressValueOnce(string memory tag_, address value) internal { + require(getAddressValue(tag_) == address(0x0), "ALREADY_SET"); + setAddressValue(tag_, value); + } - function getBoolValue(string memory tag_) internal view returns (bool retVal) { - bytes32 slot = keccak256(abi.encodePacked(tag_)); - assembly { - retVal := sload(slot) + function getBoolValue(string memory tag_) internal view returns (bool retVal) { + bytes32 slot = keccak256(abi.encodePacked(tag_)); + assembly { + retVal := sload(slot) + } } - } - function setBoolValue(string memory tag_, bool value) internal { - bytes32 slot = keccak256(abi.encodePacked(tag_)); - assembly { - sstore(slot, value) + function setBoolValue(string memory tag_, bool value) internal { + bytes32 slot = keccak256(abi.encodePacked(tag_)); + assembly { + sstore(slot, value) + } } - } -} \ No newline at end of file +} diff --git a/ethereum/src/mocks/StarknetMessaging.sol b/ethereum/src/mocks/StarknetMessaging.sol index 345376ae..73e0f340 100644 --- a/ethereum/src/mocks/StarknetMessaging.sol +++ b/ethereum/src/mocks/StarknetMessaging.sol @@ -5,10 +5,10 @@ import "./IStarknetMessaging.sol"; import "./NamedStorage.sol"; /** - Implements sending messages to L2 by adding them to a pipe and consuming messages from L2 by - removing them from a different pipe. A deriving contract can handle the former pipe and add items - to the latter pipe while interacting with L2. -*/ + * Implements sending messages to L2 by adding them to a pipe and consuming messages from L2 by + * removing them from a different pipe. A deriving contract can handle the former pipe and add items + * to the latter pipe while interacting with L2. + */ contract StarknetMessaging is IStarknetMessaging { /* Random slot storage elements and accessors. @@ -18,20 +18,16 @@ contract StarknetMessaging is IStarknetMessaging { string constant L1L2_MESSAGE_NONCE_TAG = "STARKNET_1.0_MSGING_L1TOL2_NONCE"; - string constant L1L2_MESSAGE_CANCELLATION_MAP_TAG = ( - "STARKNET_1.0_MSGING_L1TOL2_CANCELLATION_MAPPPING" - ); + string constant L1L2_MESSAGE_CANCELLATION_MAP_TAG = ("STARKNET_1.0_MSGING_L1TOL2_CANCELLATION_MAPPPING"); - string constant L1L2_MESSAGE_CANCELLATION_DELAY_TAG = ( - "STARKNET_1.0_MSGING_L1TOL2_CANCELLATION_DELAY" - ); + string constant L1L2_MESSAGE_CANCELLATION_DELAY_TAG = ("STARKNET_1.0_MSGING_L1TOL2_CANCELLATION_DELAY"); uint256 public constant MAX_L1_MSG_FEE = 1 ether; /** - Returns the msg_fee + 1 for the message with the given 'msgHash', - or 0 if no message with such a hash is pending. - */ + * Returns the msg_fee + 1 for the message with the given 'msgHash', + * or 0 if no message with such a hash is pending. + */ function l1ToL2Messages(bytes32 msgHash) external view returns (uint256) { return l1ToL2Messages()[msgHash]; } @@ -61,53 +57,41 @@ contract StarknetMessaging is IStarknetMessaging { } /** - Returns the timestamp at the time cancelL1ToL2Message was called with a message - matching 'msgHash'. - - The function returns 0 if cancelL1ToL2Message was never called. - */ + * Returns the timestamp at the time cancelL1ToL2Message was called with a message + * matching 'msgHash'. + * + * The function returns 0 if cancelL1ToL2Message was never called. + */ function l1ToL2MessageCancellations(bytes32 msgHash) external view returns (uint256) { return l1ToL2MessageCancellations()[msgHash]; } - function l1ToL2MessageCancellations() - internal - pure - returns (mapping(bytes32 => uint256) storage) - { + function l1ToL2MessageCancellations() internal pure returns (mapping(bytes32 => uint256) storage) { return NamedStorage.bytes32ToUint256Mapping(L1L2_MESSAGE_CANCELLATION_MAP_TAG); } /** - Returns the hash of an L1 -> L2 message from msg.sender. - */ - function getL1ToL2MsgHash( - uint256 toAddress, - uint256 selector, - uint256[] calldata payload, - uint256 nonce - ) internal view returns (bytes32) { - return - keccak256( - abi.encodePacked( - uint256(uint160(msg.sender)), - toAddress, - nonce, - selector, - payload.length, - payload - ) - ); + * Returns the hash of an L1 -> L2 message from msg.sender. + */ + function getL1ToL2MsgHash(uint256 toAddress, uint256 selector, uint256[] calldata payload, uint256 nonce) + internal + view + returns (bytes32) + { + return keccak256( + abi.encodePacked(uint256(uint160(msg.sender)), toAddress, nonce, selector, payload.length, payload) + ); } /** - Sends a message to an L2 contract. - */ - function sendMessageToL2( - uint256 toAddress, - uint256 selector, - uint256[] calldata payload - ) external payable override returns (bytes32, uint256) { + * Sends a message to an L2 contract. + */ + function sendMessageToL2(uint256 toAddress, uint256 selector, uint256[] calldata payload) + external + payable + override + returns (bytes32, uint256) + { require(msg.value <= MAX_L1_MSG_FEE, "MAX_L1_MSG_FEE_EXCEEDED"); uint256 nonce = l1ToL2MessageNonce(); NamedStorage.setUintValue(L1L2_MESSAGE_NONCE_TAG, nonce + 1); @@ -120,18 +104,17 @@ contract StarknetMessaging is IStarknetMessaging { } /** - Consumes a message that was sent from an L2 contract. - - Returns the hash of the message. - */ + * Consumes a message that was sent from an L2 contract. + * + * Returns the hash of the message. + */ function consumeMessageFromL2(uint256 fromAddress, uint256[] calldata payload) external override returns (bytes32) { - bytes32 msgHash = keccak256( - abi.encodePacked(fromAddress, uint256(uint160(msg.sender)), payload.length, payload) - ); + bytes32 msgHash = + keccak256(abi.encodePacked(fromAddress, uint256(uint160(msg.sender)), payload.length, payload)); require(l2ToL1Messages()[msgHash] > 0, "INVALID_MESSAGE_TO_CONSUME"); emit ConsumedMessageToL1(fromAddress, msg.sender, payload); @@ -153,12 +136,11 @@ contract StarknetMessaging is IStarknetMessaging { return msgHash; } - function cancelL1ToL2Message( - uint256 toAddress, - uint256 selector, - uint256[] calldata payload, - uint256 nonce - ) external override returns (bytes32) { + function cancelL1ToL2Message(uint256 toAddress, uint256 selector, uint256[] calldata payload, uint256 nonce) + external + override + returns (bytes32) + { emit MessageToL2Canceled(msg.sender, toAddress, selector, payload, nonce); bytes32 msgHash = getL1ToL2MsgHash(toAddress, selector, payload, nonce); uint256 msgFeePlusOne = l1ToL2Messages()[msgHash]; diff --git a/starknet/src/execution_strategies/eth_relayer.cairo b/starknet/src/execution_strategies/eth_relayer.cairo index 4ff0152b..8aa96815 100644 --- a/starknet/src/execution_strategies/eth_relayer.cairo +++ b/starknet/src/execution_strategies/eth_relayer.cairo @@ -4,8 +4,6 @@ mod EthRelayerExecutionStrategy { use option::OptionTrait; use traits::{Into, TryInto}; use serde::Serde; - use clone::Clone; - use starknet::{EthAddress, contract_address_const}; use starknet::syscalls::send_message_to_l1_syscall; use starknet::info; use sx::interfaces::IExecutionStrategy;