Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:matter-labs/zksync-dev into fk/125/w…
Browse files Browse the repository at this point in the history
…ithdraws
  • Loading branch information
furkhat committed Jan 22, 2020
2 parents f97f373 + f7c0417 commit d445795
Show file tree
Hide file tree
Showing 22 changed files with 720 additions and 1,448 deletions.
1 change: 1 addition & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ steps:
- export PATH=$ZKSYNC_HOME/bin:$PATH
- export CARGO_HOME=$ZKSYNC_HOME/target/cargo
- f cargo test
- zksync circuit-tests
depends_on:
- rust-checks

Expand Down
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ integration-full-exit:
price:
@node contracts/scripts/check-price.js

circuit-tests:
cargo test --no-fail-fast --release -p circuit -- --ignored

# Loadtest

run-loadtest: confirm_action
Expand Down
3 changes: 2 additions & 1 deletion bin/contracts-test.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash
set -e

. .setup_env

echo contracts-test
cd contracts
yarn test | tee ../test.log
yarn test
cd ..
19 changes: 8 additions & 11 deletions contracts/contracts/Franklin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ contract Franklin {
/// @notice Base gas for full exit transaction
uint256 constant BASE_FULL_EXIT_GAS = 170000;

/// @notice Max amount of any token must fit into uint128
uint256 constant MAX_VALUE = 2 ** 112 - 1;

/// @notice ETH blocks verification expectation
uint256 constant EXPECT_VERIFICATION_IN = 8 * 60 * 100;

Expand Down Expand Up @@ -275,8 +272,14 @@ contract Franklin {

/// @notice Accrues users balances from deposit priority requests in Exodus mode
/// @dev WARNING: Only for Exodus mode
function cancelOutstandingDepositsForExodusMode() internal {
bytes memory depositsPubData = priorityQueue.getOutstandingDeposits();
/// @dev Canceling may take several separate transactions to be completed
/// @param _number Supposed number of requests to look at
function cancelOutstandingDepositsForExodusMode(uint64 _number) external {
require(
exodusMode,
"frс11"
); // frс11 - exodus mode is not activated
bytes memory depositsPubData = priorityQueue.deletePriorityRequestsAndPopOutstandingDeposits(_number);
uint64 i = 0;
while (i < depositsPubData.length) {
bytes memory owner = Bytes.slice(depositsPubData, i, ETH_ADDR_BYTES);
Expand Down Expand Up @@ -334,11 +337,6 @@ contract Franklin {
msg.value >= fee + _amount,
"fdh11"
); // fdh11 - Not enough ETH provided

require(
_amount <= MAX_VALUE,
"fdh12"
); // fdh12 - deposit amount value is heigher than Franklin is able to process

if (msg.value != fee + _amount) {
msg.sender.transfer(msg.value-(fee + _amount));
Expand Down Expand Up @@ -876,7 +874,6 @@ contract Franklin {
function triggerExodusIfNeeded() internal returns (bool) {
if (priorityQueue.triggerExodusIfNeeded()) {
exodusMode = true;
cancelOutstandingDepositsForExodusMode();
emit ExodusMode();
return true;
} else {
Expand Down
24 changes: 18 additions & 6 deletions contracts/contracts/PriorityQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,26 @@ contract PriorityQueue {
return totalFee;
}

/// @notice Concates open (outstanding) deposit requests public data
/// @return concated deposits public data
function getOutstandingDeposits() external view returns (bytes memory depositsPubData) {
for (uint64 i = firstPriorityRequestId; i < firstPriorityRequestId + totalOpenPriorityRequests; i++) {
if (priorityRequests[i].opType == DEPOSIT_OP) {
depositsPubData = Bytes.concat(depositsPubData, priorityRequests[i].pubData);
/// @notice Concates open (outstanding) deposit requests public data up to defined deposits number
/// @dev Deletes processed requests.
/// @param _number Supposed number of open requests to look at and delete
/// @return concated deposits public data for limited number of deposits so as not to go beyond the block gas limit in the caller function
function deletePriorityRequestsAndPopOutstandingDeposits(uint64 _number) external returns (bytes memory depositsPubData) {
requireFranklin();
require(
totalOpenPriorityRequests > 0,
"pgs11"
); // pgs11 - no one priority request left
uint64 toProcess = totalOpenPriorityRequests < _number ? totalOpenPriorityRequests : _number;
for (uint64 i = 0; i < toProcess; i++) {
uint64 id = firstPriorityRequestId + i;
if (priorityRequests[id].opType == DEPOSIT_OP) {
depositsPubData = Bytes.concat(depositsPubData, priorityRequests[id].pubData);
}
delete priorityRequests[id];
}
firstPriorityRequestId += toProcess;
totalOpenPriorityRequests -= toProcess;
}

/// @notice Compares Rollup operation with corresponding priority requests' operation
Expand Down
2 changes: 1 addition & 1 deletion contracts/src.ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const priorityQueueContractSourceCode = fs.readFileSync('flat/PriorityQue
export const franklinTestContractCode = require('../build/FranklinTest');
export const verifierTestContractCode = require('../build/VerifierTest');
export const governanceTestContractCode = require('../build/GovernanceTest');
export const priorityQueueTestContractCode = require('../build/PriorityQueueTest')
export const priorityQueueTestContractCode = require('../build/PriorityQueueTest');

export async function publishSourceCodeToEtherscan(contractname, contractaddress, sourceCode, compiled, constructorParams: any[]) {
const network = process.env.ETH_NETWORK;
Expand Down
17 changes: 8 additions & 9 deletions contracts/test/fails_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ describe("PLANNED FAILS", function () {

const code3 = await provider.call(tx3, tx3.blockNumber);
const reason3 = hex_to_ascii(code3.substr(138));

expect(reason3.substring(0, 5)).equal("fd011");
console.log(" + ERC20 deposit: Wrong tx value (msg.value < fee) passed");

Expand Down Expand Up @@ -365,17 +364,22 @@ describe("PLANNED FAILS", function () {
expect(balanceToWithdraw).equal(parseEther("0"));

// Cancel first 2 deposits
const cancelTx1 = await franklinDeployedContract.cancelOutstandingDepositsForExodusMode();
const cancelTx1 = await franklinDeployedContract.cancelOutstandingDepositsForExodusMode(2);
await cancelTx1.wait();

balanceToWithdraw = await franklinDeployedContract.balancesToWithdraw(wallet.address, 0);
expect(await priorityQueueDeployedContract.totalOpenPriorityRequests()).equal(1);
expect(await priorityQueueDeployedContract.firstPriorityRequestId()).equal(2);
expect(balanceToWithdraw).equal(parseEther("19.993556"));

// Cancel last deposit
const cancelTx2 = await franklinDeployedContract.cancelOutstandingDepositsForExodusMode();
// Cancel last deposit - try 5 but there is only 1 left
const cancelTx2 = await franklinDeployedContract.cancelOutstandingDepositsForExodusMode(5);
await cancelTx2.wait();

expect(await priorityQueueDeployedContract.totalOpenPriorityRequests()).equal(0);
expect(await priorityQueueDeployedContract.firstPriorityRequestId()).equal(3);
balanceToWithdraw = await franklinDeployedContract.balancesToWithdraw(wallet.address, 0);

expect(balanceToWithdraw).equal(parseEther("29.990334"));

console.log("Deposits canceled");
Expand Down Expand Up @@ -529,7 +533,6 @@ describe("PLANNED FAILS", function () {

const code6 = await provider.call(tx6, tx6.blockNumber);
const reason6 = hex_to_ascii(code6.substr(138));

expect(reason6.substring(0, 5)).equal("fvs11");
console.log(" + Wrong priority operation - different data passed");

Expand All @@ -548,7 +551,6 @@ describe("PLANNED FAILS", function () {

const code7 = await provider.call(tx7, tx7.blockNumber);
const reason7 = hex_to_ascii(code7.substr(138));

expect(reason7.substring(0, 5)).equal("grr21");
console.log(" + Not governor passed");
});
Expand All @@ -574,7 +576,6 @@ describe("PLANNED FAILS", function () {

const code1 = await provider.call(tx1, tx1.blockNumber);
const reason1 = hex_to_ascii(code1.substr(138));

expect(reason1.substring(0, 5)).equal("fvk11");
console.log(" + Wrong verify number passed");

Expand All @@ -587,7 +588,6 @@ describe("PLANNED FAILS", function () {

const code2 = await provider.call(tx2, tx2.blockNumber);
const reason2 = hex_to_ascii(code2.substr(138));

expect(reason2.substring(0, 5)).equal("grr21");
console.log(" + Not governor passed");
});
Expand Down Expand Up @@ -636,7 +636,6 @@ describe("PLANNED FAILS", function () {

const code1 = await provider.call(prTx2, prTx2.blockNumber);
const reason1 = hex_to_ascii(code1.substr(138));

expect(reason1.substring(0, 5)).equal("pcs11");
console.log(" + Set franklin address twice will not work passed");
});
Expand Down
5 changes: 2 additions & 3 deletions contracts/test/integration_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { expect, use } from "chai";
import { solidity } from "ethereum-waffle";
import { bigNumberify, parseEther, hexlify, formatEther } from "ethers/utils";
import { createDepositPublicData, createWithdrawPublicData, createFullExitPublicData, hex_to_ascii } from "./helpers";
import { createDepositPublicData, createWithdrawPublicData, createFullExitPublicData } from "./helpers";

use(solidity);

Expand Down Expand Up @@ -113,7 +113,6 @@ describe("INTEGRATION", function () {

// Commit block with eth partial exit.
const exitValue = parseEther("0.2");

const exitBlockPublicData = createWithdrawPublicData(tokenId, hexlify(exitValue), exitWallet.address);

const partExTx = await franklinDeployedContract.commitBlock(2, 22,
Expand Down Expand Up @@ -173,7 +172,7 @@ describe("INTEGRATION", function () {

// Full exit eth
const fullExitAmount = parseEther("0.096778"); // amount after: tx value - some counted fee - exit amount
const fullExitMinusGas = parseEther("0.096047308");
const fullExitMinusGas = parseEther("0.096047605");
const accId = 0;
const pubkey = "0x0000000000000000000000000000000000000000000000000000000000000000";
const signature = Buffer.from("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "hex");
Expand Down
6 changes: 6 additions & 0 deletions core/circuit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ log = "0.4"
serde = "1.0.90"
serde_derive = "1.0.90"
serde_json = "1.0.0"

[dev-dependencies]
plasma = { path = "../plasma", version = "0.1.1" }
bigdecimal = { version = "0.1.0", features = ["serde"]}
testkit = { path = "../testkit", version = "0.1.0"}
web3 = "0.8.0"
Loading

0 comments on commit d445795

Please sign in to comment.