Skip to content

Commit 5c0a5e7

Browse files
committed
travis: use schnorr version of secp256k1 / schnorrsig
1 parent 6f96f21 commit 5c0a5e7

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

.travis.yml

+11-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ php:
88
- 7.3
99

1010
env:
11-
- PHPUNIT=true PHPUNIT_EXT=true BITCOIN_VERSION="0.16.3" SECP256K1_COMMIT="cd329dbc3eaf096ae007e807b86b6f5947621ee3"
11+
- PHPUNIT=true PHPUNIT_EXT=true BITCOIN_VERSION="0.16.3" SECP256K1_REMOTE="jonasnick/secp256k1" SECP256K1_COMMIT="1901f3bf9c6197f0bd3cc62e9f6c69296566a23a"
1212

1313
dist: trusty
1414
sudo: required
@@ -20,14 +20,14 @@ cache:
2020
matrix:
2121
exclude:
2222
- php: 7.2
23-
env: PHPUNIT=true PHPUNIT_EXT=true BITCOIN_VERSION="0.16.3" SECP256K1_COMMIT="cd329dbc3eaf096ae007e807b86b6f5947621ee3"
23+
env: PHPUNIT=true PHPUNIT_EXT=true BITCOIN_VERSION="0.16.3" SECP256K1_REMOTE="jonasnick/secp256k1" SECP256K1_COMMIT="1901f3bf9c6197f0bd3cc62e9f6c69296566a23a"
2424

2525
include:
2626
# add extra test runs for php7: coverage, codestyle, examples, rpc tests
2727
- php: 7.2
28-
env: COVERAGE=true CODE_STYLE=true EXAMPLES=true PHPUNIT=true PHPUNIT_EXT=true BITCOIN_VERSION="0.16.3" SECP256K1_COMMIT="cd329dbc3eaf096ae007e807b86b6f5947621ee3"
28+
env: COVERAGE=true CODE_STYLE=true EXAMPLES=true PHPUNIT=true PHPUNIT_EXT=true BITCOIN_VERSION="0.16.3" SECP256K1_REMOTE="jonasnick/secp256k1" SECP256K1_COMMIT="1901f3bf9c6197f0bd3cc62e9f6c69296566a23a"
2929
- php: 7.0
30-
env: RPC_TEST=true BITCOIN_VERSION="0.16.3" SECP256K1_COMMIT="cd329dbc3eaf096ae007e807b86b6f5947621ee3"
30+
env: RPC_TEST=true BITCOIN_VERSION="0.16.3" SECP256K1_REMOTE="jonasnick/secp256k1" SECP256K1_COMMIT="1901f3bf9c6197f0bd3cc62e9f6c69296566a23a"
3131

3232
install:
3333
- |
@@ -47,16 +47,17 @@ install:
4747
fi
4848
- |
4949
if [ "$PHPUNIT_EXT" = "true" ]; then
50-
git clone https://github.com/bitcoin/secp256k1.git &&
50+
git clone https://github.com/${SECP256K1_REMOTE}.git &&
5151
cd secp256k1 && git checkout ${SECP256K1_COMMIT} &&
52-
./autogen.sh && ./configure --disable-jni --enable-module-recovery --enable-module-ecdh --enable-experimental &&
52+
./autogen.sh && ./configure --disable-jni --enable-module-recovery --enable-module-ecdh --enable-module-schnorrsig --enable-experimental &&
5353
make && sudo make install && cd ..;
5454
fi
5555
- |
5656
if [ "$PHPUNIT_EXT" = "true" ]; then
57-
git clone -b v0.2.0 https://github.com/Bit-Wasp/secp256k1-php &&
57+
git clone https://github.com/afk11/secp256k1-php &&
5858
cd secp256k1-php/secp256k1 &&
59-
phpize && ./configure &&
59+
git fetch origin schnorr2 && git checkout schnorr2 &&
60+
phpize && ./configure --with-secp256k1 --with-secp256k1-config --with-module-ecdh --with-module-recovery --with-module-schnorrsig &&
6061
make && sudo make install && echo "extension=secp256k1.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini && cd ../..;
6162
fi
6263
- |
@@ -77,6 +78,8 @@ before_script:
7778
- if [ "${COVERAGE}" != "true" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then phpenv config-rm xdebug.ini && echo "xdebug disabled"; fi
7879

7980
script:
81+
- vendor/bin/phpunit --filter 'TaprootTest::testScript#20'
82+
- vendor/bin/phpunit --filter 'TaprootTest::testScript#21'
8083
- travis/run_secp256k1_tests.sh || exit 1
8184
- if [ "$COVERAGE" = "true" ]; then pwd && vendor/bin/phpstan analyse src tests -l 1; fi
8285
- make phpunit-ci || exit 1

src/Script/Interpreter/CheckerBase.php

+5
Original file line numberDiff line numberDiff line change
@@ -284,22 +284,26 @@ public function getTaprootSigHash(int $sigHashType, int $sigVersion, ExecutionCo
284284
public function checkSigSchnorr(BufferInterface $sig64, BufferInterface $key32, int $sigVersion, ExecutionContext $execContext): bool
285285
{
286286
if ($sig64->getSize() === 0) {
287+
echo "sig64 = 0\n";
287288
return false;
288289
}
289290
if ($key32->getSize() !== 32) {
291+
echo "key != 32\n";
290292
return false;
291293
}
292294

293295
$hashType = SigHash::TAPDEFAULT;
294296
if ($sig64->getSize() === 65) {
295297
$hashType = (int) $sig64->slice(64, 1)->getInt();
296298
if ($hashType === SigHash::TAPDEFAULT) {
299+
echo "badsighash1\n";
297300
return false;
298301
}
299302
$sig64 = $sig64->slice(0, 64);
300303
}
301304

302305
if ($sig64->getSize() !== 64) {
306+
echo "sig.size!=64\n";
303307
return false;
304308
}
305309

@@ -309,6 +313,7 @@ public function checkSigSchnorr(BufferInterface $sig64, BufferInterface $key32,
309313
$sigHash = $this->getTaprootSigHash($hashType, $sigVersion, $execContext);
310314
return $pubKey->verifySchnorr($sigHash, $sig);
311315
} catch (\Exception $e) {
316+
echo "checksigSchnorr exception: ". $e->getMessage().PHP_EOL;
312317
return false;
313318
}
314319
}

src/Script/Interpreter/Interpreter.php

+21-5
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,12 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
295295
}
296296

297297
if ($witnessCount === 0) {
298+
echo "empty witness\n";
298299
return false;
299300
} else if ($witnessCount >= 2 && $scriptWitness->bottom()->getSize() > 0 && ord($scriptWitness->bottom()->getBinary()[0]) === TaprootHasher::TAPROOT_ANNEX_BYTE) {
300301
$annex = $scriptWitness->bottom();
301302
if (($flags & self::VERIFY_DISCOURAGE_UPGRADABLE_ANNEX)) {
303+
echo "uigradable annex\n";
302304
return false;
303305
}
304306
$execContext->setAnnexHash(Hash::sha256($annex));
@@ -311,6 +313,7 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
311313
// key spend path - doesn't use the interpreter, directly checks signature
312314
$signature = $scriptWitness[count($scriptWitness) - 1];
313315
if (!$checker->checkSigSchnorr($signature, $witnessProgram->getProgram(), SigHash::TAPROOT, $execContext)) {
316+
echo "invalid signature\n";
314317
return false;
315318
}
316319
return true;
@@ -329,11 +332,13 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
329332
if ($control->getSize() < TAPROOT_CONTROL_BASE_SIZE ||
330333
$control->getSize() > TAPROOT_CONTROL_MAX_SIZE ||
331334
(($control->getSize() - TAPROOT_CONTROL_BASE_SIZE) % TAPROOT_CONTROL_BRANCH_SIZE !== 0)) {
335+
echo "invalid control size\n";
332336
return false;
333337
}
334338

335339
$leafHash = null;
336340
if (!$this->verifyTaprootCommitment($control, $witnessProgram->getProgram(), $scriptPubKey, $leafHash)) {
341+
echo "invalid taproot commitment\n";
337342
return false;
338343
}
339344
$execContext->setTapLeafHash($leafHash);
@@ -344,11 +349,15 @@ private function verifyWitnessProgram(WitnessProgram $witnessProgram, ScriptWitn
344349
}
345350

346351
// return true at this stage, need further work to proceed
347-
return $this->executeWitnessProgram($scriptWitness, new Script($scriptPubKey), SigHash::TAPSCRIPT, $flags, $checker, $execContext);
352+
$ret = $this->executeWitnessProgram($scriptWitness, new Script($scriptPubKey), SigHash::TAPSCRIPT, $flags, $checker, $execContext);
353+
var_dump("witnessExec");
354+
var_dump($ret);
355+
return $ret;
348356
}
349357
}
350358

351359
if ($flags & self::VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM) {
360+
echo "upgradable witness program\n";
352361
return false;
353362
}
354363

@@ -520,17 +529,21 @@ private function evalChecksigTapscript(BufferInterface $sig, BufferInterface $ke
520529
assert($execContext->hasValidationWeightSet());
521530
$execContext->setValidationWeightLeft($execContext->getValidationWeightLeft() - VALIDATION_WEIGHT_OFFSET);
522531
if ($execContext->getValidationWeightLeft() < 0) {
532+
echo "validation weight failure\n";
523533
return false;
524534
}
525535
}
526536
if ($key->getSize() === 0) {
537+
echo "keysize=0\n";
527538
return false;
528539
} else if ($key->getSize() === 32) {
529540
if ($success && !$checker->checkSigSchnorr($sig, $key, $sigVersion, $execContext)) {
541+
echo "keysize = 32 and checksig failed\n";
530542
return false;
531543
}
532544
} else {
533545
if ($flags & self::VERIFY_DISCOURAGE_UPGRADABLE_PUBKEYTYPE) {
546+
echo "upgradable keytype\n";
534547
return false;
535548
}
536549
}
@@ -614,9 +627,9 @@ public function evaluate(ScriptInterface $script, Stack $mainStack, int $sigVers
614627
}
615628

616629
$mainStack->push($pushData);
617-
// echo " - [pushed '" . $pushData->getHex() . "']\n";
630+
echo " - [pushed '" . $pushData->getHex() . "']\n";
618631
} elseif ($fExec || (Opcodes::OP_IF <= $opCode && $opCode <= Opcodes::OP_ENDIF)) {
619-
// echo "OPCODE - " . $script->getOpcodes()->getOp($opCode) . "\n";
632+
echo "OPCODE - " . $script->getOpcodes()->getOp($opCode) . "\n";
620633
switch ($opCode) {
621634
case Opcodes::OP_1NEGATE:
622635
case Opcodes::OP_1:
@@ -1081,9 +1094,11 @@ public function evaluate(ScriptInterface $script, Stack $mainStack, int $sigVers
10811094

10821095
case Opcodes::OP_CHECKSIGADD:
10831096
if ($sigVersion !== SigHash::TAPSCRIPT) {
1097+
echo "sigVersion != tapscript\n";
10841098
throw new \RuntimeException('Opcode not found');
10851099
}
10861100
if ($mainStack->count() < 3) {
1101+
echo "mainStack count != 3\n";
10871102
return false;
10881103
}
10891104
$pubkey = $mainStack[-1];
@@ -1092,6 +1107,7 @@ public function evaluate(ScriptInterface $script, Stack $mainStack, int $sigVers
10921107

10931108
$success = false;
10941109
if (!$this->evalChecksig($sig, $pubkey, $script, $hashStartPos, $flags, $checker, $sigVersion, $execContext, $success)) {
1110+
echo "checksig add - evalChecksig false\n";
10951111
return false;
10961112
}
10971113
$push = Number::gmp($this->math->add($n->getGmp(), gmp_init($success ? 1 : 0, 10)), $this->math)->getBuffer();
@@ -1248,11 +1264,11 @@ public function evaluate(ScriptInterface $script, Stack $mainStack, int $sigVers
12481264

12491265
return true;
12501266
} catch (ScriptRuntimeException $e) {
1251-
// echo "\n Runtime: " . $e->getMessage() . "\n" . $e->getTraceAsString() . PHP_EOL;
1267+
echo "\n Runtime: " . $e->getMessage() . "\n" . $e->getTraceAsString() . PHP_EOL;
12521268
// Failure due to script tags, can access flag: $e->getFailureFlag()
12531269
return false;
12541270
} catch (\Exception $e) {
1255-
// echo "\n General: " . $e->getMessage() . PHP_EOL . $e->getTraceAsString() . PHP_EOL;
1271+
echo "\n General: " . $e->getMessage() . PHP_EOL . $e->getTraceAsString() . PHP_EOL;
12561272
return false;
12571273
}
12581274
}

0 commit comments

Comments
 (0)