Skip to content

Commit

Permalink
fix: fix rec_id
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyr committed Feb 9, 2022
1 parent ddea4dd commit e646d8a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
9 changes: 9 additions & 0 deletions crates/benches/benches/benchmarks/sudt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ pub fn bench(c: &mut Criterion) {
let init_a_balance: u128 = 10000;

// init accounts
let _meta = tree
.create_account_from_script(
Script::new_builder()
.code_hash(DUMMY_SUDT_VALIDATOR_SCRIPT_TYPE_HASH.clone().pack())
.args([0u8; 64].to_vec().pack())
.hash_type(ScriptHashType::Type.into())
.build(),
)
.expect("create account");
let sudt_id = tree
.create_account_from_script(
Script::new_builder()
Expand Down
23 changes: 13 additions & 10 deletions crates/generator/src/account_lock_manage/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ impl Secp256k1Eth {
}
}

// extract rec_id
fn extract_rec_id(rec_id: u8) -> u8 {
match rec_id {
r if r == 27 => 0,
r if r == 28 => 1,
r => r,
}
}

/// Usage
/// register AlwaysSuccess to AccountLockManage
///
Expand All @@ -189,11 +198,8 @@ impl LockAlgorithm for Secp256k1Eth {
let signature: RecoverableSignature = {
let signature = convert_signature_to_byte65(signature)?;
let recid = {
let rec_param: i32 = match signature[64] {
28 => 1,
_ => 0,
};
RecoveryId::from_i32(rec_param)
let rec_param = extract_rec_id(signature[64]);
RecoveryId::from_i32(rec_param.into())
.map_err(|err| LockAlgorithmError::InvalidSignature(err.to_string()))?
};
let data = &signature[..64];
Expand Down Expand Up @@ -320,11 +326,8 @@ impl LockAlgorithm for Secp256k1Tron {
let signature: RecoverableSignature = {
let signature: [u8; 65] = convert_signature_to_byte65(signature)?;
let recid = {
let rec_param: i32 = match signature[64] {
28 => 1,
_ => 0,
};
RecoveryId::from_i32(rec_param)
let rec_param = extract_rec_id(signature[64]);
RecoveryId::from_i32(rec_param.into())
.map_err(|err| LockAlgorithmError::InvalidSignature(err.to_string()))?
};
let data = &signature[..64];
Expand Down
1 change: 1 addition & 0 deletions devtools/fetch-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ docker pull ghcr.io/jjyr/godwoken-prebuilds:compatible-feature
[ -d $dir_name ] && rm -rf $dir_name && echo "Delete old dir"
mkdir -p $dir_name && echo "Create dir"
docker run --rm -v $(pwd)/$dir_name:/tmp ghcr.io/jjyr/godwoken-prebuilds:compatible-feature cp -r /scripts/godwoken-scripts /tmp && echo "Copy scripts"
docker run --rm -v $(pwd)/$dir_name:/tmp ghcr.io/jjyr/godwoken-prebuilds:compatible-feature cp -r /scripts/godwoken-polyjuice /tmp && echo "Copy polyjuice"
echo "Done"

0 comments on commit e646d8a

Please sign in to comment.