From 7ea91db38b2f5a361ab51cb3855864790506c418 Mon Sep 17 00:00:00 2001 From: Dao Nguyen Date: Tue, 22 Oct 2024 00:51:58 +0700 Subject: [PATCH] update --- packages/engine/src/opcodes/crypto.cairo | 3 ++- packages/engine/src/signature/signature.cairo | 26 ++++--------------- tests/run-core-tests.sh | 2 +- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/packages/engine/src/opcodes/crypto.cairo b/packages/engine/src/opcodes/crypto.cairo index 7d9f20b..537e200 100644 --- a/packages/engine/src/opcodes/crypto.cairo +++ b/packages/engine/src/opcodes/crypto.cairo @@ -75,7 +75,8 @@ pub fn opcode_checksig< let err = res.unwrap_err(); if err == Error::SCRIPT_ERR_SIG_DER || err == Error::PUBKEYTYPE - || err == Error::SIG_HASHTYPE { + || err == Error::SIG_HASHTYPE + || err == Error::SIG_HIGH_S { return Result::Err(err); }; engine.dstack.push_bool(false); diff --git a/packages/engine/src/signature/signature.cairo b/packages/engine/src/signature/signature.cairo index d8d4256..bdb90b4 100644 --- a/packages/engine/src/signature/signature.cairo +++ b/packages/engine/src/signature/signature.cairo @@ -567,31 +567,15 @@ pub fn remove_signature(script: @ByteArray, sig_bytes: @ByteArray) -> @ByteArray let script_len = script.len(); while i < script_len { - let push_data: u8 = script[i]; - if push_data >= 8 && push_data <= 72 { - let mut len: usize = push_data.into(); - let mut found: bool = false; - if len == sig_bytes.len() { - found = compare_data(script, sig_bytes, i, push_data); - } - - if i + len <= script.len() { - i += len; - } else { - i += 1; - } + let opcode = script[i]; + let data_len = parser::data_len(script, i).unwrap(); + let end = i + data_len + 1; + if data_len == sig_bytes.len() { + let mut found = compare_data(script, sig_bytes, i, opcode); if found { i = end; continue; } - - processed_script.append_byte(push_data); - while len != 0 && i - len < script_len { - processed_script.append_byte(script[i - len + 1]); - len -= 1; - }; - } else { - processed_script.append_byte(push_data); } while i != end { processed_script.append_byte(script[i]); diff --git a/tests/run-core-tests.sh b/tests/run-core-tests.sh index 35fdeac..e351092 100755 --- a/tests/run-core-tests.sh +++ b/tests/run-core-tests.sh @@ -208,7 +208,7 @@ jq -c '.[]' $SCRIPT_TESTS_JSON | { elif echo "$RESULT" | grep -q "$INVALID_SIG_FMT"; then SCRIPT_RESULT="SIG_DER" elif echo "$RESULT" | grep -q "$INVALID_HASH_TYPE"; then - SCRIPT_RESULT="SIG_DER" + SCRIPT_RESULT="SIG_HASHTYPE" elif echo "$RESULT" | grep -q "$NONZERO_NULLFAIL"; then SCRIPT_RESULT="NULLFAIL" elif echo "$RESULT" | grep -q "$SIG_NULLFAIL"; then