Skip to content

Commit

Permalink
replace "++" with "+" for concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
xhliu committed Jun 3, 2020
1 parent e0171b8 commit 407d0a3
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions contracts/ackermann.scrypt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ contract Ackermann {
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
8 changes: 4 additions & 4 deletions contracts/advancedCounter.scrypt
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ contract AdvancedCounter {
int counter = unpack(scriptCode[scriptLen - 1 :]);

// Expect the counter to be incremented in the new transaction state
bytes scriptCode_ = scriptCode[: scriptLen - 1] ++ num2bin(counter + 1, 1);
bytes scriptCode_ = scriptCode[: scriptLen - 1] + num2bin(counter + 1, 1);

bytes counterOutput = num2bin(amount, 8) ++ Util.writeVarint(scriptCode_);
bytes counterOutput = num2bin(amount, 8) + Util.writeVarint(scriptCode_);

// Expect the additional CHANGE output
bytes changeScript = Util.buildPublicKeyHashScript(changePKH);
bytes changeOutput = num2bin(changeSats, 8) ++ Util.writeVarint(changeScript);
bytes changeOutput = num2bin(changeSats, 8) + Util.writeVarint(changeScript);

// output: amount + scriptlen + script
Sha256 hashOutputs_ = hash256(counterOutput ++ changeOutput);
Sha256 hashOutputs_ = hash256(counterOutput + changeOutput);

// ensure output matches what we expect:
// - amount is same as specified
Expand Down
10 changes: 5 additions & 5 deletions contracts/advancedTokenSale.scrypt
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ contract AdvancedTokenSale {
// data after the OP_RETURN is a growing list of sales entries:
// PubKeyA,numTokensPurchased
// PubKeyB,numTokensPurchased
bytes newSalesEntry = buyer ++ num2bin(numTokens, 1);
bytes newSalesEntry = buyer + num2bin(numTokens, 1);

// expect the latest sales entry to be appended to the previous script/state
bytes scriptCode_ = scriptCode ++ Util.writeVarint(newSalesEntry);
bytes scriptCode_ = scriptCode + Util.writeVarint(newSalesEntry);

// output: amount + scriptlen + script
bytes counterOutput = num2bin(newBalance, 8) ++ Util.writeVarint(scriptCode_);
bytes counterOutput = num2bin(newBalance, 8) + Util.writeVarint(scriptCode_);

// Expect the additional CHANGE output
bytes changeScript = Util.buildPublicKeyHashScript(changePKH);
// output: amount + scriptlen + script
bytes changeOutput = num2bin(changeSats, 8) ++ Util.writeVarint(changeScript);
bytes changeOutput = num2bin(changeSats, 8) + Util.writeVarint(changeScript);

// expect exactly two outputs
Sha256 hashOutputs_ = hash256(counterOutput ++ changeOutput);
Sha256 hashOutputs_ = hash256(counterOutput + changeOutput);

// ensure output matches what we expect:
// - amount/balance reflects funds received from sale
Expand Down
4 changes: 2 additions & 2 deletions contracts/counter.scrypt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ contract Counter {
// last byte contains the state, i.e., counter
int counter = unpack(scriptCode[scriptLen - 1 :]);
// increment counter
bytes scriptCode_ = scriptCode[: scriptLen - 1] ++ num2bin(counter + 1, 1);
bytes scriptCode_ = scriptCode[: scriptLen - 1] + num2bin(counter + 1, 1);
// output: amount + scriptlen + script
Sha256 hashOutputs_ = hash256(num2bin(amount, 8) ++ Util.writeVarint(scriptCode_));
Sha256 hashOutputs_ = hash256(num2bin(amount, 8) + Util.writeVarint(scriptCode_));
// ensure output is expected: amount is same with specified
// also output script is the same with scriptCode except counter incremented
require(hashOutputs == hashOutputs_);
Expand Down
6 changes: 3 additions & 3 deletions contracts/rabin.scrypt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import "util.scrypt";

contract RabinSignature {
public function verifySig(int sig, bytes msg, bytes padding, int n) {
int h = Util.fromLEUnsigned(this.hash(msg ++ padding));
int h = Util.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');
}
}
4 changes: 2 additions & 2 deletions contracts/token.scrypt
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ contract Token {
}

// write new locking script
bytes lockingScript_ = lockingScript[: scriptLen - 68] ++ pk0 ++ num2bin(balance0, 1) ++ pk1 ++ num2bin(balance1, 1);
bytes lockingScript_ = lockingScript[: scriptLen - 68] + pk0 + num2bin(balance0, 1) + pk1 + num2bin(balance1, 1);
int len = length(txPreimage);
bytes hashOutputs = txPreimage[len - 40 : len - 8];
Sha256 hashOutputs_ = hash256(num2bin(amount, 8) ++ Util.writeVarint(lockingScript_));
Sha256 hashOutputs_ = hash256(num2bin(amount, 8) + Util.writeVarint(lockingScript_));
require(hashOutputs == hashOutputs_);
}
}
4 changes: 2 additions & 2 deletions contracts/tokensale.scrypt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ contract TokenSale {
int newBalance = oldBalance + numTokens * this.price;

// write new locking script
bytes lockingScript_ = lockingScript ++ b'22' /* "OP_PUSHDATA0" */ ++ buyer ++ num2bin(numTokens, 1);
bytes lockingScript_ = lockingScript + b'22' /* "OP_PUSHDATA0" */ + buyer + num2bin(numTokens, 1);
int len = length(txPreimage);
bytes hashOutputs = txPreimage[len - 40 : len - 8];
Sha256 hashOutputs_ = hash256(num2bin(newBalance, 8) ++ Util.writeVarint(lockingScript_));
Sha256 hashOutputs_ = hash256(num2bin(newBalance, 8) + Util.writeVarint(lockingScript_));
require(hashOutputs == hashOutputs_);
}
}
12 changes: 6 additions & 6 deletions contracts/util.scrypt
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ contract Util {
if (n < 0xfd) {
header = this.toLEUnsigned(n, 1);
} else if (n < 0x10000) {
header = b'fd' ++ this.toLEUnsigned(n, 2);
header = b'fd' + this.toLEUnsigned(n, 2);
} else if (n < 0x100000000) {
header = b'fe' ++ this.toLEUnsigned(n, 4);
header = b'fe' + this.toLEUnsigned(n, 4);
} else if (n < 0x10000000000000000) {
header = b'ff' ++ this.toLEUnsigned(n, 8);
header = b'ff' + this.toLEUnsigned(n, 8);
}

return header ++ b;
return header + b;
}

// convert signed integer `n` to unsigned integer of `len` bytes, in little endian
Expand All @@ -49,10 +49,10 @@ contract Util {

static 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');
}

static function buildPublicKeyHashScript(Ripemd160 pubKeyHash) returns (bytes) {
return OpCode.OP_DUP ++ OpCode.OP_HASH160 ++ b'14' /* "OP_PUSHDATA0" */ ++ pubKeyHash ++ OpCode.OP_EQUALVERIFY ++ OpCode.OP_CHECKSIG;
return OpCode.OP_DUP + OpCode.OP_HASH160 + b'14' /* "OP_PUSHDATA0" */ + pubKeyHash + OpCode.OP_EQUALVERIFY + OpCode.OP_CHECKSIG;
}
}

0 comments on commit 407d0a3

Please sign in to comment.