Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to solc v0.8.4. #46

Merged
merged 2 commits into from
Mar 20, 2022
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
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",
};