-
Notifications
You must be signed in to change notification settings - Fork 75
fix(svm): use borch serializer #765
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ import { | |
| mintTo, | ||
| createApproveCheckedInstruction, | ||
| } from "@solana/spl-token"; | ||
| import { PublicKey, Keypair, Transaction, sendAndConfirmTransaction } from "@solana/web3.js"; | ||
| import { PublicKey, Keypair, Transaction, sendAndConfirmTransaction, ComputeBudgetProgram } from "@solana/web3.js"; | ||
| import { common } from "./SvmSpoke.common"; | ||
| import { MerkleTree } from "@uma/common/dist/MerkleTree"; | ||
| import { | ||
|
|
@@ -372,7 +372,7 @@ describe("svm_spoke.slow_fill", () => { | |
| .rpc(); | ||
|
|
||
| // Execute V3 slow relay leaf after requesting slow fill | ||
| await program.methods | ||
| const ix = await program.methods | ||
| .executeV3SlowRelayLeaf( | ||
| Array.from(relayHash), | ||
| { ...leaf, relayData: formatRelayData(relayData) }, | ||
|
|
@@ -381,7 +381,9 @@ describe("svm_spoke.slow_fill", () => { | |
| ) | ||
| .accounts(executeSlowRelayLeafAccounts) | ||
| .remainingAccounts(fillRemainingAccounts) | ||
| .rpc(); | ||
| .instruction(); | ||
| const computeBudgetInstruction = ComputeBudgetProgram.setComputeUnitLimit({ units: 1_400_000 }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Has the borsh serialisation increased the CU? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its hard to tell precisely as our tests are not deterministic and have much more variance due to differing bumps in PDA derivation, but over 10 runs I observed on average +2% in CU, which I guess is acceptable here. |
||
| await sendAndConfirmTransaction(connection, new Transaction().add(computeBudgetInstruction, ix), [payer]); | ||
|
|
||
| // Verify the results | ||
| const fVaultBal = (await connection.getTokenAccountBalance(vault)).value.amount; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,14 +164,17 @@ export function calculateRelayerRefundLeafHashUint8Array(relayData: RelayerRefun | |
|
|
||
| const refundAddressesBuffer = Buffer.concat(relayData.refundAddresses.map((address) => address.toBuffer())); | ||
|
|
||
| // TODO: We better consider reusing Borch serializer in production. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 we should probably test this and make sure they produce the same byte layout |
||
| const contentToHash = Buffer.concat([ | ||
| // SVM leaves require the first 64 bytes to be 0 to ensure EVM leaves can never be played on SVM and vice versa. | ||
| Buffer.alloc(64, 0), | ||
| relayData.amountToReturn.toArrayLike(Buffer, "le", 8), | ||
| relayData.chainId.toArrayLike(Buffer, "le", 8), | ||
| new BN(relayData.refundAmounts.length).toArrayLike(Buffer, "le", 4), | ||
| refundAmountsBuffer, | ||
| relayData.leafId.toArrayLike(Buffer, "le", 4), | ||
| relayData.mintPublicKey.toBuffer(), | ||
| new BN(relayData.refundAddresses.length).toArrayLike(Buffer, "le", 4), | ||
| refundAddressesBuffer, | ||
| ]); | ||
|
|
||
|
|
@@ -222,6 +225,7 @@ export interface SlowFillLeaf { | |
| updatedOutputAmount: BN; | ||
| } | ||
|
|
||
| // TODO: We better consider reusing Borch serializer in production. | ||
| export function slowFillHashFn(slowFillLeaf: SlowFillLeaf): string { | ||
| const contentToHash = Buffer.concat([ | ||
| // SVM leaves require the first 64 bytes to be 0 to ensure EVM leaves can never be played on SVM and vice versa. | ||
|
|
@@ -237,6 +241,7 @@ export function slowFillHashFn(slowFillLeaf: SlowFillLeaf): string { | |
| slowFillLeaf.relayData.depositId.toArrayLike(Buffer, "le", 4), | ||
| slowFillLeaf.relayData.fillDeadline.toArrayLike(Buffer, "le", 4), | ||
| slowFillLeaf.relayData.exclusivityDeadline.toArrayLike(Buffer, "le", 4), | ||
| new BN(slowFillLeaf.relayData.message.length).toArrayLike(Buffer, "le", 4), | ||
| slowFillLeaf.relayData.message, | ||
| slowFillLeaf.chainId.toArrayLike(Buffer, "le", 8), | ||
| slowFillLeaf.updatedOutputAmount.toArrayLike(Buffer, "le", 8), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Wow! Much better like this