Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Nov 18, 2020
1 parent bcc8fca commit f1ab61e
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 67 deletions.
3 changes: 2 additions & 1 deletion contracts/contracts/Config.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ contract Config {
uint256 constant CHANGE_PUBKEY_BYTES = 6 * CHUNK_BYTES;

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

/// @dev Expiration delta for priority request to be satisfied (in ETH blocks)
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/Operations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ library Operations {
returns (PartialExit memory parsed)
{
// NOTE: there is no check that variable sizes are same as constants (i.e. TOKEN_BYTES), fix if possible.
uint offset = OP_TYPE_BYTES + ACCOUNT_ID_BYTES; // opType + accountId (ignored)
uint offset = OP_TYPE_BYTES + ACCOUNT_ID_BYTES; // opType + accountId (ignored)
(offset, parsed.tokenId) = Bytes.readUInt16(_data, offset); // tokenId
(offset, parsed.amount) = Bytes.readUInt128(_data, offset); // amount
offset += FEE_BYTES; // fee (ignored)
Expand All @@ -177,7 +177,7 @@ library Operations {
returns (ForcedExit memory parsed)
{
// NOTE: there is no check that variable sizes are same as constants (i.e. TOKEN_BYTES), fix if possible.
uint offset = OP_TYPE_BYTES + ACCOUNT_ID_BYTES * 2; // opType + initiatorAccountId + targetAccountId (ignored)
uint offset = OP_TYPE_BYTES + ACCOUNT_ID_BYTES * 2; // opType + initiatorAccountId + targetAccountId (ignored)
(offset, parsed.tokenId) = Bytes.readUInt16(_data, offset); // tokenId
(offset, parsed.amount) = Bytes.readUInt128(_data, offset); // amount
offset += FEE_BYTES; // fee (ignored)
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/Ownable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract Ownable {
}

/// @notice Returns contract masters address
/// @return master Masters address
/// @return master Master's address
function getMaster() public view returns (address master) {
bytes32 position = masterPosition;
assembly {
Expand All @@ -32,7 +32,7 @@ contract Ownable {
}

/// @dev Sets new masters address
/// @param _newMaster New masters address
/// @param _newMaster New master's address
function setMaster(address _newMaster) internal {
bytes32 position = masterPosition;
assembly {
Expand Down
15 changes: 11 additions & 4 deletions contracts/contracts/Storage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ contract Storage {
/// @dev Governance contract. Contains the governor (the owner) of whole system, validators list, possible tokens list
Governance public governance;

uint8 constant FILLED_GAS_RESERVE_VALUE = 0xff; // we use it to set gas revert value so slot will not be emptied with 0 balance
struct BalanceToWithdraw {
uint128 balanceToWithdraw;
uint8 gasReserveValue; // gives user opportunity to fill storage slot with nonzero value
Expand Down Expand Up @@ -126,23 +127,29 @@ contract Storage {
}

/// @Rollup block stored data - not used in current version
/// @member blockNumber Rollup block number
/// @member priorityOperations Number of priority operations processed
/// @member pendingOnchainOperationsHash Hash of all operations that must be processed after verify
/// @member timestamp Rollup block timestamp, have the same format as Ethereum block constant
/// @member stateHash Root hash of the rollup state
/// @member commitment Verified input for the zkSync circuit
struct StoredBlockInfo {
uint32 blockNumber;
uint64 priorityOperations;
bytes32 processableOnchainOperationsHash;
bytes32 pendingOnchainOperationsHash;
uint256 timestamp;
bytes32 stateHash;
bytes32 commitment;
}

/// @notice Hash StoredBlockInfo
/// @notice Returns the keccak hash of the ABI-encoded StoredBlockInfo
function hashStoredBlockInfo(StoredBlockInfo memory _storedBlockInfo) internal pure returns (bytes32) {
return keccak256(abi.encode(_storedBlockInfo));
}

/// @notice Stored hashed StoredBlockInfo for some block number
mapping(uint32 => bytes32) public hashedBlocks;
mapping(uint32 => bytes32) public storedBlockHashes;

/// @notice Stores verified commitments hashed in one slot.
mapping(bytes32 => bool) public hashedVerifiedCommitments;
mapping(bytes32 => bool) public verifiedCommitmentHashes;
}
8 changes: 4 additions & 4 deletions contracts/contracts/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ library Utils {

/// @notice Recovers signer's address from ethereum signature for given message
/// @param _signature 65 bytes concatenated. R (32) + S (32) + V (1)
/// @param _message signed message hash.
/// @param _messageHash signed message hash.
/// @return address of the signer
function recoverAddressFromEthSignature(bytes memory _signature, bytes32 _message) internal pure returns (address) {
function recoverAddressFromEthSignature(bytes memory _signature, bytes32 _messageHash) internal pure returns (address) {
require(_signature.length == 65, "ves10"); // incorrect signature length

bytes32 signR;
Expand All @@ -76,11 +76,11 @@ library Utils {
(offset, signS) = Bytes.readBytes32(_signature, offset);
uint8 signV = uint8(_signature[offset]);

return ecrecover(_message, signV, signR, signS);
return ecrecover(_messageHash, signV, signR, signS);
}

/// @notice Returns new_hash = hash(old_hash + bytes)
function addBytesToHash(bytes32 _hash, bytes memory _bytes) internal pure returns (bytes32) {
function concatHash(bytes32 _hash, bytes memory _bytes) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(_hash, _bytes));
}
}
Loading

0 comments on commit f1ab61e

Please sign in to comment.