Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:matter-labs/zksync-dev into fk/325-l…
Browse files Browse the repository at this point in the history
…eader-election
  • Loading branch information
furkhat committed Apr 17, 2020
2 parents a25aa34 + dfbe8b4 commit c04cbfd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 31 deletions.
4 changes: 3 additions & 1 deletion core/models/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ pub fn account_tree_depth() -> usize {

unsafe {
if ACCOUNT_TREE_DEPTH_VALUE == 0 {
let value: &'static str = env!("ACCOUNT_TREE_DEPTH");
let value: &'static str = option_env!("ACCOUNT_TREE_DEPTH")
.expect("ACCOUNT_TREE_DEPTH variable was not set during compilation. \
Make sure that ACCOUNT_TREE_DEPTH is set in `dev.env` file and recompile the project");
ACCOUNT_TREE_DEPTH_VALUE =
usize::from_str(value).expect("account tree depth value is invalid");
let runtime_value = env::var("ACCOUNT_TREE_DEPTH").expect("ACCOUNT_TREE_DEPTH missing");
Expand Down
10 changes: 5 additions & 5 deletions core/server/src/eth_watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub enum EthWatchRequest {
},
CheckEIP1271Signature {
address: Address,
data: Vec<u8>,
message: Vec<u8>,
signature: EIP1271Signature,
resp: oneshot::Sender<Result<bool, failure::Error>>,
},
Expand Down Expand Up @@ -305,14 +305,14 @@ impl<T: Transport> EthWatch<T> {
async fn is_eip1271_signature_correct(
&self,
address: Address,
data: Vec<u8>,
message: Vec<u8>,
signature: EIP1271Signature,
) -> Result<bool, failure::Error> {
let received: [u8; 4] = self
.get_eip1271_contract(address)
.query(
"isValidSignature",
(data, signature.0),
(message, signature.0),
None,
Options::default(),
None,
Expand Down Expand Up @@ -399,12 +399,12 @@ impl<T: Transport> EthWatch<T> {
}
EthWatchRequest::CheckEIP1271Signature {
address,
data,
message,
signature,
resp,
} => {
let signature_correct = self
.is_eip1271_signature_correct(address, data, signature)
.is_eip1271_signature_correct(address, message, signature)
.await;

resp.send(signature_correct).unwrap_or_default();
Expand Down
4 changes: 3 additions & 1 deletion core/server/src/signature_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ async fn verify_eth_signature(
}
}
TxEthSignature::EIP1271Signature(signature) => {
let message = format!("\x19Ethereum Signed Message:\n{}{}", message.len(), message);

let eth_watch_resp = oneshot::channel();
eth_watch_req
.clone()
.send(EthWatchRequest::CheckEIP1271Signature {
address: request.tx.account(),
data: message.as_bytes().to_vec(),
message: message.into_bytes(),
signature: signature.clone(),
resp: eth_watch_resp.0,
})
Expand Down
30 changes: 10 additions & 20 deletions core/storage/src/chain/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,26 +358,16 @@ impl<'a> BlockSchema<'a> {
) -> QueryResult<Vec<(Operation, bool)>> {
self.0.conn().transaction(|| {
let ops: Vec<(StoredOperation, Option<StoredProof>)> = diesel::sql_query(format!(
"
WITH sized_operations AS (
SELECT operations.*, proofs.*, operations.block_number as the_block_number
FROM operations
LEFT JOIN blocks
ON number = block_number
LEFT JOIN proofs
USING (block_number)
)
SELECT *
FROM sized_operations
WHERE action_type = 'COMMIT'
AND the_block_number > (
SELECT COALESCE(max(the_block_number), 0)
FROM sized_operations
WHERE action_type = 'VERIFY'
)
AND the_block_number > {}
ORDER BY the_block_number
LIMIT {}
"SELECT operations.*, proofs.*
FROM operations
LEFT JOIN blocks
ON number = block_number
LEFT JOIN proofs
USING (block_number)
WHERE operations.action_type = 'COMMIT'
AND operations.block_number > {}
ORDER BY operations.block_number
LIMIT {}
",
block, limit
))
Expand Down
8 changes: 4 additions & 4 deletions core/storage/src/tests/chain/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,17 +452,17 @@ fn load_commits_after_block() {
},
Vec::new(),
))?;
ProverSchema(&conn).store_proof(2, &Default::default())?;
ProverSchema(&conn).store_proof(3, &Default::default())?;

// Now test the method.
let empty_vec = vec![];
let test_vector = vec![
// Blocks 2 & 3.
((1, 2), &operations[1..3], vec![true, false]),
((1, 2), &operations[1..3], vec![false, true]),
// Block 2.
((1, 1), &operations[1..2], vec![true]),
((1, 1), &operations[1..2], vec![false]),
// Block 3.
((2, 1), &operations[2..3], vec![false]),
((2, 1), &operations[2..3], vec![true]),
// No block (there are no blocks AFTER block 3.
((3, 1), &empty_vec, vec![]),
// Obviously none.
Expand Down

0 comments on commit c04cbfd

Please sign in to comment.