Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
add travis ci (#154)
Browse files Browse the repository at this point in the history
* add travis ci

* build c directory

* rust tests
  • Loading branch information
ewilz authored May 22, 2020
1 parent dca7b82 commit e48683a
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "c/deps/ckb-c-stdlib"]
path = c/deps/ckb-c-stdlib
url = git@github.com:nervosnetwork/ckb-c-stdlib.git
url = https://github.com/nervosnetwork/ckb-c-stdlib.git
69 changes: 69 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
matrix:
include:
- language: go
go: 1.13.1
env:
- GO111MODULE=on
before_script:
- cd golang
- curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.20.0
script:
- go test ./btcspv

- language: node_js
node_js: 10.14.2
before_script:
- cp testVectors.json solidity/test
- cd solidity
- npm install -g truffle
- npm install
script:
- npm run lint
- npm run test

- language: node_js
node_js: 10.14.2
before_script:
- cd js
- npm install
script:
- npm run lint
- npm run test

- language: python
python:
- "3.6"
before_install:
- cd python
- pip install pipenv
install:
- pipenv install --dev
script:
- pipenv run test

- language: rust
rust: stable
cache:
directories:
- ./target
- /home/travis/.cargo
before_install:
- cd c
- sudo apt-get install build-essential
- sudo apt-get install check
install:
- make setup
script:
- make

- language: rust
rust: stable
cache:
directories:
- ./target
- /home/travis/.cargo
before_script:
- cd rust
script:
- cargo test
- cargo test --no-default-features
37 changes: 19 additions & 18 deletions solidity/contracts/BTCUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ library BTCUtils {
/// @param _b A byte-string starting with a VarInt
/// @return number of bytes in the encoding (not counting the tag), the encoded int
function parseVarInt(bytes memory _b) internal pure returns (uint256, uint256) {
uint8 _dataLen = determineVarIntDataLength(_b);
uint8 _dataLen = determineVarIntDataLength(_b);

if (_dataLen == 0) {
return (0, uint8(_b[0]));
}
if (_b.length < 1 + _dataLen) {
return (ERR_BAD_ARG, 0);
}
uint256 _number = bytesToUint(reverseEndianness(_b.slice(1, _dataLen)));
return (_dataLen, _number);
if (_dataLen == 0) {
return (0, uint8(_b[0]));
}
if (_b.length < 1 + _dataLen) {
return (ERR_BAD_ARG, 0);
}
uint256 _number = bytesToUint(reverseEndianness(_b.slice(1, _dataLen)));
return (_dataLen, _number);
}

/// @notice Changes the endianness of a byte array
Expand Down Expand Up @@ -140,6 +140,7 @@ library BTCUtils {
/// @param _b The pre-image
/// @return The digest
function hash256View(bytes memory _b) internal view returns (bytes32 res) {
// solium-disable-next-line security/no-inline-assembly
assembly {
let ptr := mload(0x40)
pop(staticcall(gas, 2, add(_b, 32), mload(_b), ptr, 32))
Expand Down Expand Up @@ -197,7 +198,7 @@ library BTCUtils {
/// @return The length of the script sig
function extractScriptSigLen(bytes memory _input) internal pure returns (uint256, uint256) {
if (_input.length < 37) {
return (ERR_BAD_ARG, 0);
return (ERR_BAD_ARG, 0);
}
bytes memory _afterOutpoint = _input.slice(36, _input.length - 36);

Expand All @@ -217,7 +218,7 @@ library BTCUtils {
uint256 _scriptSigLen;
(_varIntDataLen, _scriptSigLen) = extractScriptSigLen(_input);
if (_varIntDataLen == ERR_BAD_ARG) {
return ERR_BAD_ARG;
return ERR_BAD_ARG;
}

return 36 + 1 + _varIntDataLen + _scriptSigLen + 4;
Expand Down Expand Up @@ -313,7 +314,7 @@ library BTCUtils {
/// @return The length indicated by the prefix, error if invalid length
function determineOutputLength(bytes memory _output) internal pure returns (uint256) {
if (_output.length < 9) {
return ERR_BAD_ARG;
return ERR_BAD_ARG;
}
bytes memory _afterValue = _output.slice(8, _output.length - 8);

Expand All @@ -322,7 +323,7 @@ library BTCUtils {
(_varIntDataLen, _scriptPubkeyLength) = parseVarInt(_afterValue);

if (_varIntDataLen == ERR_BAD_ARG) {
return ERR_BAD_ARG;
return ERR_BAD_ARG;
}

// 8 byte value, 1 byte for tag itself
Expand Down Expand Up @@ -406,7 +407,7 @@ library BTCUtils {
if (uint8(_output.slice(9, 1)[0]) == 0) {
uint256 _len = uint8(extractOutputScriptLen(_output)[0]);
if (_len < 2) {
return hex"";
return hex"";
}
_len -= 2;
// Check for maliciously formatted witness outputs
Expand Down Expand Up @@ -461,14 +462,14 @@ library BTCUtils {
for (uint256 i = 0; i < _nIns; i++) {
// If we're at the end, but still expect more
if (_offset >= _vin.length) {
return false;
return false;
}

// Grab the next input and determine its length.
bytes memory _next = _vin.slice(_offset, _vin.length - _offset);
uint256 _nextLen = determineInputLength(_next);
if (_nextLen == ERR_BAD_ARG) {
return false;
return false;
}

// Increase the offset by that much
Expand Down Expand Up @@ -499,15 +500,15 @@ library BTCUtils {
for (uint256 i = 0; i < _nOuts; i++) {
// If we're at the end, but still expect more
if (_offset >= _vout.length) {
return false;
return false;
}

// Grab the next output and determine its length.
// Increase the offset by that much
bytes memory _next = _vout.slice(_offset, _vout.length - _offset);
uint256 _nextLen = determineOutputLength(_next);
if (_nextLen == ERR_BAD_ARG) {
return false;
return false;
}

_offset += _nextLen;
Expand Down
24 changes: 12 additions & 12 deletions solidity/contracts/CheckBitcoinSigs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ library CheckBitcoinSigs {
bytes20 _outputPKH // 20 byte hash160
) internal pure returns (bytes32) {
return wpkhSpendSighash(
_outpoint,
_inputPKH,
_inputValue,
_outputValue,
abi.encodePacked(
_outpoint,
_inputPKH,
_inputValue,
_outputValue,
abi.encodePacked(
hex"160014", // wpkh tag
_outputPKH)
);
);
}

/// @notice Preserved for API compatibility with older version
Expand All @@ -193,13 +193,13 @@ library CheckBitcoinSigs {
/// @param _outputPKH the output pubkeyhash (hash160(recipient_pubkey))
/// @return the double-sha256 (hash256) signature hash as defined by bip143
function oneInputOneOutputSighash(
bytes memory _outpoint, // 36 byte UTXO id
bytes20 _inputPKH, // 20 byte hash160
bytes8 _inputValue, // 8-byte LE
bytes8 _outputValue, // 8-byte LE
bytes20 _outputPKH // 20 byte hash160
bytes memory _outpoint, // 36 byte UTXO id
bytes20 _inputPKH, // 20 byte hash160
bytes8 _inputValue, // 8-byte LE
bytes8 _outputValue, // 8-byte LE
bytes20 _outputPKH // 20 byte hash160
) internal pure returns (bytes32) {
return wpkhToWpkhSighash(_outpoint, _inputPKH, _inputValue, _outputValue, _outputPKH);
return wpkhToWpkhSighash(_outpoint, _inputPKH, _inputValue, _outputValue, _outputPKH);
}

}
13 changes: 11 additions & 2 deletions solidity/contracts/TypedMemView.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ library TypedMemView {
/// Create a mask with the highest `_len` bits set
function leftMask(uint8 _len) private pure returns (uint256 mask) {
assembly {
// solium-disable-previous-line security/no-inline-assembly
mask := sar(
sub(_len, 1),
0x8000000000000000000000000000000000000000000000000000000000000000
Expand Down Expand Up @@ -77,9 +78,10 @@ library TypedMemView {
/// memory pointer and ensuring that the view's upper bound is less than
/// that.
function isValid(bytes32 memView) internal pure returns (bool ret) {
if (typeOf(memView) == 0xffff) { return false; }
if (typeOf(memView) == 0xffff) {return false;}
uint256 _end = end(memView);
assembly {
// solium-disable-previous-line security/no-inline-assembly
ret := lt(_end, mload(0x40))
}
}
Expand All @@ -98,6 +100,7 @@ library TypedMemView {
function build(uint256 _type, uint256 _loc, uint256 _len) internal pure returns (bytes32) {
uint256 _end = _loc.add(_len);
assembly {
// solium-disable-previous-line security/no-inline-assembly
if gt(_end, mload(0x40)) {
_end := 0
}
Expand All @@ -124,6 +127,7 @@ library TypedMemView {

uint256 _loc;
assembly {
// solium-disable-previous-line security/no-inline-assembly
_loc := add(arr, 0x20) // our view is of the data, not the struct
}

Expand All @@ -134,6 +138,7 @@ library TypedMemView {
function typeOf(bytes32 memView) internal pure returns (uint16 _type) {
uint256 _mask = leftMask(16); // first two bytes
assembly {
// solium-disable-previous-line security/no-inline-assembly
_type := shr(240, and(memView, _mask)) // shift out lower 30
}
}
Expand Down Expand Up @@ -197,13 +202,14 @@ library TypedMemView {
/// This can be immediately cast to a smaller fixed-length byte array.
/// To automatically cast to an integer, use `indexUint` or `indexInt`.
function index(bytes32 memView, uint256 _index, uint8 _bytes) internal pure returns (bytes32 result) {
if (_bytes == 0) { return bytes32(0); }
if (_bytes == 0) {return bytes32(0);}
require(_index.add(_bytes) <= len(memView), "TypedMemView/index - Overran the view.");
require(_bytes <= 32, "TypedMemView/index - Attempted to index more than 32 bytes");
uint8 bitLength = _bytes * 8;
uint256 _loc = loc(memView);
uint256 mask = leftMask(bitLength);
assembly {
// solium-disable-previous-line security/no-inline-assembly
result := and(mload(add(_loc, _index)), mask)
}
}
Expand All @@ -230,6 +236,7 @@ library TypedMemView {
uint256 _loc = loc(memView);
uint256 _len = len(memView);
assembly {
// solium-disable-previous-line security/no-inline-assembly
digest := keccak256(_loc, _len)
}
}
Expand All @@ -241,6 +248,7 @@ library TypedMemView {

// for cleanliness, avoid growing the free pointer
assembly {
// solium-disable-previous-line security/no-inline-assembly
mstore(0x40, copy)
}
}
Expand Down Expand Up @@ -276,6 +284,7 @@ library TypedMemView {
uint256 _loc = loc(memView);
uint256 _len = len(memView);
assembly {
// solium-disable-previous-line security/no-inline-assembly
ret := mload(0x40) // load unused pointer to the array
mstore(0x40, add(add(ret, _footprint), 0x20)) // write new unused pointer
mstore(ret, _len) // write len of new array (in bytes)
Expand Down
2 changes: 2 additions & 0 deletions solidity/contracts/test/TestMemView.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ contract TestMemView {

function slicing() public pure {
// 76 bytes - 3 words

// solium-disable-next-line max-len
bytes memory one = hex"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b";

bytes32 v1 = TypedMemView.ref(one, 1);
Expand Down

0 comments on commit e48683a

Please sign in to comment.