Skip to content

Commit

Permalink
use latest rabin
Browse files Browse the repository at this point in the history
  • Loading branch information
xhliu committed Mar 28, 2020
1 parent 286b74d commit 377be4c
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions docs/rabin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,25 @@
Rabin Signature
===============

`Rabin signature <https://nchain.com/app/uploads/2018/09/Rabin-Signatures-in-Bitcoin-Cash.pdf>`_ is an alternative form of digital signature to ECDSA used in Bitcoin.
`Rabin signature <https://medium.com/@xiaohuiliu/access-external-data-from-bitcoin-smart-contracts-2ecdc7448c43>`_ is an alternative form of digital signature to ECDSA used in Bitcoin.

.. code-block:: solidity
contract RabinSignature {
Ripemd160 nHash; // nHash = b"88d9931ea73d60eaf7e5671efc0552b912911f2a"
function hash3072(bytes x) returns (bytes) {
Sha256 y = sha256(x);
int i = 0;
// start with empty
bytes ret = b"";
// divide into 3072 / 256 = 12 slices
loop (12) {
// 256 bits is 32 bytes
bytes slice = y[32 * i : 32 * (i + 1)];
ret = ret ++ sha256(slice);
i = i + 1;
}
// 3072 bit hash
return ret;
public function verifySig(int sig, bytes msg, bytes padding, int n) {
int h = this.fromLEUnsigned(this.hash(msg ++ padding));
require((sig * sig) % n == h % n);
}
public function verifySig(int S, bytes U, bytes m, int lambda, bytes n) {
require(hash160(n) == this.nHash);
function hash(bytes x) returns (bytes) {
// expand into 512 bit hash
bytes hx = sha256(x);
int idx = length(hx) / 2;
return sha256(hx[:idx]) ++ sha256(hx[idx:]);
}
int h = unpack(this.hash3072(m ++ U));
require(S * S == h + lambda * unpack(n));
function fromLEUnsigned(bytes b) returns (int) {
// append positive sign byte. This does not hurt even when sign bit is already positive
return unpack(b ++ b"00");
}
}

0 comments on commit 377be4c

Please sign in to comment.