Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ contract Lib_ResolvedDelegateProxy {
constructor(
address _libAddressManager,
string memory _implementationName
)
{
) {
addressManager[address(this)] = Lib_AddressManager(_libAddressManager);
implementationName[address(this)] = _implementationName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
pragma solidity >0.5.0 <0.8.0;
pragma experimental ABIEncoderV2;

/* Library Imports */
import { Lib_BytesUtils } from "../utils/Lib_BytesUtils.sol";

/**
* @title Lib_RLPWriter
* @author Bakaoh (with modifications)
Expand All @@ -18,15 +15,15 @@ library Lib_RLPWriter {
/**
* RLP encodes a byte string.
* @param _in The byte string to encode.
* @return _out The RLP encoded string in bytes.
* @return The RLP encoded string in bytes.
*/
function writeBytes(
bytes memory _in
)
internal
pure
returns (
bytes memory _out
bytes memory
)
{
bytes memory encoded;
Expand All @@ -43,15 +40,15 @@ library Lib_RLPWriter {
/**
* RLP encodes a list of RLP encoded byte byte strings.
* @param _in The list of RLP encoded byte strings.
* @return _out The RLP encoded list of items in bytes.
* @return The RLP encoded list of items in bytes.
*/
function writeList(
bytes[] memory _in
)
internal
pure
returns (
bytes memory _out
bytes memory
)
{
bytes memory list = _flatten(_in);
Expand All @@ -61,15 +58,15 @@ library Lib_RLPWriter {
/**
* RLP encodes a string.
* @param _in The string to encode.
* @return _out The RLP encoded string in bytes.
* @return The RLP encoded string in bytes.
*/
function writeString(
string memory _in
)
internal
pure
returns (
bytes memory _out
bytes memory
)
{
return writeBytes(bytes(_in));
Expand All @@ -78,15 +75,15 @@ library Lib_RLPWriter {
/**
* RLP encodes an address.
* @param _in The address to encode.
* @return _out The RLP encoded address in bytes.
* @return The RLP encoded address in bytes.
*/
function writeAddress(
address _in
)
internal
pure
returns (
bytes memory _out
bytes memory
)
{
return writeBytes(abi.encodePacked(_in));
Expand All @@ -95,15 +92,15 @@ library Lib_RLPWriter {
/**
* RLP encodes a uint.
* @param _in The uint256 to encode.
* @return _out The RLP encoded uint256 in bytes.
* @return The RLP encoded uint256 in bytes.
*/
function writeUint(
uint256 _in
)
internal
pure
returns (
bytes memory _out
bytes memory
)
{
return writeBytes(_toBinary(_in));
Expand All @@ -112,15 +109,15 @@ library Lib_RLPWriter {
/**
* RLP encodes a bool.
* @param _in The bool to encode.
* @return _out The RLP encoded bool in bytes.
* @return The RLP encoded bool in bytes.
*/
function writeBool(
bool _in
)
internal
pure
returns (
bytes memory _out
bytes memory
)
{
bytes memory encoded = new bytes(1);
Expand All @@ -137,7 +134,7 @@ library Lib_RLPWriter {
* Encode the first byte, followed by the `len` in binary form if `length` is more than 55.
* @param _len The length of the string or the payload.
* @param _offset 128 if item is string, 192 if item is list.
* @return _encoded RLP encoded bytes.
* @return RLP encoded bytes.
*/
function _writeLength(
uint256 _len,
Expand All @@ -146,7 +143,7 @@ library Lib_RLPWriter {
private
pure
returns (
bytes memory _encoded
bytes memory
)
{
bytes memory encoded;
Expand Down Expand Up @@ -176,15 +173,15 @@ library Lib_RLPWriter {
* Encode integer in big endian binary form with no leading zeroes.
* @notice TODO: This should be optimized with assembly to save gas costs.
* @param _x The integer to encode.
* @return _binary RLP encoded bytes.
* @return RLP encoded bytes.
*/
function _toBinary(
uint256 _x
)
private
pure
returns (
bytes memory _binary
bytes memory
)
{
bytes memory b = abi.encodePacked(_x);
Expand Down Expand Up @@ -243,15 +240,15 @@ library Lib_RLPWriter {
* Flattens a list of byte strings into one byte string.
* @notice From: https://github.com/sammayo/solidity-rlp-encoder/blob/master/RLPEncode.sol.
* @param _list List of byte strings to flatten.
* @return _flattened The flattened byte string.
* @return The flattened byte string.
*/
function _flatten(
bytes[] memory _list
)
private
pure
returns (
bytes memory _flattened
bytes memory
)
{
if (_list.length == 0) {
Expand Down Expand Up @@ -280,4 +277,4 @@ library Lib_RLPWriter {

return flattened;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ library Lib_BytesUtils {
)
internal
pure
returns (bytes memory)
returns (
bytes memory
)
{
require(_length + 31 >= _length, "slice_overflow");
require(_start + _length >= _start, "slice_overflow");
Expand Down Expand Up @@ -87,7 +89,9 @@ library Lib_BytesUtils {
)
internal
pure
returns (bytes memory)
returns (
bytes memory
)
{
if (_bytes.length - _start == 0) {
return bytes('');
Expand All @@ -101,7 +105,9 @@ library Lib_BytesUtils {
)
internal
pure
returns (bytes32)
returns (
bytes32
)
{
bytes32 ret;
uint256 len = _bytes.length <= 32 ? _bytes.length : 32;
Expand All @@ -116,7 +122,9 @@ library Lib_BytesUtils {
)
internal
pure
returns (bytes32)
returns (
bytes32
)
{
if (_bytes.length < 32) {
bytes32 ret;
Expand All @@ -134,12 +142,23 @@ library Lib_BytesUtils {
)
internal
pure
returns (uint256)
returns (
uint256
)
{
return uint256(toBytes32(_bytes));
}

function toUint24(bytes memory _bytes, uint256 _start) internal pure returns (uint24) {
function toUint24(
bytes memory _bytes,
uint256 _start
)
internal
pure
returns (
uint24
)
{
require(_start + 3 >= _start, "toUint24_overflow");
require(_bytes.length >= _start + 3 , "toUint24_outOfBounds");
uint24 tempUint;
Expand All @@ -151,7 +170,16 @@ library Lib_BytesUtils {
return tempUint;
}

function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) {
function toUint8(
bytes memory _bytes,
uint256 _start
)
internal
pure
returns (
uint8
)
{
require(_start + 1 >= _start, "toUint8_overflow");
require(_bytes.length >= _start + 1 , "toUint8_outOfBounds");
uint8 tempUint;
Expand All @@ -163,7 +191,16 @@ library Lib_BytesUtils {
return tempUint;
}

function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {
function toAddress(
bytes memory _bytes,
uint256 _start
)
internal
pure
returns (
address
)
{
require(_start + 20 >= _start, "toAddress_overflow");
require(_bytes.length >= _start + 20, "toAddress_outOfBounds");
address tempAddress;
Expand All @@ -180,7 +217,9 @@ library Lib_BytesUtils {
)
internal
pure
returns (bytes memory)
returns (
bytes memory
)
{
bytes memory nibbles = new bytes(_bytes.length * 2);

Expand All @@ -197,7 +236,9 @@ library Lib_BytesUtils {
)
internal
pure
returns (bytes memory)
returns (
bytes memory
)
{
bytes memory ret = new bytes(_bytes.length / 2);

Expand All @@ -214,7 +255,9 @@ library Lib_BytesUtils {
)
internal
pure
returns (bool)
returns (
bool
)
{
return keccak256(_bytes) == keccak256(_other);
}
Expand Down
Loading