-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(svm): Refactor deposit ID to use big-endian encoding in Bytes32 format #810
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Pablo Maldonado <[email protected]>
Signed-off-by: Pablo Maldonado <[email protected]>
Signed-off-by: Pablo Maldonado <[email protected]>
Signed-off-by: Pablo Maldonado <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, this should be easier for offchain to work with
@@ -117,7 +117,7 @@ pub fn _deposit_v3( | |||
// If the passed in deposit_id is all zeros, then we use the state's number of deposits as deposit_id. | |||
if deposit_id == ZERO_DEPOSIT_ID { | |||
state.number_of_deposits += 1; | |||
applied_deposit_id[..4].copy_from_slice(&state.number_of_deposits.to_le_bytes()); | |||
applied_deposit_id[28..].copy_from_slice(&state.number_of_deposits.to_be_bytes()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is great! I love how simple it is to get these structures to match what is expected here.
@@ -1,33 +1,16 @@ | |||
import { BN } from "@coral-xyz/anchor"; | |||
import { PublicKey } from "@solana/web3.js"; | |||
import { ethers } from "ethers"; | |||
import { BigNumber, ethers } from "ethers"; | |||
|
|||
/** | |||
* Converts an integer to a 32-byte Uint8Array. | |||
*/ | |||
export function intToU8Array32(num: number | BN): number[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might make sense at some point to have unit tests for these kinds of utils.
Changes proposed in this PR:
Motivation:
Previously, "safe" (
deposit_v3
) deposit IDs were stored in little-endian (LE) format, causing friction for relayers and off-chain tools due to format conversions. Challenges included:Solution:
This PR stores "safe" (
deposit_v3
) deposit IDs in BE format, storingnumber_of_deposits
in the right-most bits. This aligns with EVM, simplifies cross-chain operations and reduces off-chain parsing complexityNote: The “unsafe” deposit (
unsafe_deposit_v3
) does not require any changes and is unaffected by these challenges, as it uses a generated hash without endianness considerations.