Skip to content

Commit

Permalink
fix(rpc): calculate tx signature hash using packed bytes
Browse files Browse the repository at this point in the history
packed bytes contains size header, should use raw bytes.
  • Loading branch information
zeroqn committed Jul 18, 2022
1 parent c5d2db6 commit af298ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion crates/rpc-server/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,8 @@ async fn submit_l2transaction(
Some(_) => tx_hash,
None => {
let mut hasher = new_blake2b();
hasher.update(tx.signature().as_slice());
let sig: Bytes = tx.signature().unpack();
hasher.update(&sig);
let mut hash = [0u8; 32];
hasher.finalize(&mut hash);
H256::from(hash)
Expand Down
6 changes: 4 additions & 2 deletions crates/tests/src/tests/rpc_server/submit_l2transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use gw_common::{
H256,
};
use gw_types::{
bytes::Bytes,
packed::{Fee, RawL2Transaction, SUDTArgs, SUDTTransfer, Script},
prelude::Pack,
prelude::{Pack, Unpack},
U256,
};

Expand Down Expand Up @@ -147,7 +148,8 @@ async fn test_in_queue_query_with_signature_hash() {
mem_pool_state.store(snap.into());
let signature_hash = {
let mut hasher = new_blake2b();
hasher.update(deploy_tx.signature().as_slice());
let sig: Bytes = deploy_tx.signature().unpack();
hasher.update(&sig);
let mut hash = [0u8; 32];
hasher.finalize(&mut hash);
H256::from(hash)
Expand Down

0 comments on commit af298ab

Please sign in to comment.