Skip to content

Commit

Permalink
Fix contract formatting
Browse files Browse the repository at this point in the history
Also remove git hooks, because it takes unjustifiably long
  • Loading branch information
ly0va committed Nov 18, 2020
1 parent 2c4864b commit 588f1b4
Show file tree
Hide file tree
Showing 26 changed files with 323 additions and 330 deletions.
6 changes: 0 additions & 6 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,3 @@ if git diff --cached $VERFIER_CONTRACT_FILE | grep -lq 'constant DUMMY_VERIFIER
echo "Please disable the DUMMY_VERIFIER and try to commit changes again"
exit 1
fi

if ! (yarn check:ts && yarn check:md && yarn lint:md) >/dev/null 2>&1; then
echo -e "${RED}Commit error!${NC}"
echo "Please format code via 'yarn fmt' and check markdown lints via 'yarn lint:md'"
echo "Cannot commit unformatted code"
fi
2 changes: 1 addition & 1 deletion .prettier-sol.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false,
"explicitTypes": "never"
"explicitTypes": "always"
}
82 changes: 41 additions & 41 deletions contracts/contracts/Bytes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ pragma solidity ^0.5.8;

library Bytes {
function toBytesFromUInt16(uint16 self) internal pure returns (bytes memory _bts) {
return toBytesFromUIntTruncated(uint(self), 2);
return toBytesFromUIntTruncated(uint256(self), 2);
}

function toBytesFromUInt24(uint24 self) internal pure returns (bytes memory _bts) {
return toBytesFromUIntTruncated(uint(self), 3);
return toBytesFromUIntTruncated(uint256(self), 3);
}

function toBytesFromUInt32(uint32 self) internal pure returns (bytes memory _bts) {
return toBytesFromUIntTruncated(uint(self), 4);
return toBytesFromUIntTruncated(uint256(self), 4);
}

function toBytesFromUInt128(uint128 self) internal pure returns (bytes memory _bts) {
return toBytesFromUIntTruncated(uint(self), 16);
return toBytesFromUIntTruncated(uint256(self), 16);
}

// Copies 'len' lower bytes from 'self' into a new 'bytes memory'.
// Returns the newly created 'bytes memory'. The returned bytes will be of length 'len'.
function toBytesFromUIntTruncated(uint self, uint8 byteLength) private pure returns (bytes memory bts) {
function toBytesFromUIntTruncated(uint256 self, uint8 byteLength) private pure returns (bytes memory bts) {
require(byteLength <= 32, "bt211");
bts = new bytes(byteLength);
// Even though the bytes will allocate a full word, we don't want
// any potential garbage bytes in there.
uint data = self << ((32 - byteLength) * 8);
uint256 data = self << ((32 - byteLength) * 8);
assembly {
mstore(
add(
Expand All @@ -48,13 +48,13 @@ library Bytes {
// Copies 'self' into a new 'bytes memory'.
// Returns the newly created 'bytes memory'. The returned bytes will be of length '20'.
function toBytesFromAddress(address self) internal pure returns (bytes memory bts) {
bts = toBytesFromUIntTruncated(uint(self), 20);
bts = toBytesFromUIntTruncated(uint256(self), 20);
}

// See comment at the top of this file for explanation of how this function works.
// NOTE: theoretically possible overflow of (_start + 20)
function bytesToAddress(bytes memory self, uint _start) internal pure returns (address addr) {
uint offset = _start + 20;
function bytesToAddress(bytes memory self, uint256 _start) internal pure returns (address addr) {
uint256 offset = _start + 20;
require(self.length >= offset, "bta11");
assembly {
addr := mload(add(self, offset))
Expand All @@ -64,7 +64,7 @@ library Bytes {
// Reasoning about why this function works is similar to that of other similar functions, except NOTE below.
// NOTE: that bytes1..32 is stored in the beginning of the word unlike other primitive types
// NOTE: theoretically possible overflow of (_start + 20)
function bytesToBytes20(bytes memory self, uint _start) internal pure returns (bytes20 r) {
function bytesToBytes20(bytes memory self, uint256 _start) internal pure returns (bytes20 r) {
require(self.length >= (_start + 20), "btb20");
assembly {
r := mload(add(add(self, 0x20), _start))
Expand All @@ -73,8 +73,8 @@ library Bytes {

// See comment at the top of this file for explanation of how this function works.
// NOTE: theoretically possible overflow of (_start + 0x2)
function bytesToUInt16(bytes memory _bytes, uint _start) internal pure returns (uint16 r) {
uint offset = _start + 0x2;
function bytesToUInt16(bytes memory _bytes, uint256 _start) internal pure returns (uint16 r) {
uint256 offset = _start + 0x2;
require(_bytes.length >= offset, "btu02");
assembly {
r := mload(add(_bytes, offset))
Expand All @@ -83,26 +83,26 @@ library Bytes {

// See comment at the top of this file for explanation of how this function works.
// NOTE: theoretically possible overflow of (_start + 0x3)
function bytesToUInt24(bytes memory _bytes, uint _start) internal pure returns (uint24 r) {
uint offset = _start + 0x3;
function bytesToUInt24(bytes memory _bytes, uint256 _start) internal pure returns (uint24 r) {
uint256 offset = _start + 0x3;
require(_bytes.length >= offset, "btu03");
assembly {
r := mload(add(_bytes, offset))
}
}

// NOTE: theoretically possible overflow of (_start + 0x4)
function bytesToUInt32(bytes memory _bytes, uint _start) internal pure returns (uint32 r) {
uint offset = _start + 0x4;
function bytesToUInt32(bytes memory _bytes, uint256 _start) internal pure returns (uint32 r) {
uint256 offset = _start + 0x4;
require(_bytes.length >= offset, "btu04");
assembly {
r := mload(add(_bytes, offset))
}
}

// NOTE: theoretically possible overflow of (_start + 0x10)
function bytesToUInt128(bytes memory _bytes, uint _start) internal pure returns (uint128 r) {
uint offset = _start + 0x10;
function bytesToUInt128(bytes memory _bytes, uint256 _start) internal pure returns (uint128 r) {
uint256 offset = _start + 0x10;
require(_bytes.length >= offset, "btu16");
assembly {
r := mload(add(_bytes, offset))
Expand All @@ -111,17 +111,17 @@ library Bytes {

// See comment at the top of this file for explanation of how this function works.
// NOTE: theoretically possible overflow of (_start + 0x14)
function bytesToUInt160(bytes memory _bytes, uint _start) internal pure returns (uint160 r) {
uint offset = _start + 0x14;
function bytesToUInt160(bytes memory _bytes, uint256 _start) internal pure returns (uint160 r) {
uint256 offset = _start + 0x14;
require(_bytes.length >= offset, "btu20");
assembly {
r := mload(add(_bytes, offset))
}
}

// NOTE: theoretically possible overflow of (_start + 0x20)
function bytesToBytes32(bytes memory _bytes, uint _start) internal pure returns (bytes32 r) {
uint offset = _start + 0x20;
function bytesToBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32 r) {
uint256 offset = _start + 0x20;
require(_bytes.length >= offset, "btb32");
assembly {
r := mload(add(_bytes, offset))
Expand All @@ -134,8 +134,8 @@ library Bytes {
// NOTE: theoretically possible overflow of (_start + _length)
function slice(
bytes memory _bytes,
uint _start,
uint _length
uint256 _start,
uint256 _length
) internal pure returns (bytes memory) {
require(_bytes.length >= (_start + _length), "bse11"); // bytes length is less then start byte + length bytes

Expand Down Expand Up @@ -167,79 +167,79 @@ library Bytes {
// NOTE: theoretically possible overflow of (_offset + _length)
function read(
bytes memory _data,
uint _offset,
uint _length
) internal pure returns (uint new_offset, bytes memory data) {
uint256 _offset,
uint256 _length
) internal pure returns (uint256 new_offset, bytes memory data) {
data = slice(_data, _offset, _length);
new_offset = _offset + _length;
}

// NOTE: theoretically possible overflow of (_offset + 1)
function readBool(bytes memory _data, uint _offset) internal pure returns (uint new_offset, bool r) {
function readBool(bytes memory _data, uint256 _offset) internal pure returns (uint256 new_offset, bool r) {
new_offset = _offset + 1;
r = uint8(_data[_offset]) != 0;
}

// NOTE: theoretically possible overflow of (_offset + 1)
function readUint8(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint8 r) {
function readUint8(bytes memory _data, uint256 _offset) internal pure returns (uint256 new_offset, uint8 r) {
new_offset = _offset + 1;
r = uint8(_data[_offset]);
}

// NOTE: theoretically possible overflow of (_offset + 2)
function readUInt16(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint16 r) {
function readUInt16(bytes memory _data, uint256 _offset) internal pure returns (uint256 new_offset, uint16 r) {
new_offset = _offset + 2;
r = bytesToUInt16(_data, _offset);
}

// NOTE: theoretically possible overflow of (_offset + 3)
function readUInt24(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint24 r) {
function readUInt24(bytes memory _data, uint256 _offset) internal pure returns (uint256 new_offset, uint24 r) {
new_offset = _offset + 3;
r = bytesToUInt24(_data, _offset);
}

// NOTE: theoretically possible overflow of (_offset + 4)
function readUInt32(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint32 r) {
function readUInt32(bytes memory _data, uint256 _offset) internal pure returns (uint256 new_offset, uint32 r) {
new_offset = _offset + 4;
r = bytesToUInt32(_data, _offset);
}

// NOTE: theoretically possible overflow of (_offset + 16)
function readUInt128(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint128 r) {
function readUInt128(bytes memory _data, uint256 _offset) internal pure returns (uint256 new_offset, uint128 r) {
new_offset = _offset + 16;
r = bytesToUInt128(_data, _offset);
}

// NOTE: theoretically possible overflow of (_offset + 20)
function readUInt160(bytes memory _data, uint _offset) internal pure returns (uint new_offset, uint160 r) {
function readUInt160(bytes memory _data, uint256 _offset) internal pure returns (uint256 new_offset, uint160 r) {
new_offset = _offset + 20;
r = bytesToUInt160(_data, _offset);
}

// NOTE: theoretically possible overflow of (_offset + 20)
function readAddress(bytes memory _data, uint _offset) internal pure returns (uint new_offset, address r) {
function readAddress(bytes memory _data, uint256 _offset) internal pure returns (uint256 new_offset, address r) {
new_offset = _offset + 20;
r = bytesToAddress(_data, _offset);
}

// NOTE: theoretically possible overflow of (_offset + 20)
function readBytes20(bytes memory _data, uint _offset) internal pure returns (uint new_offset, bytes20 r) {
function readBytes20(bytes memory _data, uint256 _offset) internal pure returns (uint256 new_offset, bytes20 r) {
new_offset = _offset + 20;
r = bytesToBytes20(_data, _offset);
}

// NOTE: theoretically possible overflow of (_offset + 32)
function readBytes32(bytes memory _data, uint _offset) internal pure returns (uint new_offset, bytes32 r) {
function readBytes32(bytes memory _data, uint256 _offset) internal pure returns (uint256 new_offset, bytes32 r) {
new_offset = _offset + 32;
r = bytesToBytes32(_data, _offset);
}

// Helper function for hex conversion.
function halfByteToHex(byte _byte) internal pure returns (byte _hexByte) {
function halfByteToHex(bytes1 _byte) internal pure returns (bytes1 _hexByte) {
require(uint8(_byte) < 0x10, "hbh11"); // half byte's value is out of 0..15 range.

// "FEDCBA9876543210" ASCII-encoded, shifted and automatically truncated.
return byte(uint8(0x66656463626139383736353433323130 >> (uint8(_byte) * 8)));
return bytes1(uint8(0x66656463626139383736353433323130 >> (uint8(_byte) * 8)));
}

// Convert bytes to ASCII hex representation
Expand Down Expand Up @@ -280,11 +280,11 @@ library Bytes {
}

/// Trim bytes into single word
function trim(bytes memory _data, uint _new_length) internal pure returns (uint r) {
function trim(bytes memory _data, uint256 _new_length) internal pure returns (uint256 r) {
require(_new_length <= 0x20, "trm10"); // new_length is longer than word
require(_data.length >= _new_length, "trm11"); // data is to short

uint a;
uint256 a;
assembly {
a := mload(add(_data, 0x20)) // load bytes into uint256
}
Expand Down
36 changes: 18 additions & 18 deletions contracts/contracts/Config.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ pragma solidity ^0.5.8;
/// @author Matter Labs
contract Config {
/// @notice ERC20 token withdrawal gas limit, used only for complete withdrawals
uint constant ERC20_WITHDRAWAL_GAS_LIMIT = 250000;
uint256 constant ERC20_WITHDRAWAL_GAS_LIMIT = 250000;

/// @notice ETH token withdrawal gas limit, used only for complete withdrawals
uint constant ETH_WITHDRAWAL_GAS_LIMIT = 10000;
uint256 constant ETH_WITHDRAWAL_GAS_LIMIT = 10000;

/// @notice Bytes in one chunk
uint8 constant CHUNK_BYTES = 9;
Expand All @@ -33,49 +33,49 @@ contract Config {
uint32 constant MAX_ACCOUNT_ID = (2**24) - 1;

/// @notice Expected average period of block creation
uint constant BLOCK_PERIOD = 15 seconds;
uint256 constant BLOCK_PERIOD = 15 seconds;

/// @notice ETH blocks verification expectation
/// Blocks can be reverted if they are not verified for at least EXPECT_VERIFICATION_IN.
/// If set to 0 validator can revert blocks at any time.
uint constant EXPECT_VERIFICATION_IN = 0 hours / BLOCK_PERIOD;
uint256 constant EXPECT_VERIFICATION_IN = 0 hours / BLOCK_PERIOD;

uint constant NOOP_BYTES = 1 * CHUNK_BYTES;
uint constant DEPOSIT_BYTES = 6 * CHUNK_BYTES;
uint constant TRANSFER_TO_NEW_BYTES = 6 * CHUNK_BYTES;
uint constant PARTIAL_EXIT_BYTES = 6 * CHUNK_BYTES;
uint constant TRANSFER_BYTES = 2 * CHUNK_BYTES;
uint constant FORCED_EXIT_BYTES = 6 * CHUNK_BYTES;
uint256 constant NOOP_BYTES = 1 * CHUNK_BYTES;
uint256 constant DEPOSIT_BYTES = 6 * CHUNK_BYTES;
uint256 constant TRANSFER_TO_NEW_BYTES = 6 * CHUNK_BYTES;
uint256 constant PARTIAL_EXIT_BYTES = 6 * CHUNK_BYTES;
uint256 constant TRANSFER_BYTES = 2 * CHUNK_BYTES;
uint256 constant FORCED_EXIT_BYTES = 6 * CHUNK_BYTES;

/// @notice Full exit operation length
uint constant FULL_EXIT_BYTES = 6 * CHUNK_BYTES;
uint256 constant FULL_EXIT_BYTES = 6 * CHUNK_BYTES;

/// @notice OnchainWithdrawal data length
uint constant ONCHAIN_WITHDRAWAL_BYTES = 1 + 20 + 2 + 16; // (uint8 addToPendingWithdrawalsQueue, address _to, uint16 _tokenId, uint128 _amount)
uint256 constant ONCHAIN_WITHDRAWAL_BYTES = 1 + 20 + 2 + 16; // (uint8 addToPendingWithdrawalsQueue, address _to, uint16 _tokenId, uint128 _amount)

/// @notice ChangePubKey operation length
uint constant CHANGE_PUBKEY_BYTES = 6 * CHUNK_BYTES;
uint256 constant CHANGE_PUBKEY_BYTES = 6 * CHUNK_BYTES;

/// @notice Expiration delta for priority request to be satisfied (in seconds)
/// NOTE: Priority expiration should be > (EXPECT_VERIFICATION_IN * BLOCK_PERIOD), otherwise incorrect block with priority op could not be reverted.
uint constant PRIORITY_EXPIRATION_PERIOD = 3 days;
uint256 constant PRIORITY_EXPIRATION_PERIOD = 3 days;

/// @notice Expiration delta for priority request to be satisfied (in ETH blocks)
uint constant PRIORITY_EXPIRATION = PRIORITY_EXPIRATION_PERIOD / BLOCK_PERIOD;
uint256 constant PRIORITY_EXPIRATION = PRIORITY_EXPIRATION_PERIOD / BLOCK_PERIOD;

/// @notice Maximum number of priority request to clear during verifying the block
/// @dev Cause deleting storage slots cost 5k gas per each slot it's unprofitable to clear too many slots
/// @dev Value based on the assumption of ~750k gas cost of verifying and 5 used storage slots per PriorityOperation structure
uint64 constant MAX_PRIORITY_REQUESTS_TO_DELETE_IN_VERIFY = 6;

/// @notice Reserved time for users to send full exit priority operation in case of an upgrade (in seconds)
uint constant MASS_FULL_EXIT_PERIOD = 3 days;
uint256 constant MASS_FULL_EXIT_PERIOD = 3 days;

/// @notice Reserved time for users to withdraw funds from full exit priority operation in case of an upgrade (in seconds)
uint constant TIME_TO_WITHDRAW_FUNDS_FROM_FULL_EXIT = 2 days;
uint256 constant TIME_TO_WITHDRAW_FUNDS_FROM_FULL_EXIT = 2 days;

/// @notice Notice period before activation preparation status of upgrade mode (in seconds)
// NOTE: we must reserve for users enough time to send full exit operation, wait maximum time for processing this operation and withdraw funds from it.
uint constant UPGRADE_NOTICE_PERIOD =
uint256 constant UPGRADE_NOTICE_PERIOD =
MASS_FULL_EXIT_PERIOD + PRIORITY_EXPIRATION_PERIOD + TIME_TO_WITHDRAW_FUNDS_FROM_FULL_EXIT;
}
2 changes: 1 addition & 1 deletion contracts/contracts/DeployFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ contract DeployFactory is TokenDeployInit {
address _finalGovernor
) internal {
address[] memory tokens = getTokens();
for (uint i = 0; i < tokens.length; ++i) {
for (uint256 i = 0; i < tokens.length; ++i) {
_governance.addToken(tokens[i]);
}
_governance.setValidator(_validator, true);
Expand Down
14 changes: 7 additions & 7 deletions contracts/contracts/Events.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface Events {
uint64 serialId,
Operations.OpType opType,
bytes pubData,
uint expirationBlock
uint256 expirationBlock
);

/// @notice Deposit committed event.
Expand Down Expand Up @@ -67,21 +67,21 @@ interface Events {
/// @author Matter Labs
interface UpgradeEvents {
/// @notice Event emitted when new upgradeable contract is added to upgrade gatekeeper's list of managed contracts
event NewUpgradable(uint indexed versionId, address indexed upgradeable);
event NewUpgradable(uint256 indexed versionId, address indexed upgradeable);

/// @notice Upgrade mode enter event
event NoticePeriodStart(
uint indexed versionId,
uint256 indexed versionId,
address[] newTargets,
uint noticePeriod // notice period (in seconds)
uint256 noticePeriod // notice period (in seconds)
);

/// @notice Upgrade mode cancel event
event UpgradeCancel(uint indexed versionId);
event UpgradeCancel(uint256 indexed versionId);

/// @notice Upgrade mode preparation status event
event PreparationStart(uint indexed versionId);
event PreparationStart(uint256 indexed versionId);

/// @notice Upgrade mode complete event
event UpgradeComplete(uint indexed versionId, address[] newTargets);
event UpgradeComplete(uint256 indexed versionId, address[] newTargets);
}
Loading

0 comments on commit 588f1b4

Please sign in to comment.