Skip to content

Commit

Permalink
u32 instead of u64 for timestamp in server
Browse files Browse the repository at this point in the history
  • Loading branch information
Barichek committed Jan 13, 2021
1 parent c369167 commit e6550d8
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions core/lib/circuit/src/witness/tests/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@ fn test_transfer_replay() {
/// Basic check for execution of `Transfer` operation in circuit with incorrect timestamps.
#[test]
#[ignore]
fn test_incorrect_transfer_timestamps() {
fn test_incorrect_transfer_timestamp() {
// Test vector of (initial_balance, transfer_amount, fee_amount, valid_from, valid_until).
let test_vector = vec![
(10u64, 7u64, 3u64, 0, 0), // Basic transfer
(0, 0, 0, 0, 0), // Zero transfer
(std::u64::MAX, 1, 1, 0, 0), // Small transfer from rich account,
(std::u64::MAX, 10000, 1, u64::MAX, u64::MAX), // Big transfer from rich account (too big values can't be used, since they're not packable),
(std::u64::MAX, 1, 10000, u64::MAX, u64::MAX), // Very big fee
(std::u64::MAX, 10000, 1, u32::MAX, u32::MAX), // Big transfer from rich account (too big values can't be used, since they're not packable),
(std::u64::MAX, 1, 10000, u32::MAX, u32::MAX), // Very big fee
];

for (initial_balance, transfer_amount, fee_amount, valid_from, valid_until) in test_vector {
Expand All @@ -443,9 +443,9 @@ fn test_incorrect_transfer_timestamps() {
BigUint::from(fee_amount),
&account_to.account.address,
None,
true,
valid_from,
valid_until,
true,
)
.0,
from: account_from.id,
Expand Down
8 changes: 4 additions & 4 deletions core/lib/circuit/src/witness/tests/transfer_to_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,14 @@ fn test_transfer_replay() {
/// Basic check for execution of `TransferToNew` operation in circuit with incorrect timestamps.
#[test]
#[ignore]
fn test_incorrect_transfer_to_new_timestamps() {
fn test_incorrect_transfer_to_new_timestamp() {
// Test vector of (initial_balance, transfer_amount, fee_amount, valid_from, valid_until).
let test_vector = vec![
(10u64, 7u64, 3u64, 0, 0), // Basic transfer
(0, 0, 0, 0, 0), // Zero transfer
(std::u64::MAX, 1, 1, 0, 0), // Small transfer from rich account,
(std::u64::MAX, 10000, 1, u64::MAX, u64::MAX), // Big transfer from rich account (too big values can't be used, since they're not packable),
(std::u64::MAX, 1, 10000, u64::MAX, u64::MAX), // Very big fee
(std::u64::MAX, 10000, 1, u32::MAX, u32::MAX), // Big transfer from rich account (too big values can't be used, since they're not packable),
(std::u64::MAX, 1, 10000, u32::MAX, u32::MAX), // Very big fee
];

for (initial_balance, transfer_amount, fee_amount, valid_from, valid_until) in test_vector {
Expand All @@ -399,9 +399,9 @@ fn test_incorrect_transfer_to_new_timestamps() {
BigUint::from(fee_amount),
&account_to.account.address,
None,
true,
valid_from,
valid_until,
true,
)
.0,
from: account_from.id,
Expand Down
6 changes: 3 additions & 3 deletions core/lib/circuit/src/witness/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub struct TransferData {
pub token: u32,
pub from_account_address: u32,
pub to_account_address: u32,
pub valid_from: u64,
pub valid_until: u64,
pub valid_from: u32,
pub valid_until: u32,
}

pub struct TransferWitness<E: RescueEngine> {
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Witness for TransferWitness<Bn256> {
from_account_address: transfer.from,
to_account_address: transfer.to,
valid_from: transfer.tx.valid_from.unwrap_or(0),
valid_until: transfer.tx.valid_until.unwrap_or(u64::MAX),
valid_until: transfer.tx.valid_until.unwrap_or(u32::MAX),
};
// le_bit_vector_into_field_element()
Self::apply_data(tree, &transfer_data)
Expand Down
6 changes: 3 additions & 3 deletions core/lib/circuit/src/witness/transfer_to_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub struct TransferToNewData {
pub from_account_address: u32,
pub to_account_address: u32,
pub new_address: Fr,
pub valid_from: u64,
pub valid_until: u64,
pub valid_from: u32,
pub valid_until: u32,
}

pub struct TransferToNewWitness<E: RescueEngine> {
Expand Down Expand Up @@ -69,7 +69,7 @@ impl Witness for TransferToNewWitness<Bn256> {
to_account_address: transfer_to_new.to,
new_address: eth_address_to_fr(&transfer_to_new.tx.to),
valid_from: transfer_to_new.tx.valid_from.unwrap_or(0),
valid_until: transfer_to_new.tx.valid_until.unwrap_or(u64::MAX),
valid_until: transfer_to_new.tx.valid_until.unwrap_or(u32::MAX),
};
// le_bit_vector_into_field_element()
Self::apply_data(tree, &transfer_data)
Expand Down
2 changes: 1 addition & 1 deletion core/lib/crypto/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn used_account_subtree_depth() -> usize {
/// Max token id, based on the depth of the used left subtree
pub fn max_account_id() -> AccountId {
let list_count = 2u32.saturating_pow(used_account_subtree_depth() as u32);
if list_count == u32::max_value() {
if list_count == u32::MAX {
list_count
} else {
list_count - 1
Expand Down
2 changes: 1 addition & 1 deletion core/lib/storage/src/chain/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl<'a, 'c> BlockSchema<'a, 'c> {
idx
} else {
// failed operations are at the end.
u32::max_value()
u32::MAX
}
}
ExecutedOperations::PriorityOp(op) => op.block_index,
Expand Down
4 changes: 2 additions & 2 deletions core/lib/storage/src/chain/operations_ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,11 @@ impl<'a, 'c> OperationsExtSchema<'a, 'c> {
let (block_id, block_tx_id) = tx_id;
let (block_number_start_idx, block_number_end_idx) = match direction {
SearchDirection::Older => (0i64, block_id as i64 - 1), // Older blocks have lesser block ID.
SearchDirection::Newer => (block_id as i64 + 1, i64::max_value()), // Newer blocks have greater block ID.
SearchDirection::Newer => (block_id as i64 + 1, i64::MAX), // Newer blocks have greater block ID.
};
let (tx_number_start_idx, tx_number_end_idx) = match direction {
SearchDirection::Older => (0i32, block_tx_id as i32 - 1),
SearchDirection::Newer => (block_tx_id as i32 + 1, i32::max_value()),
SearchDirection::Newer => (block_tx_id as i32 + 1, i32::MAX),
};

// This query does the following:
Expand Down
2 changes: 1 addition & 1 deletion core/lib/types/src/tx/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl Transfer {
&& self.account_id <= max_account_id()
&& self.token <= max_token_id()
&& self.to != Address::zero()
&& self.valid_from.unwrap_or(0) <= self.valid_until.unwrap_or(u64::MAX);
&& self.valid_from.unwrap_or(0) <= self.valid_until.unwrap_or(u32::MAX);
if valid {
let signer = self.verify_signature();
valid = valid && signer.is_some();
Expand Down

0 comments on commit e6550d8

Please sign in to comment.