sendrawtransaction – Find out how to repair this error?: Signature should be zero for failed CHECK(MULTI)SIG operation (code -26)

0
69


I am attempting to unlock cash from P2SH 2NG4PEU9rya1fcqAfSvQQAteaUkvc54J1fF, however the library shouldn’t be utilized by https://www.youtube.com/watch?v=U2bw_N6kQL8

Once I mix the Tx, I hash the Tx with SHA256 twice, then signal it with ECDSA (not used library).

After I confirm that the signatures I’ve are legitimate and gather the signed tx (Signed Tx) and distribute the Tx to the bitcoin community (testnet), the issue I encounter is “Unacceptable signature: unnecessarily excessive S-value.”

after which edit this thread.
https://github.com/bitcoin/bips/blob/grasp/bip-0146.mediawiki

After I did this technique, the results of S is lower than R, however there may be one other drawback. “Signature should be zero for motion. Failed CHECK(MULTI)SIG”

However Script it not multisig

However right here remains to be an issue. So I do not know how you can resolve this drawback. and do not know how you can ask this query to the purpose

Personal Key: 
| hex = 82d6cfc556c25e3fd02eb384bd95ba4fd217911836ce5b19fb34c864f6a5a9f4 
| dec = 59180209569427299317707189507794282735328653532808969125005524031929026193908 

Public Key: 
| x = 00aa36a1958e2fc5e5de75d05bcf6f3ccc0799be4905f4e418505dc6ab4422a8db
| y = 1fabeb6911ae2715032944ca90d452b30192b5539e4dfb0c386013321fcada8c

Unsigned Transaction: 
| 0100000001fc3adf56a9b345dd394479b5438365777ba7d91eb3954d9f2b5e2c7a68d06b980000000029030c3725b1752102aa36a1958e2fc5e5de75d05bcf6f3ccc0799be4905f4e418505dc6ab4422a8dbacfdffffff01d36f0300000000001600149058b7a55f5d5f88667a01fd66dd59e379002f5d0c372500

Message (doubleSHA256): 40a9f18c88d0f16989742b5fde90c52097c6c52feb37f7bf912140998b0713f4

Signatures: 
| r = 85481222987935817085579092069107947283118149501178124668858153032995539683302
| s = 23241719739309219792817770422392736282205653387772946202874350868806068363298

Signed Transaction: 
| 0100000001fc3adf56a9b345dd394479b5438365777ba7d91eb3954d9f2b5e2c7a68d06b980000000073483045022100bcfca85cc0582a456aefd52539747bf24342b360f821d66a570fb7b754b687e60220336258e21892cea41ea90a8a8538b0af4081c605f2f7a73821f871066c2060220129030c3725b1752102aa36a1958e2fc5e5de75d05bcf6f3ccc0799be4905f4e418505dc6ab4422a8dbacfdffffff01d36f0300000000001600149058b7a55f5d5f88667a01fd66dd59e379002f5d0c372500
{
  "txid": "53a4886fa2f89864c0b874b0db03836b4cbb1b9b13fa45d0ca262cf321138c5d",
  "hash": "53a4886fa2f89864c0b874b0db03836b4cbb1b9b13fa45d0ca262cf321138c5d",
  "model": 1,
  "measurement": 197,
  "vsize": 197,
  "weight": 788,
  "locktime": 2438924,
  "vin": [
    {
      "txid": "986bd0687a2c5e2b9f4d95b31ed9a77b77658343b5794439dd45b3a956df3afc",
      "vout": 0,
      "scriptSig": {
        "asm": "3045022100bcfca85cc0582a456aefd52539747bf24342b360f821d66a570fb7b754b687e60220336258e21892cea41ea90a8a8538b0af4081c605f2f7a73821f871066c206022[ALL] 030c3725b1752102aa36a1958e2fc5e5de75d05bcf6f3ccc0799be4905f4e418505dc6ab4422a8dbac",
        "hex": "483045022100bcfca85cc0582a456aefd52539747bf24342b360f821d66a570fb7b754b687e60220336258e21892cea41ea90a8a8538b0af4081c605f2f7a73821f871066c2060220129030c3725b1752102aa36a1958e2fc5e5de75d05bcf6f3ccc0799be4905f4e418505dc6ab4422a8dbac"
      },
      "sequence": 4294967293
    }
  ],
  "vout": [
    {
      "value": 0.00225235,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 9058b7a55f5d5f88667a01fd66dd59e379002f5d",
        "desc": "addr(tb1qjpvt0f2lt40csen6q87kdh2eudusqt6atkf5ca)#6fsn5mx5",
        "hex": "00149058b7a55f5d5f88667a01fd66dd59e379002f5d",
        "address": "tb1qjpvt0f2lt40csen6q87kdh2eudusqt6atkf5ca",
        "type": "witness_v0_keyhash"
      }
    }
  ]
}

How do I resolve this drawback?

// jdk 20

object EllipticCurve {

    // * Secp256k1
    personal val A = BigInteger.ZERO
    personal val B = BigInteger.valueOf(7)
    personal val P = BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 16)
    personal val N = BigInteger("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16)
    personal val G = Level(
        BigInteger("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 16),
        BigInteger("483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", 16)
    )

    // * จุดบนเส้นโค้งวงรี มีพิกัด x และ y
    knowledge class Level(val x: BigInteger, val y: BigInteger)


    // ──────────────────────────────────────────────────────────────────────────────────────── 

    /*
    * < Elliptic Curve cryptography >
    * ในส่วนนี้เป็นการคำนวณค Public Key
    *
    * อ้างอิงจาก:
    * https://github.com/wobine/blackboard101/blob/grasp/EllipticCurvesPart5-TheMagic-SigningAndVerifying.py
    * */

    // * https://www.dcode.fr/modular-inverse
    enjoyable modinv(A: BigInteger, N: BigInteger = P) = A.modInverse(N)


    enjoyable doublePoint(level: Level): Level {
        val (x, y) = level

        // ! (3 * x * x + A) % P
        val slope = (BigInteger.valueOf(3) * x * x + A) % P

        val lam_denom = (BigInteger.valueOf(2) * y) % P

        val lam = (slope * modinv(lam_denom)) % P

        val xR = (lam * lam - BigInteger.valueOf(2) * x) % P

        val yR = (lam * (x - xR) - y) % P

        // * จุดใหม่ที่ได้หลังจากการคูณด้วย 2 บนเส้นโค้งวงรี
        return Level(xR, (yR + P) % P)
    }

    enjoyable addPoint(point1: Level, point2: Level): Level {
        if (point1 == point2) {
            return doublePoint(point1)
        }
        val (x1, y1) = point1
        val (x2, y2) = point2

        val slope = ((y2 - y1) * modinv(x2 - x1)) % P

        val xR = (slope * slope - x1 - x2) % P

        val yR = (slope * (x1 - xR) - y1) % P

        // ! จัดการพิกัด Y ที่เป็นค่าลบ
        val yResult = if (yR < BigInteger.ZERO) yR + P else yR

        return Level(xR, yResult)
    }

    enjoyable multiplyPoint(ok: BigInteger, level: Level? = null): Level {
        // * ตัวแปร present ถูกกำหนดให้เป็น level ที่รับเข้ามา หากไม่มีการระบุ level ค่าเริ่มต้นจะเป็นจุด G ที่ใช้ในการคูณเช่นกับ personal key
        val present = level ?: G

        // * แปลงจำนวนเต็ม ok เป็นเลขฐานสอง
        val binary = ok.toString(2)

        // * เริ่มต้นด้วยจุดเริ่มต้นปัจจุบัน
        var currentPoint = present

        // * วนลูปตามจำนวน binary digits ของ ok
        for (i in 1 till binary.size) {
            currentPoint = doublePoint(currentPoint)

            // * ถ้า binary ตัวที่ตำแหน่ง i เป็น '1'  ให้บวกจุดเริ่มต้น (present) เข้ากับจุดปัจจุบัน (currentPoint)
            if (binary[i] == '1') {
                currentPoint = addPoint(currentPoint, present)
            }

            // * Debug
            //println("binary[i] = $i:")
            //println("Present Level: $currentPoint n")
        }

        // * ส่งคืนจุดที่คำนวณได้
        return currentPoint
    }


    // ──────────────────────────────────────────────────────────────────────────────────────── 
    
 
 
 object ECDSA {

        /*
        * https://github.com/bitcoin/bips/blob/grasp/bip-0062.mediawiki
        */


        enjoyable SignSignature(privateKey: BigInteger, message: BigInteger): Pair<BigInteger, BigInteger> {
            val m = message
            val ok = BigInteger("42854675228720239947134362876390869888553449708741430898694136287991817016610")
            //val ok = BigInteger(256, SecureRandom())

            val level = multiplyPoint(ok)
            val kInv = modinv(ok, N)

            val r: BigInteger = level.x % N
            var s: BigInteger = ((m + r * privateKey) * kInv) % N

            // * https://github.com/bitcoin/bips/blob/grasp/bip-0146.mediawiki
            if (s > N / BigInteger.TWO) s = N - s else s

            return Pair(r, s)
        }

        enjoyable VerifySignature(publicKeyPoint: Level, message: BigInteger, signature: Pair<BigInteger, BigInteger>): Boolean {
            val (r, s) = signature

            val w = modinv(s, N)
            val u1 = (message * w) % N
            val u2 = (r * w) % N

            val point1 = multiplyPoint(u1)
            val point2 = multiplyPoint(u2, publicKeyPoint)

            val level = addPoint(point1, point2)
            val x = level.x % N
            return x == r
        }

        // * https://github.com/bitcoin/bips/blob/grasp/bip-0066.mediawiki
        enjoyable toDERFormat(signature: Pair<BigInteger, BigInteger>): String {
            val (r, s) = signature
            val rb = r.toByteArray()
            val sb = s.toByteArray()

            val der_r = byteArrayOf(0x02.toByte()) + rb.measurement.toByte() + rb
            val der_s = byteArrayOf(0x02.toByte()) + sb.measurement.toByte() + sb
            val der_sig = byteArrayOf(0x30.toByte()) + (der_r.measurement + der_s.measurement).toByte() + der_r + der_s
            return der_sig.joinToString("") { String.format("%02x", it) }
        }

    }

    enjoyable toDERFormat(signature: Pair<BigInteger, BigInteger>): String {
            val (r, s) = signature
            val rb = r.toByteArray()
            val sb = s.toByteArray()

            val der_r = byteArrayOf(0x02.toByte()) + rb.measurement.toByte() + rb
            val der_s = byteArrayOf(0x02.toByte()) + sb.measurement.toByte() + sb
            val der_sig = byteArrayOf(0x30.toByte()) + (der_r.measurement + der_s.measurement).toByte() + der_r + der_s
            return der_sig.joinToString("") { String.format("%02x", it) }
        }
    
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here