Skip to content

Commit

Permalink
update franklin-crypto, regen keys, xor -> or
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Jan 25, 2021
1 parent 64d8331 commit 30cf761
Show file tree
Hide file tree
Showing 47 changed files with 256 additions and 311 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

6 changes: 3 additions & 3 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-etherscan": "^2.0.1",
"@nomiclabs/hardhat-etherscan": "^2.1.0",
"@nomiclabs/hardhat-solpp": "^2.0.0",
"@nomiclabs/hardhat-waffle": "^2.0.0",
"@openzeppelin/contracts": "3.2.1-solc-0.7",
Expand All @@ -16,12 +16,13 @@
"axios": "^0.21.0",
"chai": "^4.2.0",
"chalk": "^4.1.0",
"commander": "^6.0.0",
"ethereum-waffle": "^3.0.0",
"ethereumjs-abi": "^0.6.8",
"ethers": "^5.0.0",
"ethjs": "^0.4.0",
"fs": "^0.0.1-security",
"hardhat": "^2.0.2",
"hardhat": "^2.0.8",
"hardhat-contract-sizer": "^2.0.2",
"hardhat-typechain": "^0.3.3",
"mocha": "^6.2.0",
Expand All @@ -34,7 +35,6 @@
"ts-node": "^9.0.0",
"typechain": "^4.0.0",
"typescript": "^4.0.5",
"commander": "^6.0.0",
"zksync": "link:../sdk/zksync.js"
},
"scripts": {
Expand Down
6 changes: 2 additions & 4 deletions core/bin/data_restore/src/contract/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ mod test {
20u32.into(),
20u32.into(),
3,
0,
u32::MAX,
Default::default(),
None,
);
let op1 = ZkSyncOp::TransferToNew(Box::new(TransferToNewOp {
Expand All @@ -209,8 +208,7 @@ mod test {
20u32.into(),
10u32.into(),
3,
0,
u32::MAX,
Default::default(),
None,
);
let op1 = ZkSyncOp::Transfer(Box::new(TransferOp {
Expand Down
12 changes: 4 additions & 8 deletions core/bin/data_restore/src/tree_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,7 @@ mod test {
BigUint::from(40u32),
BigUint::from(1u32),
3,
0,
u32::MAX,
Default::default(),
None,
);
let op3 = ZkSyncOp::TransferToNew(Box::new(TransferToNewOp {
Expand All @@ -521,8 +520,7 @@ mod test {
BigUint::from(19u32),
BigUint::from(1u32),
1,
0,
u32::MAX,
Default::default(),
None,
);
let op4 = ZkSyncOp::Transfer(Box::new(TransferOp {
Expand Down Expand Up @@ -715,8 +713,7 @@ mod test {
BigUint::from(40u32),
BigUint::from(1u32),
3,
0,
u32::MAX,
Default::default(),
None,
);
let op3 = ZkSyncOp::TransferToNew(Box::new(TransferToNewOp {
Expand All @@ -734,8 +731,7 @@ mod test {
BigUint::from(19u32),
BigUint::from(1u32),
1,
0,
u32::MAX,
Default::default(),
None,
);
let op4 = ZkSyncOp::Transfer(Box::new(TransferOp {
Expand Down
9 changes: 3 additions & 6 deletions core/bin/zksync_api/src/api_server/rest/v1/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ impl TestServerConfig {
&to.address,
None,
false,
0,
u32::MAX,
Default::default(),
)
.0;

Expand Down Expand Up @@ -169,8 +168,7 @@ impl TestServerConfig {
&to.address,
None,
false,
0,
u32::MAX,
Default::default(),
)
.0;

Expand Down Expand Up @@ -205,8 +203,7 @@ impl TestServerConfig {
2_u64.into(),
fee.into(),
0,
0,
u32::MAX,
Default::default(),
None,
);

Expand Down
3 changes: 1 addition & 2 deletions core/bin/zksync_api/src/api_server/rest/v1/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,7 @@ mod tests {
&to.address,
None,
false,
0,
u32::MAX,
Default::default(),
);
client
.submit_tx(
Expand Down
10 changes: 0 additions & 10 deletions core/bin/zksync_api/src/api_server/tx_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,6 @@ impl TxSender {
withdraw.fast = fast_processing;
}

if let ZkSyncTx::Transfer(transfer) = &mut tx {
let valid_from = transfer.valid_from.unwrap_or(0);
let valid_until = transfer.valid_until.unwrap_or(u32::MAX);
if valid_from > valid_until {
return Err(SubmitError::IncorrectTx(
"Incorrect time segment when transfer execution is valid".to_string(),
));
}
}

let msg_to_sign = self.tx_message_to_sign(&tx).await?;

let tx_fee_info = tx.get_fee_info();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ impl MempoolTransactionsQueue {
mod tests {
use super::*;
use crate::mempool::Address;
use zksync_types::tx::{Transfer, Withdraw};
use zksync_types::tx::{TimeRange, Transfer, Withdraw};

fn get_transfer_with_timestamps(valid_from: u32, valid_until: u32) -> SignedTxVariant {
fn get_transfer_with_timestamps(valid_from: u64, valid_until: u64) -> SignedTxVariant {
let transfer = Transfer::new(
4242,
Address::random(),
Expand All @@ -116,8 +116,7 @@ mod tests {
500u32.into(),
20u32.into(),
11,
valid_from,
valid_until,
TimeRange::new(valid_from, valid_until),
None,
);

Expand Down
8 changes: 5 additions & 3 deletions core/bin/zksync_core/src/state_keeper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,13 +703,15 @@ impl ZkSyncStateKeeper {
) -> Result<(), anyhow::Error> {
match tx {
ZkSyncTx::Transfer(tx) => {
let valid_from = u64::from(tx.valid_from.unwrap_or(0));
let valid_until = u64::from(tx.valid_until.unwrap_or(u32::MAX));
let time_range = tx.time_range.unwrap_or_default();
ensure!(
valid_from <= block_timestamp && block_timestamp <= valid_until,
time_range.is_valid(block_timestamp),
"The transaction can't be executed in the block because of an invalid timestamp"
);
}
ZkSyncTx::Withdraw(tx) => {
// todo!("should check withdraw tx here too")
}
_ => {
// There are no timestamps in other transactions
}
Expand Down
24 changes: 13 additions & 11 deletions core/bin/zksync_core/src/state_keeper/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ fn create_account_and_transfer<B: Into<BigUint>>(
account_id: AccountId,
balance: B,
transfer_amount: B,
valid_from: u32,
valid_until: u32,
) -> SignedZkSyncTx {
let (account, sk) = tester.add_account(account_id);
tester.set_balance(account_id, token_id, balance);
Expand All @@ -104,8 +102,7 @@ fn create_account_and_transfer<B: Into<BigUint>>(
transfer_amount.into(),
BigUint::from(1u32),
account.nonce,
valid_from,
valid_until,
Default::default(),
&sk,
)
.unwrap();
Expand Down Expand Up @@ -210,7 +207,7 @@ pub fn create_deposit(token: TokenId, amount: impl Into<BigUint>) -> PriorityOp
}

async fn apply_single_transfer(tester: &mut StateKeeperTester) {
let transfer = create_account_and_transfer(tester, 0, 1, 200u32, 100u32, 0, u32::MAX);
let transfer = create_account_and_transfer(tester, 0, 1, 200u32, 100u32);
let proposed_block = ProposedBlock {
txs: vec![SignedTxVariant::Tx(transfer)],
priority_ops: Vec::new(),
Expand All @@ -222,8 +219,8 @@ async fn apply_single_transfer(tester: &mut StateKeeperTester) {
}

async fn apply_batch_with_two_transfers(tester: &mut StateKeeperTester) {
let first_transfer = create_account_and_transfer(tester, 0, 1, 200u32, 100u32, 0, u32::MAX);
let second_transfer = create_account_and_transfer(tester, 0, 2, 200u32, 100u32, 0, u32::MAX);
let first_transfer = create_account_and_transfer(tester, 0, 1, 200u32, 100u32);
let second_transfer = create_account_and_transfer(tester, 0, 2, 200u32, 100u32);
let proposed_block = ProposedBlock {
txs: vec![SignedTxVariant::Batch(SignedTxsBatch {
txs: vec![first_transfer, second_transfer],
Expand Down Expand Up @@ -998,17 +995,22 @@ mod execute_proposed_block {
balance.into(),
fee.into(),
0,
0,
u32::MAX,
Default::default(),
&sk_from,
)
.unwrap();

let mut premature_transfer = correct_transfer.clone();
premature_transfer.valid_from = Some(u32::MAX);
premature_transfer
.time_range
.as_mut()
.map(|t| t.valid_from = u64::max_value());

let mut belated_transfer = correct_transfer.clone();
belated_transfer.valid_until = Some(0);
belated_transfer
.time_range
.as_mut()
.map(|t| t.valid_until = 0);

let correct_transfer = SignedZkSyncTx {
tx: ZkSyncTx::Transfer(Box::new(correct_transfer)),
Expand Down
9 changes: 3 additions & 6 deletions core/lib/circuit/benches/criterion/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ fn transfer_apply_tx(b: &mut Bencher<'_>, number_of_accounts: &usize) {
&account_to.account.address,
None,
true,
0,
u32::MAX,
Default::default(),
)
.0,
from: account_from.id,
Expand Down Expand Up @@ -57,8 +56,7 @@ fn transfer_get_pubdata(b: &mut Bencher<'_>) {
&account_to.account.address,
None,
true,
0,
u32::MAX,
Default::default(),
)
.0,
from: account_from.id,
Expand Down Expand Up @@ -88,8 +86,7 @@ fn transfer_calculate_operations(b: &mut Bencher<'_>) {
&account_to.account.address,
None,
true,
0,
u32::MAX,
Default::default(),
)
.0,
from: account_from.id,
Expand Down
9 changes: 3 additions & 6 deletions core/lib/circuit/benches/criterion/transfer_to_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ fn transfer_to_new_apply_tx(b: &mut Bencher<'_>, number_of_accounts: &usize) {
&account_to.account.address,
None,
true,
0,
u32::MAX,
Default::default(),
)
.0,
from: account_from.id,
Expand Down Expand Up @@ -58,8 +57,7 @@ fn transfer_to_new_get_pubdata(b: &mut Bencher<'_>) {
&account_to.account.address,
None,
true,
0,
u32::MAX,
Default::default(),
)
.0,
from: account_from.id,
Expand Down Expand Up @@ -89,8 +87,7 @@ fn transfer_to_new_calculate_operations(b: &mut Bencher<'_>) {
&account_to.account.address,
None,
true,
0,
u32::MAX,
Default::default(),
)
.0,
from: account_from.id,
Expand Down
20 changes: 8 additions & 12 deletions core/lib/circuit/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,10 +1147,9 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
&op_data,
)?;

let is_serialized_tx_correct = Boolean::xor(
let is_serialized_tx_correct = multi_or(
cs.namespace(|| "is_serialized_tx_correct"),
&is_new_serialized_tx_correct,
&is_old_serialized_tx_correct,
&[is_new_serialized_tx_correct, is_old_serialized_tx_correct],
)?;
let is_signed_correctly = multi_and(
cs.namespace(|| "is_signed_correctly"),
Expand Down Expand Up @@ -1619,10 +1618,9 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
&op_data,
)?;

let is_serialized_tx_correct = Boolean::xor(
let is_serialized_tx_correct = multi_or(
cs.namespace(|| "is_serialized_tx_correct"),
&is_new_serialized_tx_correct,
&is_old_serialized_tx_correct,
&[is_new_serialized_tx_correct, is_old_serialized_tx_correct],
)?;

let (is_equal_pubdata, packed_pubdata) = vectorized_compare(
Expand Down Expand Up @@ -1982,10 +1980,9 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
&op_data,
)?;

let is_serialized_tx_correct = Boolean::xor(
let is_serialized_tx_correct = multi_or(
cs.namespace(|| "old_or_new_signature_correct"),
&is_new_serialized_tx_correct,
&is_old_serialized_tx_correct,
&[is_new_serialized_tx_correct, is_old_serialized_tx_correct],
)?;

log::debug!(
Expand Down Expand Up @@ -2252,10 +2249,9 @@ impl<'a, E: RescueEngine + JubjubEngine> ZkSyncCircuit<'a, E> {
&op_data,
)?;

let is_serialized_tx_correct = Boolean::xor(
let is_serialized_tx_correct = multi_or(
cs.namespace(|| "is_serialized_tx_correct"),
&is_new_serialized_tx_correct,
&is_old_serialized_tx_correct,
&[is_new_serialized_tx_correct, is_old_serialized_tx_correct],
)?;
lhs_valid_flags.push(is_serialized_tx_correct);

Expand Down
Loading

0 comments on commit 30cf761

Please sign in to comment.