Skip to content

Commit

Permalink
update syntax in sync w/ scrypt 0.1.20
Browse files Browse the repository at this point in the history
1) ++ -> +
2) SigHashType & OpCodeType
3) Tx.checkPreimage()
4) auto
5) static property
  • Loading branch information
xhliu committed Jun 11, 2020
1 parent ebbd2dd commit ad3f522
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
6 changes: 3 additions & 3 deletions docs/ackermann.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ nCrypt has devised a way to calculate the value of the Ackermann function using
n = n + 1;
m = m - 1;
// push
stk = num2bin(m, 1) ++ stk;
stk = num2bin(m, 1) + stk;
} else {
stk = num2bin(m - 1, 1) ++ stk;
stk = num2bin(m, 1) ++ stk;
stk = num2bin(m - 1, 1) + stk;
stk = num2bin(m, 1) + stk;
n = n - 1;
}
}
Expand Down
7 changes: 3 additions & 4 deletions docs/contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ As an example, contract ``CheckLockTimeVerify`` ensures coins are timelocked and
int matureTime;
public function spend(bytes sighashPreimage) {
Tx tx = new Tx();
// this ensures the preimage is for the current tx
require(tx.validate(sighashPreimage));
require(Tx.checkPreimage(txPreimage));
// parse nLocktime
int len = length(sighashPreimage);
Expand All @@ -125,7 +124,7 @@ As an example, contract ``CheckLockTimeVerify`` ensures coins are timelocked and
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');
return unpack(b + b'00');
}
}
Expand Down Expand Up @@ -157,7 +156,7 @@ Full List

* - Tx
- None
- validate(bytes sighashPreimage)
- checkPreimage(bytes sighashPreimage)

.. [#] ``X`` is hashing function and can be Ripemd160/Sha1/Sha256/Hash160
.. [#] ``Y`` is hashing function return type and can be Ripemd160/Sha1/Sha256/Ripemd160
Expand Down
17 changes: 10 additions & 7 deletions docs/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,22 @@ is functionally equivalent to
return true;
}
static function
---------------
A static function can be called with contract name without an instantiated contract, similar to a static function in Javascript or C++.
static function and property
----------------------------
A static function/property can be referenced with contract name without an instantiated contract, similar to a static function/property in Javascript or C+.

.. code-block:: solidity
contract Foo {
static function sum(int a, int b) returns (int) {
return a + b;
int i;
static int N = 0;
static function incByN(int a) returns (int) {
return a + Foo.N;
}
function double(int x) returns (int) {
return this.sum(x, x);
return Foo.incByN(x) + this.i;
}
}
Expand Down Expand Up @@ -136,7 +139,7 @@ bytes Operations
// b[:4] == b'00112233'
// b[5:] = b'556677'
* ``b1 ++ b2``
* ``b1 + b2``

Returns the concatenation of bytes ``b1`` and bytes ``b2``.

Expand Down
4 changes: 2 additions & 2 deletions docs/multipartyhashpuzzles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ Instead, we can combine all ``y``'s into a single y such that ``y = H(H(y1 || y2
Sha256 hash1 = sha256(preimage1);
Sha256 hash2 = sha256(preimage2);
Sha256 hash3 = sha256(preimage3);
Sha256 hash12 = sha256(hash1 ++ hash2);
Sha256 hash123 = sha256(hash12 ++ hash3);
Sha256 hash12 = sha256(hash1 + hash2);
Sha256 hash123 = sha256(hash12 + hash3);
require(hash123 == this.combinedHash);
}
Expand Down
6 changes: 3 additions & 3 deletions docs/rabin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ Rabin Signature
contract RabinSignature {
public function verifySig(int sig, bytes msg, bytes padding, int n) {
int h = this.fromLEUnsigned(this.hash(msg ++ padding));
int h = this.fromLEUnsigned(this.hash(msg + padding));
require((sig * sig) % n == h % n);
}
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:]);
return sha256(hx[:idx]) + sha256(hx[idx:]);
}
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');
return unpack(b + b'00');
}
}
8 changes: 7 additions & 1 deletion docs/syntax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ where the most significant bit indicates the sign (``0`` for positive, ``1`` for
int a4 = unpack(b'e883'); // -1000
bytes b = pack(a4); // b'e883'
* **auto** keyword - The ``auto`` keyword specifies that the type of the variable, of basic type, declared will be automatically deducted from its initializer.

.. code-block:: solidity
auto a1 = b'36'; // bytes a1 = b'36';
auto a2 = 1 + 5 * 3; // int a2 = 1 + 5 * 3;
Subtypes of ``bytes``
---------------------
Expand Down Expand Up @@ -121,7 +127,7 @@ To cast a supertype ``bytes`` to them, a function of the type name must be expli

.. code-block:: solidity
OpCodeType s = OpCode.OP_DUP ++ OpCode.OP_ADD;
OpCodeType s = OpCode.OP_DUP + OpCode.OP_ADD;
Subtypes of ``int``
---------------------
Expand Down

0 comments on commit ad3f522

Please sign in to comment.