Skip to content

Comments

Eth stream#118

Open
Tomasvrba wants to merge 3 commits intoBitBoxSwiss:masterfrom
Tomasvrba:eth-stream
Open

Eth stream#118
Tomasvrba wants to merge 3 commits intoBitBoxSwiss:masterfrom
Tomasvrba:eth-stream

Conversation

@Tomasvrba
Copy link
Contributor

No description provided.

Copy link
Contributor

@benma benma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Please bump Cargo.toml and NPM_VERSION versions and add a changelog entry to both CHANGELOG files.

/// Signs an Ethereum transaction. It returns a 65 byte signature (R, S, and 1 byte recID). The
/// `tx` param can be constructed manually or parsed from a raw transaction using
/// `raw_tx_slice.try_into()` (`rlp` feature required).
pub async fn eth_sign_transaction(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flow here is even nicer than in bitbox02.py, where the streaming was folded into the handle_antiklepto helper 😄

@@ -0,0 +1,174 @@
#![cfg(feature = "simulator")]
// SPDX-License-Identifier: Apache-2.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be the first line, followed by an empty line. I see the other files in this folder have the same mistake - would you mind fixing them all up?

Comment on lines 23 to 24
assert!(address.starts_with("0x"));
assert_eq!(address.len(), 42);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just compare the whole address to a string literal - the simulator runs with a fixed seed.

async fn test_eth_sign_transaction_nonstreaming() {
test_initialized_simulators(async |paired_bitbox| {
// Skip if firmware doesn't support ETH
if !paired_bitbox.eth_supported() {
Copy link
Contributor

@benma benma Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd assert!(paired_bitbox.eth_supported()) instead, as the simulator has it and it's important to not accidentally skip the test (we do the same in the cardno simulator tests)

Comment on lines 53 to 57
assert!(
result.is_ok(),
"eth_sign_transaction failed: {:?}",
result.err()
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant, the next line will make the test fail if it was not ok. Same for the tests below.

"eth_sign_transaction streaming failed: {:?}",
result.err()
);
assert_eq!(result.unwrap().len(), 65);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we tell that streaming worked properly?

Maybe we could verify the signature using bitcoin::secp256k1 against the sighash of the tx above? Could hardcode the expected sighash for this (maybe with a tiny Go/Python script in a comment that shows how it was computed, similar to the test gen tools in the PR you made in the fw repo).

Copy link
Contributor Author

@Tomasvrba Tomasvrba Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to generate hundreds of test cases here right, so just do it directly in rust in the test file without external scripts?

added it to the test file, don't have to rely on an external script this way that would have to run to regenerate the sighashes if something changed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah didn't realize doing it in Rust would be so simple, even better 👍

@Tomasvrba
Copy link
Contributor Author

Thank you!

Please bump Cargo.toml and NPM_VERSION versions and add a changelog entry to both CHANGELOG files.

will do, wasn't done yet, was still going to do a full end to end test with Rabby before asking for a review but you beat me to it :D

Copy link
Contributor

@benma benma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK, nice. Please squash the streaming-related commits, and leave the webhid.js and license header fix in separate commits. Thanks

eth: update proto files to prepare for streaming

eth: implement streaming handler for large transaction data

eth: add simulator integration tests for eth tx data streaming

tests: add signature verification to eth tests

bump versions and add CHANGELOG entries
wasm-pack 0.13+ adds "type": "module" to the generated package.json,
which requires fully-specified import paths. Add the .js extension to
the raw_module attribute so the generated import works with strict ESM
bundlers like webpack.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants