From b0508750cb7486554bc8e8751d94c4e784defd89 Mon Sep 17 00:00:00 2001 From: satoshiotomakan <127754187+satoshiotomakan@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:22:14 +0100 Subject: [PATCH] [Solana]: Improve `TransactionDecoder` API (#3723) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [Solana]: Do not require to provide a sender address if `RawMessage` specified * [CI] Trigger CI * [CI]: Fix Docker and check-binary-sizes * [CI]: Fix Docker build * [CI]: Fix Docker build №2 --- .github/workflows/linux-ci-rust.yml | 1 + Dockerfile | 1 + rust/chains/tw_solana/src/compiler.rs | 6 ++---- .../tw_solana/src/modules/message_builder.rs | 16 ---------------- .../tw_solana/src/transaction/versioned.rs | 10 ++++++++++ .../tests/chains/solana/solana_transaction.rs | 2 -- tests/chains/Firo/TransactionCompilerTests.cpp | 4 ++-- tools/release-size | 2 +- 8 files changed, 17 insertions(+), 25 deletions(-) diff --git a/.github/workflows/linux-ci-rust.yml b/.github/workflows/linux-ci-rust.yml index 9de4326f918..258c8f2d916 100644 --- a/.github/workflows/linux-ci-rust.yml +++ b/.github/workflows/linux-ci-rust.yml @@ -152,6 +152,7 @@ jobs: ./tools/release-size compare --before previous/release-report.json --current release-report.json > report-diff.md - name: Create or Update Comment + if: github.event_name == 'pull_request' uses: edumserrano/find-create-or-update-comment@v2 with: issue-number: ${{ github.event.pull_request.number }} diff --git a/Dockerfile b/Dockerfile index 7db09d1bd5b..179fa0d8973 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,6 +38,7 @@ ENV CXX=/usr/bin/clang++-14 RUN wget "https://sh.rustup.rs" -O rustup.sh \ && sh rustup.sh -y ENV PATH="/root/.cargo/bin:${PATH}" +RUN rustup default nightly-2024-02-09 RUN cargo install --force cbindgen \ && rustup target add wasm32-unknown-emscripten diff --git a/rust/chains/tw_solana/src/compiler.rs b/rust/chains/tw_solana/src/compiler.rs index 5b3c9f89df8..bd5a8af0297 100644 --- a/rust/chains/tw_solana/src/compiler.rs +++ b/rust/chains/tw_solana/src/compiler.rs @@ -35,13 +35,11 @@ impl SolanaCompiler { input: Proto::SigningInput<'_>, ) -> SigningResult> { let builder = MessageBuilder::new(input); - let signers = builder.signers()?; let unsigned_msg = builder.build()?; - let data_to_sign = TxSigner::preimage_versioned(&unsigned_msg)?; - let signers: Vec<_> = signers - .iter() + let signers: Vec<_> = unsigned_msg + .signers() .map(|addr| Cow::from(addr.to_string().into_bytes())) .collect(); diff --git a/rust/chains/tw_solana/src/modules/message_builder.rs b/rust/chains/tw_solana/src/modules/message_builder.rs index 7b8f6eaee04..59cc70fc739 100644 --- a/rust/chains/tw_solana/src/modules/message_builder.rs +++ b/rust/chains/tw_solana/src/modules/message_builder.rs @@ -57,22 +57,6 @@ impl<'a> MessageBuilder<'a> { Ok(signing_keys) } - pub fn signers(&self) -> SigningResult> { - let mut signers = Vec::default(); - if !self.input.fee_payer.is_empty() { - signers.push(SolanaAddress::from_str(self.input.fee_payer.as_ref())?); - } - - signers.push(self.signer_address()?); - - // Consider matching other transaction types if they may contain other private keys. - if let ProtoTransactionType::create_nonce_account(ref nonce) = self.input.transaction_type { - signers.push(SolanaAddress::from_str(nonce.nonce_account.as_ref())?); - } - - Ok(signers) - } - pub fn external_signatures(&self) -> SigningResult { match self.input.raw_message { Some(ref raw_message) => RawMessageBuilder::external_signatures(raw_message), diff --git a/rust/chains/tw_solana/src/transaction/versioned.rs b/rust/chains/tw_solana/src/transaction/versioned.rs index 71282340222..ade097c4b7d 100644 --- a/rust/chains/tw_solana/src/transaction/versioned.rs +++ b/rust/chains/tw_solana/src/transaction/versioned.rs @@ -65,6 +65,16 @@ impl VersionedMessage { } } + pub fn signers(&self) -> impl Iterator { + let signatures_count = self.num_required_signatures(); + match self { + VersionedMessage::Legacy(legacy) => &legacy.account_keys, + VersionedMessage::V0(v0) => &v0.account_keys, + } + .iter() + .take(signatures_count) + } + pub fn recent_blockhash(&self) -> Blockhash { match self { VersionedMessage::Legacy(legacy) => Blockhash::with_bytes(legacy.recent_blockhash), diff --git a/rust/tw_any_coin/tests/chains/solana/solana_transaction.rs b/rust/tw_any_coin/tests/chains/solana/solana_transaction.rs index 6d00329d02f..afb51dc08d8 100644 --- a/rust/tw_any_coin/tests/chains/solana/solana_transaction.rs +++ b/rust/tw_any_coin/tests/chains/solana/solana_transaction.rs @@ -302,8 +302,6 @@ fn test_solana_decode_transaction_update_blockhash_preimage_hash_and_compile() { // Step 3. Pre-image hash the transaction. let input = Proto::SigningInput { - // There is no matching pubkey in the transaction account keys. - sender: SENDER_PUBLIC_KEY.into(), raw_message: Some(decoded_tx), tx_encoding: Proto::Encoding::Base64, ..Proto::SigningInput::default() diff --git a/tests/chains/Firo/TransactionCompilerTests.cpp b/tests/chains/Firo/TransactionCompilerTests.cpp index 5851ae6ce4f..c5265971f52 100644 --- a/tests/chains/Firo/TransactionCompilerTests.cpp +++ b/tests/chains/Firo/TransactionCompilerTests.cpp @@ -2,7 +2,6 @@ // // Copyright © 2017 Trust Wallet. -#include "Coin.h" #include "HexCoding.h" #include "PublicKey.h" #include "TransactionCompiler.h" @@ -10,10 +9,11 @@ #include "proto/Bitcoin.pb.h" #include "proto/TransactionCompiler.pb.h" +#include +#include #include #include "Bitcoin/Script.h" -#include "Bitcoin/TransactionPlan.h" #include "TestUtilities.h" #include diff --git a/tools/release-size b/tools/release-size index bcd4076f9e8..3d73f4f50f6 100755 --- a/tools/release-size +++ b/tools/release-size @@ -54,7 +54,7 @@ def compare_sizes(args): print("## Binary size comparison") print() for target, current_kb in current_json.items(): - before_kb = before_json.get(target, 0) + before_kb = before_json.get(target, current_kb) display_target(target, before_kb, current_kb) print()