Skip to content

Instantly share code, notes, and snippets.

@gluk64
Created July 2, 2020 13:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gluk64/72125093c00987db81bbe88e30a03427 to your computer and use it in GitHub Desktop.
Save gluk64/72125093c00987db81bbe88e30a03427 to your computer and use it in GitHub Desktop.
contracts.diff
diff --git a/contracts/contracts/Config.sol b/contracts/contracts/Config.sol
index 6fdba645..cc3c77c6 100644
--- a/contracts/contracts/Config.sol
+++ b/contracts/contracts/Config.sol
@@ -44,7 +44,9 @@ contract Config {
uint256 constant BLOCK_PERIOD = 15 seconds;
/// @notice ETH blocks verification expectation
- uint256 constant EXPECT_VERIFICATION_IN = 3 hours / BLOCK_PERIOD;
+ /// 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.
+ uint256 constant EXPECT_VERIFICATION_IN = 0 hours / BLOCK_PERIOD;
uint256 constant NOOP_BYTES = 1 * CHUNK_BYTES;
uint256 constant DEPOSIT_BYTES = 6 * CHUNK_BYTES;
diff --git a/contracts/contracts/Events.sol b/contracts/contracts/Events.sol
index a5de3260..83103ed0 100644
--- a/contracts/contracts/Events.sol
+++ b/contracts/contracts/Events.sol
@@ -54,21 +54,37 @@ interface Events {
uint256 expirationBlock
);
+ /// @notice Deposit committed event.
event DepositCommit(
- uint32 indexed franklinBlockId,
+ uint32 indexed zkSyncBlockId,
uint32 indexed accountId,
address owner,
uint16 indexed tokenId,
uint128 amount
);
+ /// @notice Full exit committed event.
event FullExitCommit(
- uint32 indexed franklinBlockId,
+ uint32 indexed zkSyncBlockId,
uint32 indexed accountId,
address owner,
uint16 indexed tokenId,
uint128 amount
);
+
+ /// @notice Pending withdrawals index range that were added in the verifyBlock operation.
+ /// NOTE: processed indexes in the queue map are [queueStartIndex, queueEndIndex)
+ event PendingWithdrawalsAdd(
+ uint32 queueStartIndex,
+ uint32 queueEndIndex
+ );
+
+ /// @notice Pending withdrawals index range that were executed in the completeWithdrawals operation.
+ /// NOTE: processed indexes in the queue map are [queueStartIndex, queueEndIndex)
+ event PendingWithdrawalsComplete(
+ uint32 queueStartIndex,
+ uint32 queueEndIndex
+ );
}
/// @title Upgrade events
diff --git a/contracts/contracts/Utils.sol b/contracts/contracts/Utils.sol
index eae48558..76c32097 100644
--- a/contracts/contracts/Utils.sol
+++ b/contracts/contracts/Utils.sol
@@ -30,6 +30,23 @@ library Utils {
return callSuccess && returnedSuccess;
}
+ /// @notice Transfers token from one address to another
+ /// @dev NOTE: this function handles tokens that have transfer function not strictly compatible with ERC20 standard
+ /// @dev NOTE: call `transferFrom` to this token may return (bool) or nothing
+ /// @param _token Token address
+ /// @param _from Address of sender
+ /// @param _to Address of recipient
+ /// @param _amount Amount of tokens to transfer
+ /// @return bool flag indicating that transfer is successful
+ function transferFromERC20(IERC20 _token, address _from, address _to, uint256 _amount) internal returns (bool) {
+ (bool callSuccess, bytes memory callReturnValueEncoded) = address(_token).call(
+ abi.encodeWithSignature("transferFrom(address,address,uint256)", _from, _to, _amount)
+ );
+ // `transferFrom` method may return (bool) or nothing.
+ bool returnedSuccess = callReturnValueEncoded.length == 0 || abi.decode(callReturnValueEncoded, (bool));
+ return callSuccess && returnedSuccess;
+ }
+
/// @notice Sends ETH
/// @param _to Address of recipient
/// @param _amount Amount of tokens to transfer
diff --git a/contracts/contracts/ZkSync.sol b/contracts/contracts/ZkSync.sol
index 3cb2f8a6..4a26e78f 100644
--- a/contracts/contracts/ZkSync.sol
+++ b/contracts/contracts/ZkSync.sol
@@ -138,6 +138,9 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
}
}
}
+ if (toProcess > 0) {
+ emit PendingWithdrawalsComplete(startIndex, startIndex + toProcess);
+ }
}
/// @notice Accrues users balances from deposit priority requests in Exodus mode
@@ -186,7 +189,7 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
uint16 tokenId = governance.validateTokenAddress(address(_token));
uint256 balance_before = _token.balanceOf(address(this));
- require(_token.transferFrom(msg.sender, address(this), SafeCast.toUint128(_amount)), "fd012"); // token transfer failed deposit
+ require(Utils.transferFromERC20(_token, msg.sender, address(this), SafeCast.toUint128(_amount)), "fd012"); // token transfer failed deposit
uint256 balance_after = _token.balanceOf(address(this));
uint128 deposit_amount = SafeCast.toUint128(balance_after.sub(balance_before));
@@ -686,8 +689,11 @@ contract ZkSync is UpgradeableMaster, Storage, Config, Events, ReentrancyGuard {
withdrawalsDataHash = keccak256(abi.encode(withdrawalsDataHash, addToPendingWithdrawalsQueue, _to, _tokenId, _amount));
offset += ONCHAIN_WITHDRAWAL_BYTES;
}
- numberOfPendingWithdrawals = localNumberOfPendingWithdrawals;
require(withdrawalsDataHash == expectedWithdrawalsDataHash, "pow12"); // pow12 - withdrawals data hash not matches with expected value
+ if (numberOfPendingWithdrawals != localNumberOfPendingWithdrawals) {
+ emit PendingWithdrawalsAdd(firstPendingWithdrawalIndex + numberOfPendingWithdrawals, firstPendingWithdrawalIndex + localNumberOfPendingWithdrawals);
+ }
+ numberOfPendingWithdrawals = localNumberOfPendingWithdrawals;
}
/// @notice Checks whether oldest unverified block has expired
diff --git a/contracts/contracts/test/tokens/MintableERC20NoTransferReturnValueTest.sol b/contracts/contracts/test/tokens/MintableERC20NoTransferReturnValueTest.sol
index 3c0817c1..6b97c798 100644
--- a/contracts/contracts/test/tokens/MintableERC20NoTransferReturnValueTest.sol
+++ b/contracts/contracts/test/tokens/MintableERC20NoTransferReturnValueTest.sol
@@ -98,10 +98,9 @@ contract MintableERC20NoTransferReturnValueTest is ContextTest, MintableIERC20No
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
- function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
+ function transferFrom(address sender, address recipient, uint256 amount) public {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
- return true;
}
/**
diff --git a/contracts/contracts/test/tokens/MintableIERC20NoTransferReturnValueTest.sol b/contracts/contracts/test/tokens/MintableIERC20NoTransferReturnValueTest.sol
index 38ecf894..bf2c11ce 100644
--- a/contracts/contracts/test/tokens/MintableIERC20NoTransferReturnValueTest.sol
+++ b/contracts/contracts/test/tokens/MintableIERC20NoTransferReturnValueTest.sol
@@ -61,7 +61,7 @@ interface MintableIERC20NoTransferReturnValueTest {
*
* Emits a {Transfer} event.
*/
- function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
+ function transferFrom(address sender, address recipient, uint256 amount) external;
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment