aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts
diff options
context:
space:
mode:
authorRemco Bloemen <remco@wicked.ventures>2018-06-13 17:53:22 +0800
committerRemco Bloemen <remco@wicked.ventures>2018-06-23 19:53:38 +0800
commitafd83e59b8bf2b755e589562ab12b300aaf12601 (patch)
treea18d81556c9034f5e755c9bc96b1917b9b46901d /packages/contracts
parent7f84049538af09e7596623158e1364a68bb17a35 (diff)
downloaddexon-sol-tools-afd83e59b8bf2b755e589562ab12b300aaf12601.tar
dexon-sol-tools-afd83e59b8bf2b755e589562ab12b300aaf12601.tar.gz
dexon-sol-tools-afd83e59b8bf2b755e589562ab12b300aaf12601.tar.bz2
dexon-sol-tools-afd83e59b8bf2b755e589562ab12b300aaf12601.tar.lz
dexon-sol-tools-afd83e59b8bf2b755e589562ab12b300aaf12601.tar.xz
dexon-sol-tools-afd83e59b8bf2b755e589562ab12b300aaf12601.tar.zst
dexon-sol-tools-afd83e59b8bf2b755e589562ab12b300aaf12601.zip
Make LibBytes a library
Diffstat (limited to 'packages/contracts')
-rw-r--r--packages/contracts/src/contracts/current/protocol/AssetProxy/MixinERC20Transfer.sol3
-rw-r--r--packages/contracts/src/contracts/current/protocol/AssetProxy/MixinERC721Transfer.sol7
-rw-r--r--packages/contracts/src/contracts/current/protocol/AssetProxyOwner/AssetProxyOwner.sol3
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol18
-rw-r--r--packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol32
-rw-r--r--packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol2
6 files changed, 30 insertions, 35 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxy/MixinERC20Transfer.sol b/packages/contracts/src/contracts/current/protocol/AssetProxy/MixinERC20Transfer.sol
index 4af39a00b..34da13fcc 100644
--- a/packages/contracts/src/contracts/current/protocol/AssetProxy/MixinERC20Transfer.sol
+++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/MixinERC20Transfer.sol
@@ -24,7 +24,6 @@ import "../../tokens/ERC20Token/IERC20Token.sol";
import "./libs/LibTransferErrors.sol";
contract MixinERC20Transfer is
- LibBytes,
LibTransferErrors
{
/// @dev Internal version of `transferFrom`.
@@ -41,7 +40,7 @@ contract MixinERC20Transfer is
internal
{
// Decode asset data.
- address token = readAddress(assetData, 0);
+ address token = LibBytes.readAddress(assetData, 0);
// Transfer tokens.
// We do a raw call so we can check the success separate
diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxy/MixinERC721Transfer.sol b/packages/contracts/src/contracts/current/protocol/AssetProxy/MixinERC721Transfer.sol
index 6e3156e8a..028f4ed8a 100644
--- a/packages/contracts/src/contracts/current/protocol/AssetProxy/MixinERC721Transfer.sol
+++ b/packages/contracts/src/contracts/current/protocol/AssetProxy/MixinERC721Transfer.sol
@@ -24,7 +24,6 @@ import "../../tokens/ERC721Token/ERC721Token.sol";
import "./libs/LibTransferErrors.sol";
contract MixinERC721Transfer is
- LibBytes,
LibTransferErrors
{
/// @dev Internal version of `transferFrom`.
@@ -78,10 +77,10 @@ contract MixinERC721Transfer is
)
{
// Decode asset data.
- token = readAddress(assetData, 0);
- tokenId = readUint256(assetData, 20);
+ token = LibBytes.readAddress(assetData, 0);
+ tokenId = LibBytes.readUint256(assetData, 20);
if (assetData.length > 52) {
- receiverData = readBytes(assetData, 52);
+ receiverData = LibBytes.readBytes(assetData, 52);
}
return (
diff --git a/packages/contracts/src/contracts/current/protocol/AssetProxyOwner/AssetProxyOwner.sol b/packages/contracts/src/contracts/current/protocol/AssetProxyOwner/AssetProxyOwner.sol
index 7f5f056b5..4d5e5f786 100644
--- a/packages/contracts/src/contracts/current/protocol/AssetProxyOwner/AssetProxyOwner.sol
+++ b/packages/contracts/src/contracts/current/protocol/AssetProxyOwner/AssetProxyOwner.sol
@@ -22,7 +22,6 @@ import "../../multisig/MultiSigWalletWithTimeLock.sol";
import "../../utils/LibBytes/LibBytes.sol";
contract AssetProxyOwner is
- LibBytes,
MultiSigWalletWithTimeLock
{
@@ -104,7 +103,7 @@ contract AssetProxyOwner is
pure
returns (bool)
{
- bytes4 first4Bytes = readFirst4(data);
+ bytes4 first4Bytes = LibBytes.readFirst4(data);
require(REMOVE_AUTHORIZED_ADDRESS_SELECTOR == first4Bytes);
return true;
}
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
index 881d6e7b3..4a6bb5de5 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
@@ -26,7 +26,6 @@ import "./interfaces/IWallet.sol";
import "./interfaces/IValidator.sol";
contract MixinSignatureValidator is
- LibBytes,
LibExchangeErrors,
MSignatureValidator,
MTransactions
@@ -102,7 +101,7 @@ contract MixinSignatureValidator is
);
// Ensure signature is supported
- uint8 signatureTypeRaw = uint8(popLastByte(signature));
+ uint8 signatureTypeRaw = uint8(LibBytes.popLastByte(signature));
require(
signatureTypeRaw < uint8(SignatureType.NSignatureTypes),
SIGNATURE_UNSUPPORTED
@@ -144,8 +143,8 @@ contract MixinSignatureValidator is
LENGTH_65_REQUIRED
);
v = uint8(signature[0]);
- r = readBytes32(signature, 1);
- s = readBytes32(signature, 33);
+ r = LibBytes.readBytes32(signature, 1);
+ s = LibBytes.readBytes32(signature, 33);
recovered = ecrecover(hash, v, r, s);
isValid = signerAddress == recovered;
return isValid;
@@ -157,8 +156,8 @@ contract MixinSignatureValidator is
LENGTH_65_REQUIRED
);
v = uint8(signature[0]);
- r = readBytes32(signature, 1);
- s = readBytes32(signature, 33);
+ r = LibBytes.readBytes32(signature, 1);
+ s = LibBytes.readBytes32(signature, 33);
recovered = ecrecover(
keccak256(abi.encodePacked(ETH_PERSONAL_MESSAGE, hash)),
v,
@@ -199,7 +198,8 @@ contract MixinSignatureValidator is
// | 0x14 + x | 1 | Signature type is always "\x06" |
} else if (signatureType == SignatureType.Validator) {
// Pop last 20 bytes off of signature byte array.
- address validatorAddress = popLast20Bytes(signature);
+ address validatorAddress = LibBytes.popLast20Bytes(signature);
+
// Ensure signer has approved validator.
if (!allowedValidators[signerAddress][validatorAddress]) {
return false;
@@ -230,8 +230,8 @@ contract MixinSignatureValidator is
LENGTH_65_REQUIRED
);
v = uint8(signature[0]);
- r = readBytes32(signature, 1);
- s = readBytes32(signature, 33);
+ r = LibBytes.readBytes32(signature, 1);
+ s = LibBytes.readBytes32(signature, 33);
recovered = ecrecover(
keccak256(abi.encodePacked(TREZOR_PERSONAL_MESSAGE, hash)),
v,
diff --git a/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol b/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol
index d9b246b29..fc9d1e5c4 100644
--- a/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol
+++ b/packages/contracts/src/contracts/current/test/TestLibBytes/TestLibBytes.sol
@@ -21,9 +21,7 @@ pragma experimental ABIEncoderV2;
import "../../utils/LibBytes/LibBytes.sol";
-contract TestLibBytes is
- LibBytes
-{
+contract TestLibBytes {
/// @dev Pops the last byte off of a byte array by modifying its length.
/// @param b Byte array that will be modified.
@@ -33,7 +31,7 @@ contract TestLibBytes is
pure
returns (bytes memory, bytes1 result)
{
- result = popLastByte(b);
+ result = LibBytes.popLastByte(b);
return (b, result);
}
@@ -45,7 +43,7 @@ contract TestLibBytes is
pure
returns (bytes memory, address result)
{
- result = popLast20Bytes(b);
+ result = LibBytes.popLast20Bytes(b);
return (b, result);
}
@@ -58,7 +56,7 @@ contract TestLibBytes is
pure
returns (bool equal)
{
- equal = areBytesEqual(lhs, rhs);
+ equal = LibBytes.areBytesEqual(lhs, rhs);
return equal;
}
@@ -89,7 +87,7 @@ contract TestLibBytes is
pure
returns (address result)
{
- result = readAddress(b, index);
+ result = LibBytes.readAddress(b, index);
return result;
}
@@ -106,7 +104,7 @@ contract TestLibBytes is
pure
returns (bytes memory)
{
- writeAddress(b, index, input);
+ LibBytes.writeAddress(b, index, input);
return b;
}
@@ -122,7 +120,7 @@ contract TestLibBytes is
pure
returns (bytes32 result)
{
- result = readBytes32(b, index);
+ result = LibBytes.readBytes32(b, index);
return result;
}
@@ -139,7 +137,7 @@ contract TestLibBytes is
pure
returns (bytes memory)
{
- writeBytes32(b, index, input);
+ LibBytes.writeBytes32(b, index, input);
return b;
}
@@ -155,7 +153,7 @@ contract TestLibBytes is
pure
returns (uint256 result)
{
- result = readUint256(b, index);
+ result = LibBytes.readUint256(b, index);
return result;
}
@@ -172,7 +170,7 @@ contract TestLibBytes is
pure
returns (bytes memory)
{
- writeUint256(b, index, input);
+ LibBytes.writeUint256(b, index, input);
return b;
}
@@ -184,7 +182,7 @@ contract TestLibBytes is
pure
returns (bytes4 result)
{
- result = readFirst4(b);
+ result = LibBytes.readFirst4(b);
return result;
}
@@ -200,7 +198,7 @@ contract TestLibBytes is
pure
returns (bytes memory result)
{
- result = readBytes(b, index);
+ result = LibBytes.readBytes(b, index);
return result;
}
@@ -218,7 +216,7 @@ contract TestLibBytes is
pure
returns (bytes memory)
{
- writeBytes(b, index, input);
+ LibBytes.writeBytes(b, index, input);
return b;
}
@@ -243,10 +241,10 @@ contract TestLibBytes is
require(dest + length <= mem.length);
// Get pointer to memory contents
- uint256 offset = getMemAddress(mem) + 32;
+ uint256 offset = LibBytes.getMemAddress(mem) + 32;
// Execute memCopy adjusted for memory array location
- memCopy(offset + dest, offset + source, length);
+ LibBytes.memCopy(offset + dest, offset + source, length);
// Return modified memory contents
return mem;
diff --git a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol
index cb63e38e6..05cf53df5 100644
--- a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol
+++ b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol
@@ -18,7 +18,7 @@
pragma solidity ^0.4.24;
-contract LibBytes {
+library LibBytes {
// Revert reasons
string constant GREATER_THAN_ZERO_LENGTH_REQUIRED = "GREATER_THAN_ZERO_LENGTH_REQUIRED";