Skip to content

Commit

Permalink
[EVM]Make public key as optional (#3673)
Browse files Browse the repository at this point in the history
* [EVM]Make public key as optional

As evm public key is optional, we need to keep compatible with before implemented in C++. Otherwise we have to change our existing prod codes to adapt this change.

* [Rust]Fix format check
  • Loading branch information
w20089527 authored Feb 1, 2024
1 parent d42429b commit 6f15eb4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions rust/tw_coin_entry/src/common/compile_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,20 @@ impl SingleSignaturePubkey {
public_key,
})
}

pub fn from_sign_list(signatures: Vec<SignatureBytes>) -> SigningResult<Self> {
if signatures.len() > 1 {
return Err(SigningError(SigningErrorType::Error_no_support_n2n));
}

let signature = signatures
.into_iter()
.next()
.ok_or(SigningError(SigningErrorType::Error_signatures_count))?;

Ok(SingleSignaturePubkey {
signature,
public_key: PublicKeyBytes::default(),
})
}
}
4 changes: 2 additions & 2 deletions rust/tw_evm/src/modules/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ impl<Context: EvmContext> Compiler<Context> {
fn compile_impl(
input: Proto::SigningInput<'_>,
signatures: Vec<SignatureBytes>,
public_keys: Vec<PublicKeyBytes>,
_: Vec<PublicKeyBytes>,
) -> SigningResult<Proto::SigningOutput<'static>> {
let SingleSignaturePubkey {
signature,
public_key: _,
} = SingleSignaturePubkey::from_sign_pubkey_list(signatures, public_keys)?;
} = SingleSignaturePubkey::from_sign_list(signatures)?;
let signature = secp256k1::Signature::from_bytes(&signature)?;

let chain_id = U256::from_big_endian_slice(&input.chain_id)?;
Expand Down
6 changes: 6 additions & 0 deletions tests/chains/Ethereum/TransactionCompilerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ TEST(EthereumCompiler, CompileWithSignatures) {
auto outputData =
TransactionCompiler::compileWithSignatures(coin, txInputData, {signature}, {publicKeyData});

// We dont care about public key in ethereum. It is not part of the transaction.
auto outputDataWithoutPubKey =
TransactionCompiler::compileWithSignatures(coin, txInputData, {signature}, {});

EXPECT_EQ(outputData, outputDataWithoutPubKey);

const auto ExpectedTx =
"f86c0b8504a817c800825208943535353535353535353535353535353535353535880de0b6b3a76400008025a0"
"360a84fb41ad07f07c845fedc34cde728421803ebbaae392fc39c116b29fc07ba053bd9d1376e15a191d844db4"
Expand Down

0 comments on commit 6f15eb4

Please sign in to comment.