Skip to content

Commit

Permalink
remove op_codes of ZkLinkTxType, fix params
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred0327 committed Nov 2, 2023
1 parent d22308c commit ecaf431
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 22 deletions.
1 change: 1 addition & 0 deletions signers/src/zklink_signer/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ fn get_bits_le_fixed(fr: &Fr, size: usize) -> Vec<bool> {
}

pub fn rescue_hash_orders(msg: &[u8]) -> Vec<u8> {
assert_eq!(msg.len(), 178);
let msg_bits = bytes_into_be_bits(msg);
let hash_fr = rescue_hash_fr(msg_bits);
let hash_bits = get_bits_le_fixed(&hash_fr, 248);
Expand Down
4 changes: 3 additions & 1 deletion types/src/basic_types/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub const USED_BALANCE_SUBTREE_DEPTH: usize = 8;
pub const TOTAL_ACCOUNT_NUMBER: usize = usize::pow(2, USED_ACCOUNT_SUBTREE_DEPTH as u32);
pub const MAX_ACCOUNT_ID: AccountId = AccountId(TOTAL_ACCOUNT_NUMBER as u32 - 1);
/// The total token number and maximum token id allowed for the current zklink layer2(if not enough, modify this parameter and update circuit).
pub const TOTAL_TOKEN_NUMBER: usize = usize::pow(2, USED_BALANCE_SUBTREE_DEPTH as u32);
pub const TOTAL_TOKEN_NUMBER: usize = 65536;
pub const MAX_TOKEN_ID: TokenId = TokenId(TOTAL_TOKEN_NUMBER as u32 - 1);
/// One slot is a leaf of order subtree, slot number = 2 ^ ORDER_SUB_TREE_DEPTH, max slot id = slot number - 1
pub const TOTAL_SLOT_NUMBER: usize = usize::pow(2, ORDER_SUB_TREE_DEPTH as u32);
Expand Down Expand Up @@ -210,6 +210,8 @@ pub const SIGNED_BATCH_FUNDING_BIT_WIDTH: usize = TX_TYPE_BIT_WIDTH
+ TOKEN_BIT_WIDTH
+ FEE_BIT_WIDTH;

/// 0 can not be used as token id
pub const TOKEN_ID_ZERO: u32 = 0;
pub const CONTRACT_PRICE_BIT_WIDTH: usize = PRICE_BIT_WIDTH + PAIR_BIT_WIDTH;
pub const CONTRACT_PRICE_BYTES: usize = CONTRACT_PRICE_BIT_WIDTH / 8;
pub const MARGIN_PRICE_BIT_WIDTH: usize = PRICE_BIT_WIDTH + TOKEN_BIT_WIDTH;
Expand Down
6 changes: 4 additions & 2 deletions types/src/tx_type/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::basic_types::pack::{is_fee_amount_packable, is_token_amount_packable}
use crate::basic_types::params::{
GLOBAL_ASSET_ACCOUNT_ID, MARGIN_TOKENS_NUMBER, MAX_ACCOUNT_ID, MAX_CHAIN_ID, MAX_NONCE,
MAX_ORDER_NONCE, MAX_PRICE, MAX_SLOT_ID, MAX_SUB_ACCOUNT_ID, MAX_TOKEN_ID, MIN_PRICE,
USDX_TOKEN_ID_LOWER_BOUND, USDX_TOKEN_ID_UPPER_BOUND, USED_POSITION_NUMBER,
TOKEN_ID_ZERO, USDX_TOKEN_ID_LOWER_BOUND, USDX_TOKEN_ID_UPPER_BOUND, USED_POSITION_NUMBER,
USED_POSITION_PAIR_ID_RANGE,
};
use crate::prelude::{
Expand Down Expand Up @@ -77,7 +77,9 @@ pub fn token_validator(token_id: &TokenId) -> Result<(), ValidationError> {
if *token_id > MAX_TOKEN_ID {
return Err(ValidationError::new("token id out of range"));
}
if **token_id >= USDX_TOKEN_ID_LOWER_BOUND && **token_id <= USDX_TOKEN_ID_UPPER_BOUND {
if **token_id == TOKEN_ID_ZERO
|| **token_id >= USDX_TOKEN_ID_LOWER_BOUND && **token_id <= USDX_TOKEN_ID_UPPER_BOUND
{
return Err(ValidationError::new("token id should not use 0 or [2, 16]"));
}
Ok(())
Expand Down
19 changes: 0 additions & 19 deletions types/src/tx_type/zklink_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,6 @@ pub enum ZkLinkTxType {
UpdateGlobalVar,
}

impl ZkLinkTxType {
pub fn op_codes(&self) -> Vec<u8> {
match self {
ZkLinkTxType::Deposit => vec![Deposit::TX_TYPE],
ZkLinkTxType::Transfer => vec![Transfer::TX_TYPE],
ZkLinkTxType::Withdraw => vec![Withdraw::TX_TYPE],
ZkLinkTxType::FullExit => vec![FullExit::TX_TYPE],
ZkLinkTxType::ChangePubKey => vec![ChangePubKey::TX_TYPE],
ZkLinkTxType::ForcedExit => vec![ForcedExit::TX_TYPE],
ZkLinkTxType::OrderMatching => vec![OrderMatching::TX_TYPE],
ZkLinkTxType::ContractMatching => vec![ContractMatching::TX_TYPE],
ZkLinkTxType::Liquidation => vec![Liquidation::TX_TYPE],
ZkLinkTxType::AutoDeleveraging => vec![AutoDeleveraging::TX_TYPE],
ZkLinkTxType::UpdateGlobalVar => vec![UpdateGlobalVar::TX_TYPE],
ZkLinkTxType::Funding => vec![Funding::TX_TYPE],
}
}
}

/// A set of L2 transaction supported by the zklink network.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
Expand Down

0 comments on commit ecaf431

Please sign in to comment.