Skip to content

Commit 38243dd

Browse files
committed
Add temporary twoxtx feature for ConfidentialTransfer extension unit testing
1 parent 4c3a3d2 commit 38243dd

File tree

6 files changed

+133
-2
lines changed

6 files changed

+133
-2
lines changed

.github/workflows/pull-request-token.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@ jobs:
5454
./ci/install-program-deps.sh
5555
echo "$HOME/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
5656
57-
- name: Build and test
57+
- name: Build and test token
5858
run: ./ci/cargo-test-bpf.sh token
5959

60-
- name: Build and test
60+
- name: Build and test ATA
6161
run: ./ci/cargo-test-bpf.sh associated-token-account
6262

63+
- name: Build and test token-2022 twoxtx (TEMPORARY)
64+
run: |
65+
./token/twoxtx-setup.sh
66+
./ci/cargo-test-bpf.sh token/program-2022-test
67+
6368
- name: Upload programs
6469
uses: actions/upload-artifact@v2
6570
with:

token/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/twoxtx-solana/

token/program-2022-test/build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@ fn main() {
5151
println!("cargo:warning=(not a warning) {}", sub);
5252
}
5353
}
54+
55+
// Set the temporary `twoxtx` cfg if `../twoxtx-setup.sh` was run
56+
let twoxtx_solana_dir = cwd
57+
.parent()
58+
.expect("Unable to get parent directory of current working dir")
59+
.join("twoxtx-solana");
60+
if twoxtx_solana_dir.exists() {
61+
println!("cargo:rustc-cfg=twoxtx");
62+
}
5463
}

token/program-2022-test/tests/confidential_transfer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![cfg(feature = "test-bpf")]
2+
#![cfg(twoxtx)]
23

34
mod program_test;
45
use {

token/twoxtx-setup.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Patch in a Solana v1.10 monorepo that supports 2x transactions for testing the
4+
# SPL Token 2022 Confidential Transfer extension
5+
#
6+
7+
set -e
8+
9+
here="$(dirname "$0")"
10+
cd "$here"
11+
12+
if [[ ! -d twoxtx-solana ]]; then
13+
if [[ -n $CI ]]; then
14+
git config --global user.email "you@example.com"
15+
git config --global user.name "Your Name"
16+
git clone https://github.com/solana-labs/solana.git twoxtx-solana
17+
else
18+
git clone git@github.com:solana-labs/solana.git twoxtx-solana
19+
fi
20+
fi
21+
22+
if [[ ! -f twoxtx-solana/.twoxtx-patched ]]; then
23+
git -C twoxtx-solana am "$PWD"/twoxtx.patch
24+
touch twoxtx-solana/.twoxtx-patched
25+
fi
26+
27+
../patch.crates-io.sh twoxtx-solana
28+
exit 0

token/twoxtx.patch

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
From 935ad2c371da8405bb85922b9941d35b3dc68ceb Mon Sep 17 00:00:00 2001
2+
From: Steven Czabaniuk <steven@solana.com>
3+
Date: Wed, 29 Sep 2021 15:43:36 -0500
4+
Subject: [PATCH] feat: double PACKET_DATA_SIZE
5+
6+
Try blind double of PACKET_DATA_SIZE; this double things across the
7+
board and is not a permanent solution.
8+
---
9+
rpc/src/rpc.rs | 16 +++++++++++-----
10+
sdk/src/packet.rs | 3 ++-
11+
web3.js/src/transaction.ts | 4 +++-
12+
3 files changed, 16 insertions(+), 7 deletions(-)
13+
14+
diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs
15+
index 987980cb53..607681728c 100644
16+
--- a/rpc/src/rpc.rs
17+
+++ b/rpc/src/rpc.rs
18+
@@ -4177,8 +4177,11 @@ pub mod rpc_obsolete_v1_7 {
19+
}
20+
}
21+
22+
-const MAX_BASE58_SIZE: usize = 1683; // Golden, bump if PACKET_DATA_SIZE changes
23+
-const MAX_BASE64_SIZE: usize = 1644; // Golden, bump if PACKET_DATA_SIZE changes
24+
+// These values need to be updated if PACKET_DATA_SIZE changes. The correct values can
25+
+// be found by hand or by simply encoding `PACKET_DATA_SIZE` bytes and checking length.
26+
+// `test_max_encoded_tx_goldens` ensures these values are correct.
27+
+const MAX_BASE58_SIZE: usize = 3365;
28+
+const MAX_BASE64_SIZE: usize = 3288;
29+
fn decode_and_deserialize<T>(
30+
encoded: String,
31+
encoding: UiTransactionEncoding,
32+
@@ -7961,7 +7964,7 @@ pub mod tests {
33+
}
34+
35+
#[test]
36+
- fn test_worst_case_encoded_tx_goldens() {
37+
+ fn test_max_encoded_tx_goldens() {
38+
let ff_tx = vec![0xffu8; PACKET_DATA_SIZE];
39+
let tx58 = bs58::encode(&ff_tx).into_string();
40+
assert_eq!(tx58.len(), MAX_BASE58_SIZE);
41+
@@ -7971,8 +7974,11 @@ pub mod tests {
42+
43+
#[test]
44+
fn test_decode_and_deserialize_too_large_payloads_fail() {
45+
- // +2 because +1 still fits in base64 encoded worst-case
46+
- let too_big = PACKET_DATA_SIZE + 2;
47+
+ // 4 base64 digits are generated from groups of 3 bytes; however, those 4 digits
48+
+ // are generated even if the group only has 1 or 2 bytes.
49+
+ // So, we need 4 - (PACKET_DATA_SIZE % 3) extra bytes to ensure we'll spill over
50+
+ let extra_bytes = 4 - (PACKET_DATA_SIZE % 3);
51+
+ let too_big = PACKET_DATA_SIZE + extra_bytes;
52+
let tx_ser = vec![0xffu8; too_big];
53+
let tx58 = bs58::encode(&tx_ser).into_string();
54+
let tx58_len = tx58.len();
55+
diff --git a/sdk/src/packet.rs b/sdk/src/packet.rs
56+
index efea219043..473a92ecfe 100644
57+
--- a/sdk/src/packet.rs
58+
+++ b/sdk/src/packet.rs
59+
@@ -12,7 +12,8 @@ use {
60+
/// 1280 is IPv6 minimum MTU
61+
/// 40 bytes is the size of the IPv6 header
62+
/// 8 bytes is the size of the fragment header
63+
-pub const PACKET_DATA_SIZE: usize = 1280 - 40 - 8;
64+
+/// Double the minimum to support larger than MTU transactions
65+
+pub const PACKET_DATA_SIZE: usize = 2 * (1280 - 40 - 8);
66+
67+
bitflags! {
68+
#[repr(C)]
69+
diff --git a/web3.js/src/transaction.ts b/web3.js/src/transaction.ts
70+
index 5466464f5a..5b71b9dc39 100644
71+
--- a/web3.js/src/transaction.ts
72+
+++ b/web3.js/src/transaction.ts
73+
@@ -29,8 +29,10 @@ const DEFAULT_SIGNATURE = Buffer.alloc(64).fill(0);
74+
* 1280 is IPv6 minimum MTU
75+
* 40 bytes is the size of the IPv6 header
76+
* 8 bytes is the size of the fragment header
77+
+ *
78+
+ * Double the minimum to support larger than MTU transactions
79+
*/
80+
-export const PACKET_DATA_SIZE = 1280 - 40 - 8;
81+
+export const PACKET_DATA_SIZE = 2464;
82+
83+
const SIGNATURE_LENGTH = 64;
84+
85+
--
86+
2.32.0 (Apple Git-132)
87+

0 commit comments

Comments
 (0)