Skip to content

Commit

Permalink
Merge pull request #46 from celestiaorg/adlerjohn/solc-v0.8.4
Browse files Browse the repository at this point in the history
Bump to solc v0.8.4.
  • Loading branch information
adlerjohn authored Mar 20, 2022
2 parents dcee50b + 513e895 commit ad8ffea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
38 changes: 29 additions & 9 deletions contracts/ProtobufLib.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.6.0 <8.0.0;
pragma solidity >=0.8.4 <0.9.0;

library ProtobufLib {
/// @notice Protobuf wire types.
enum WireType { Varint, Bits64, LengthDelimited, StartGroup, EndGroup, Bits32, WIRE_TYPE_MAX }
enum WireType {
Varint,
Bits64,
LengthDelimited,
StartGroup,
EndGroup,
Bits32,
WIRE_TYPE_MAX
}

/// @dev Maximum number of bytes for a varint.
/// @dev 64 bits, in groups of base-128 (7 bits).
Expand Down Expand Up @@ -252,7 +260,10 @@ library ProtobufLib {
}

// https://stackoverflow.com/questions/2210923/zig-zag-decoding/2211086#2211086
uint64 zigzag_val = (val >> 1) ^ (-(val & 1));
uint64 zigzag_val;
unchecked {
zigzag_val = (val >> 1) - (~(val & 1) + 1);
}

return (true, pos, int32(uint32(zigzag_val)));
}
Expand All @@ -278,7 +289,10 @@ library ProtobufLib {
}

// https://stackoverflow.com/questions/2210923/zig-zag-decoding/2211086#2211086
uint64 zigzag_val = (val >> 1) ^ (-(val & 1));
uint64 zigzag_val;
unchecked {
zigzag_val = (val >> 1) - (~(val & 1) + 1);
}

return (true, pos, int64(zigzag_val));
}
Expand Down Expand Up @@ -512,8 +526,10 @@ library ProtobufLib {
}

// Check for overflow
if (pos + size < pos) {
return (false, pos, 0);
unchecked {
if (pos + size < pos) {
return (false, pos, 0);
}
}

// Check that index is within bounds
Expand Down Expand Up @@ -655,7 +671,7 @@ library ProtobufLib {
/// @param n Number
/// @return Marshaled bytes
function encode_int32(int32 n) internal pure returns (bytes memory) {
return encode_varint(uint64(n));
return encode_varint(uint64(int64(n)));
}

/// @notice Decode varint int64.
Expand Down Expand Up @@ -686,7 +702,9 @@ library ProtobufLib {
// https://developers.google.com/protocol-buffers/docs/encoding#signed_integers
uint32 mask = 0;
if (n < 0) {
mask -= 1;
unchecked {
mask -= 1;
}
}
uint32 zigzag_val = (uint32(n) << 1) ^ mask;

Expand All @@ -700,7 +718,9 @@ library ProtobufLib {
// https://developers.google.com/protocol-buffers/docs/encoding#signed_integers
uint64 mask = 0;
if (n < 0) {
mask -= 1;
unchecked {
mask -= 1;
}
}
uint64 zigzag_val = (uint64(n) << 1) ^ mask;

Expand Down
2 changes: 1 addition & 1 deletion contracts/TestFixture.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.6.0 <8.0.0;
pragma solidity >=0.8.4 <0.9.0;

import "./ProtobufLib.sol";

Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require("@nomiclabs/hardhat-truffle5");

module.exports = {
solidity: "0.6.12",
solidity: "0.8.4",
};

0 comments on commit ad8ffea

Please sign in to comment.