opcodeCheckSig treats the top 2 items on the stack as a public key and a signature and replaces them with a bool which indicates if the signature was successfully verified. The process of verifying a signature requires calculating a signature hash in the same way the transaction signer did. It inv
(op *opcode, data []byte, vm *Engine)
| 1975 | // |
| 1976 | // Stack transformation: [... signature pubkey] -> [... bool] |
| 1977 | func opcodeCheckSig(op *opcode, data []byte, vm *Engine) error { |
| 1978 | pkBytes, err := vm.dstack.PopByteArray() |
| 1979 | if err != nil { |
| 1980 | return err |
| 1981 | } |
| 1982 | |
| 1983 | fullSigBytes, err := vm.dstack.PopByteArray() |
| 1984 | if err != nil { |
| 1985 | return err |
| 1986 | } |
| 1987 | |
| 1988 | // The signature actually needs to be longer than this, but at |
| 1989 | // least 1 byte is needed for the hash type below. The full length is |
| 1990 | // checked depending on the script flags and upon parsing the signature. |
| 1991 | // |
| 1992 | // This only applies if tapscript verification isn't active, as this |
| 1993 | // check is done within the sighash itself. |
| 1994 | if vm.taprootCtx == nil && len(fullSigBytes) < 1 { |
| 1995 | if err := vm.checkPubKeyEncoding(pkBytes); err != nil { |
| 1996 | return err |
| 1997 | } |
| 1998 | |
| 1999 | vm.dstack.PushBool(false) |
| 2000 | return nil |
| 2001 | } |
| 2002 | |
| 2003 | var sigVerifier signatureVerifier |
| 2004 | switch { |
| 2005 | // If no witness program is active, then we're verifying under the |
| 2006 | // base consensus rules. |
| 2007 | case vm.witnessProgram == nil: |
| 2008 | sigVerifier, err = newBaseSigVerifier( |
| 2009 | pkBytes, fullSigBytes, vm, |
| 2010 | ) |
| 2011 | if err != nil { |
| 2012 | var scriptErr Error |
| 2013 | if errors.As(err, &scriptErr) { |
| 2014 | return err |
| 2015 | } |
| 2016 | |
| 2017 | vm.dstack.PushBool(false) |
| 2018 | return nil |
| 2019 | } |
| 2020 | |
| 2021 | // If the base segwit version is active, then we'll create the verifier |
| 2022 | // that factors in those new consensus rules. |
| 2023 | case vm.isWitnessVersionActive(BaseSegwitWitnessVersion): |
| 2024 | sigVerifier, err = newBaseSegwitSigVerifier( |
| 2025 | pkBytes, fullSigBytes, vm, |
| 2026 | ) |
| 2027 | if err != nil { |
| 2028 | var scriptErr Error |
| 2029 | if errors.As(err, &scriptErr) { |
| 2030 | return err |
| 2031 | } |
| 2032 | |
| 2033 | vm.dstack.PushBool(false) |
| 2034 | return nil |
no test coverage detected
searching dependent graphs…