Remove `TypedMemView` from `core` contracts (#415)

* Remove TMV from contracts

* Migrate to solidity >=0.8

* Upgrade openzeppelin import

* Fix CI

* Explicitly require TS in core

* Fix initializable bugs

* Optimize gas in Message with destructure

* Add natspec and remove unused function

Co-authored-by: nambrot <nambrot@googlemail.com>
nambrot/publish-script
Yorke Rhodes 3 years ago committed by GitHub
parent f78e79ab9b
commit de74f868be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      .github/workflows/node.yml
  2. 8
      solidity/core/contracts/AbacusConnectionManager.sol
  3. 7
      solidity/core/contracts/Common.sol
  4. 31
      solidity/core/contracts/Inbox.sol
  5. 2
      solidity/core/contracts/InterchainGasPaymaster.sol
  6. 2
      solidity/core/contracts/Merkle.sol
  7. 8
      solidity/core/contracts/Outbox.sol
  8. 2
      solidity/core/contracts/test/MysteryMath.sol
  9. 2
      solidity/core/contracts/test/MysteryMathV1.sol
  10. 2
      solidity/core/contracts/test/MysteryMathV2.sol
  11. 4
      solidity/core/contracts/test/TestCommon.sol
  12. 21
      solidity/core/contracts/test/TestInbox.sol
  13. 2
      solidity/core/contracts/test/TestMerkle.sol
  14. 57
      solidity/core/contracts/test/TestMessage.sol
  15. 2
      solidity/core/contracts/test/TestMultisigValidatorManager.sol
  16. 2
      solidity/core/contracts/test/TestOutbox.sol
  17. 4
      solidity/core/contracts/test/TestRecipient.sol
  18. 2
      solidity/core/contracts/test/TestValidatorManager.sol
  19. 4
      solidity/core/contracts/test/bad-recipient/BadRecipient1.sol
  20. 4
      solidity/core/contracts/test/bad-recipient/BadRecipient3.sol
  21. 4
      solidity/core/contracts/test/bad-recipient/BadRecipient5.sol
  22. 4
      solidity/core/contracts/test/bad-recipient/BadRecipient6.sol
  23. 2
      solidity/core/contracts/test/bad-recipient/BadRecipientHandle.sol
  24. 4
      solidity/core/contracts/test/bad-recipient/RandomBadRecipient.sol
  25. 2
      solidity/core/contracts/upgrade/UpgradeBeacon.sol
  26. 2
      solidity/core/contracts/upgrade/UpgradeBeaconController.sol
  27. 2
      solidity/core/contracts/upgrade/UpgradeBeaconProxy.sol
  28. 2
      solidity/core/contracts/validator-manager/InboxValidatorManager.sol
  29. 6
      solidity/core/contracts/validator-manager/MultisigValidatorManager.sol
  30. 2
      solidity/core/contracts/validator-manager/OutboxValidatorManager.sol
  31. 2
      solidity/core/hardhat.config.ts
  32. 2
      solidity/core/interfaces/IMessageRecipient.sol
  33. 148
      solidity/core/libs/Message.sol
  34. 13
      solidity/core/libs/TypeCasts.sol
  35. 7
      solidity/core/package.json
  36. 21
      yarn.lock

@ -17,8 +17,8 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: .//node_modules
key: ${{ runner.os }}-yarn-cache3-${{ hashFiles('./yarn.lock') }}
path: '**/node_modules'
key: ${{ runner.os }}-yarn-cache4-${{ hashFiles('./yarn.lock') }}
- name: yarn-install
# Check out the lockfile from main, reinstall, and then
@ -42,8 +42,8 @@ jobs:
- name: yarn-cache
uses: actions/cache@v2
with:
path: .//node_modules
key: ${{ runner.os }}-yarn-cache3-${{ hashFiles('./yarn.lock') }}
path: '**/node_modules'
key: ${{ runner.os }}-yarn-cache4-${{ hashFiles('./yarn.lock') }}
- name: build-cache
uses: actions/cache@v2
@ -61,8 +61,8 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: .//node_modules
key: ${{ runner.os }}-yarn-cache3-${{ hashFiles('./yarn.lock') }}
path: '**/node_modules'
key: ${{ runner.os }}-yarn-cache4-${{ hashFiles('./yarn.lock') }}
- name: prettier
run: |

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
pragma abicoder v2;
// ============ Internal Imports ============
@ -9,8 +9,7 @@ import {IAbacusConnectionManager} from "../interfaces/IAbacusConnectionManager.s
// ============ External Imports ============
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/EnumerableSet.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
/**
* @title AbacusConnectionManager
@ -19,7 +18,6 @@ import {EnumerableSet} from "@openzeppelin/contracts/utils/EnumerableSet.sol";
* domains.
*/
contract AbacusConnectionManager is IAbacusConnectionManager, Ownable {
using SafeMath for uint256;
using EnumerableSet for EnumerableSet.AddressSet;
// ============ Public Storage ============
@ -129,7 +127,7 @@ contract AbacusConnectionManager is IAbacusConnectionManager, Ownable {
];
uint256 length = _inboxes.length();
address[] memory ret = new address[](length);
for (uint256 i = 0; i < length; i = i.add(1)) {
for (uint256 i = 0; i < length; i += 1) {
ret[i] = _inboxes.at(i);
}
return ret;

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
// ============ Internal Imports ============
import {ICommon} from "../interfaces/ICommon.sol";
@ -68,10 +68,7 @@ abstract contract Common is ICommon, OwnableUpgradeable {
// ============ Initializer ============
function __Common_initialize(address _validatorManager)
internal
initializer
{
function __Common_initialize(address _validatorManager) internal {
// initialize owner
__Ownable_init();
_setValidatorManager(_validatorManager);

@ -1,15 +1,14 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
// ============ Internal Imports ============
import {Version0} from "./Version0.sol";
import {Common} from "./Common.sol";
import {MerkleLib} from "../libs/Merkle.sol";
import {Message} from "../libs/Message.sol";
import {TypeCasts} from "../libs/TypeCasts.sol";
import {IMessageRecipient} from "../interfaces/IMessageRecipient.sol";
import {IInbox} from "../interfaces/IInbox.sol";
// ============ External Imports ============
import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol";
/**
* @title Inbox
@ -21,9 +20,8 @@ contract Inbox is IInbox, Version0, Common {
// ============ Libraries ============
using MerkleLib for MerkleLib.Tree;
using TypedMemView for bytes;
using TypedMemView for bytes29;
using Message for bytes29;
using Message for bytes;
using TypeCasts for bytes32;
// ============ Enums ============
@ -116,7 +114,7 @@ contract Inbox is IInbox, Version0, Common {
require(entered == 1, "!reentrant");
entered = 0;
bytes32 _messageHash = keccak256(abi.encodePacked(_message, _index));
bytes32 _messageHash = _message.leaf(_index);
// ensure that message has not been processed
require(
messages[_messageHash] == MessageStatus.None,
@ -144,14 +142,25 @@ contract Inbox is IInbox, Version0, Common {
* @param _messageHash keccak256 hash of the message
*/
function _process(bytes calldata _message, bytes32 _messageHash) internal {
bytes29 _m = _message.ref(0);
(
uint32 origin,
bytes32 sender,
uint32 destination,
bytes32 recipient,
bytes calldata body
) = _message.destructure();
// ensure message was meant for this domain
require(_m.destination() == localDomain, "!destination");
require(destination == localDomain, "!destination");
// update message status as processed
messages[_messageHash] = MessageStatus.Processed;
IMessageRecipient _recipient = IMessageRecipient(_m.recipientAddress());
_recipient.handle(_m.origin(), _m.sender(), _m.body().clone());
IMessageRecipient(recipient.bytes32ToAddress()).handle(
origin,
sender,
body
);
// emit process results
emit Process(_messageHash);
}

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
// ============ Internal Imports ============
import {IInterchainGasPaymaster} from "../interfaces/IInterchainGasPaymaster.sol";

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
// ============ Internal Imports ============
import {MerkleLib} from "../libs/Merkle.sol";

@ -1,11 +1,12 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
// ============ Internal Imports ============
import {Version0} from "./Version0.sol";
import {Common} from "./Common.sol";
import {MerkleLib} from "../libs/Merkle.sol";
import {Message} from "../libs/Message.sol";
import {TypeCasts} from "../libs/TypeCasts.sol";
import {MerkleTreeManager} from "./Merkle.sol";
import {IOutbox} from "../interfaces/IOutbox.sol";
@ -23,6 +24,7 @@ contract Outbox is IOutbox, Version0, MerkleTreeManager, Common {
// ============ Libraries ============
using MerkleLib for MerkleLib.Tree;
using TypeCasts for address;
// ============ Constants ============
@ -107,7 +109,7 @@ contract Outbox is IOutbox, Version0, MerkleTreeManager, Common {
function dispatch(
uint32 _destinationDomain,
bytes32 _recipientAddress,
bytes memory _messageBody
bytes calldata _messageBody
) external override notFailed returns (uint256) {
require(_messageBody.length <= MAX_MESSAGE_BODY_BYTES, "msg too long");
// The leaf has not been inserted yet at this point1
@ -115,7 +117,7 @@ contract Outbox is IOutbox, Version0, MerkleTreeManager, Common {
// format the message into packed bytes
bytes memory _message = Message.formatMessage(
localDomain,
bytes32(uint256(uint160(msg.sender))),
msg.sender.addressToBytes32(),
_destinationDomain,
_recipientAddress,
_messageBody

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
abstract contract MysteryMath {
uint256 public stateVar;

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
import "./MysteryMath.sol";

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
import "./MysteryMath.sol";

@ -1,12 +1,12 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
import "../Common.sol";
contract TestCommon is Common {
constructor(uint32 _localDomain) Common(_localDomain) {}
function initialize(address _validatorManager) external {
function initialize(address _validatorManager) external initializer {
__Common_initialize(_validatorManager);
}
}

@ -1,12 +1,10 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
import "../Inbox.sol";
contract TestInbox is Inbox {
using TypedMemView for bytes;
using TypedMemView for bytes29;
using Message for bytes29;
using Message for bytes32;
constructor(uint32 _localDomain) Inbox(_localDomain) {} // solhint-disable-line no-empty-blocks
@ -31,21 +29,16 @@ contract TestInbox is Inbox {
messages[_leaf] = status;
}
function getRevertMsg(bytes memory _res)
function getRevertMsg(bytes calldata _res)
internal
view
pure
returns (string memory)
{
bytes29 _view = _res.ref(0);
// If the _res length is less than 68, then the transaction failed
// silently (without a revert message)
if (_view.len() < 68) return "Transaction reverted silently";
// Remove the selector which is the first 4 bytes
bytes memory _revertData = _view.slice(4, _res.length - 4, 0).clone();
if (_res.length < 68) return "Transaction reverted silently";
// All that remains is the revert string
return abi.decode(_revertData, (string));
// Remove the selector (first 4 bytes) and decode revert string
return abi.decode(_res[4:], (string));
}
}

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
import "../Merkle.sol";

@ -2,46 +2,63 @@
pragma solidity >=0.6.11;
import {Message} from "../../libs/Message.sol";
import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol";
contract TestMessage {
using Message for bytes29;
using TypedMemView for bytes;
using TypedMemView for bytes29;
using Message for bytes;
function body(bytes memory _message) external view returns (bytes memory) {
return _message.ref(0).body().clone();
function body(bytes calldata _message)
external
pure
returns (bytes calldata _body)
{
(, , , , _body) = _message.destructure();
}
function origin(bytes memory _message) external pure returns (uint32) {
return _message.ref(0).origin();
function origin(bytes calldata _message)
external
pure
returns (uint32 _origin)
{
(_origin, , , , ) = _message.destructure();
}
function sender(bytes memory _message) external pure returns (bytes32) {
return _message.ref(0).sender();
function sender(bytes calldata _message)
external
pure
returns (bytes32 _sender)
{
(, _sender, , , ) = _message.destructure();
}
function destination(bytes memory _message) external pure returns (uint32) {
return _message.ref(0).destination();
function destination(bytes calldata _message)
external
pure
returns (uint32 _destination)
{
(, , _destination, , ) = _message.destructure();
}
function recipient(bytes memory _message) external pure returns (bytes32) {
return _message.ref(0).recipient();
function recipient(bytes calldata _message)
external
pure
returns (bytes32 _recipient)
{
(, , , _recipient, ) = _message.destructure();
}
function recipientAddress(bytes memory _message)
function recipientAddress(bytes calldata _message)
external
pure
returns (address)
returns (address _recipient)
{
return _message.ref(0).recipientAddress();
(, , , _recipient, ) = _message.destructureAddresses();
}
function leaf(bytes memory _message, uint256 _leafIndex)
function leaf(bytes calldata _message, uint256 _leafIndex)
external
view
pure
returns (bytes32)
{
return _message.ref(0).leaf(_leafIndex);
return _message.leaf(_leafIndex);
}
}

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
pragma abicoder v2;
import {MultisigValidatorManager} from "../validator-manager/MultisigValidatorManager.sol";

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
// ============ Internal Imports ============
import "../Outbox.sol";

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
import {IMessageRecipient} from "../../interfaces/IMessageRecipient.sol";
@ -14,7 +14,7 @@ contract TestRecipient is IMessageRecipient {
function handle(
uint32,
bytes32,
bytes memory
bytes calldata
) external pure override {} // solhint-disable-line no-empty-blocks
function receiveString(string calldata _str)

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
import {IInbox} from "../../interfaces/IInbox.sol";

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
import {IMessageRecipient} from "../../../interfaces/IMessageRecipient.sol";
@ -7,7 +7,7 @@ contract BadRecipient1 is IMessageRecipient {
function handle(
uint32,
bytes32,
bytes memory
bytes calldata
) external pure override {
assembly {
revert(0, 0)

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
import {IMessageRecipient} from "../../../interfaces/IMessageRecipient.sol";
@ -7,7 +7,7 @@ contract BadRecipient3 is IMessageRecipient {
function handle(
uint32,
bytes32,
bytes memory
bytes calldata
) external pure override {
assembly {
mstore(0, 0xabcdef)

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
import {IMessageRecipient} from "../../../interfaces/IMessageRecipient.sol";
@ -7,7 +7,7 @@ contract BadRecipient5 is IMessageRecipient {
function handle(
uint32,
bytes32,
bytes memory
bytes calldata
) external pure override {
require(false, "no can do");
}

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
import {IMessageRecipient} from "../../../interfaces/IMessageRecipient.sol";
@ -7,7 +7,7 @@ contract BadRecipient6 is IMessageRecipient {
function handle(
uint32,
bytes32,
bytes memory
bytes calldata
) external pure override {
require(false); // solhint-disable-line reason-string
}

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
contract BadRecipientHandle {
function handle(uint32, bytes32) external pure {} // solhint-disable-line no-empty-blocks

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
import {IMessageRecipient} from "../../../interfaces/IMessageRecipient.sol";
@ -9,7 +9,7 @@ contract BadRandomRecipient is IMessageRecipient {
function handle(
uint32,
bytes32,
bytes memory
bytes calldata
) external override {
bool isBlockHashEven = uint256(blockhash(block.number - 1)) % 2 == 0;
require(isBlockHashEven, "block hash is odd");

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
// ============ External Imports ============
import {Address} from "@openzeppelin/contracts/utils/Address.sol";

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
// ============ Internal Imports ============
import {UpgradeBeacon} from "./UpgradeBeacon.sol";

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
// ============ External Imports ============
import {Address} from "@openzeppelin/contracts/utils/Address.sol";

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
pragma abicoder v2;
// ============ Internal Imports ============

@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
pragma abicoder v2;
// ============ External Imports ============
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ECDSA} from "@openzeppelin/contracts/cryptography/ECDSA.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/EnumerableSet.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
/**
* @title MultisigValidatorManager

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
pragma solidity >=0.8.0;
pragma abicoder v2;
// ============ Internal Imports ============

@ -9,7 +9,7 @@ import "hardhat-gas-reporter";
*/
module.exports = {
solidity: {
version: "0.7.6",
version: '0.8.13',
settings: {
optimizer: {
enabled: true,

@ -5,6 +5,6 @@ interface IMessageRecipient {
function handle(
uint32 _origin,
bytes32 _sender,
bytes memory _message
bytes calldata _message
) external;
}

@ -1,7 +1,5 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
import "@summa-tx/memview-sol/contracts/TypedMemView.sol";
pragma solidity >=0.8.0;
import {TypeCasts} from "./TypeCasts.sol";
@ -11,14 +9,11 @@ import {TypeCasts} from "./TypeCasts.sol";
* @notice Library for formatted messages used by Outbox and Replica.
**/
library Message {
using TypedMemView for bytes;
using TypedMemView for bytes29;
// Number of bytes in formatted message before `body` field
uint256 internal constant PREFIX_LENGTH = 72;
using TypeCasts for bytes32;
/**
* @notice Returns formatted (packed) message with provided fields
* @dev This function should only be used in memory message construction.
* @param _originDomain Domain of home chain
* @param _sender Address of sender as bytes32
* @param _destinationDomain Domain of destination chain
@ -31,7 +26,7 @@ library Message {
bytes32 _sender,
uint32 _destinationDomain,
bytes32 _recipient,
bytes memory _messageBody
bytes calldata _messageBody
) internal pure returns (bytes memory) {
return
abi.encodePacked(
@ -45,84 +40,83 @@ library Message {
/**
* @notice Returns leaf of formatted message with provided fields.
* @param _origin Domain of home chain
* @param _sender Address of sender as bytes32
* @param _destination Domain of destination chain
* @param _recipient Address of recipient on destination chain as bytes32
* @param _body Raw bytes of message body
* @dev hash of abi packed message and leaf index.
* @param _message Raw bytes of message contents.
* @param _leafIndex Index of the message in the tree
* @return Leaf (hash) of formatted message
**/
function messageHash(
uint32 _origin,
bytes32 _sender,
uint32 _destination,
bytes32 _recipient,
bytes memory _body,
uint256 _leafIndex
) internal pure returns (bytes32) {
return
keccak256(
abi.encodePacked(
formatMessage(
_origin,
_sender,
_destination,
_recipient,
_body
),
_leafIndex
)
);
}
/// @notice Returns message's origin field
function origin(bytes29 _message) internal pure returns (uint32) {
return uint32(_message.indexUint(0, 4));
}
/// @notice Returns message's sender field
function sender(bytes29 _message) internal pure returns (bytes32) {
return _message.index(4, 32);
}
/// @notice Returns message's destination field
function destination(bytes29 _message) internal pure returns (uint32) {
return uint32(_message.indexUint(36, 4));
}
/// @notice Returns message's recipient field as bytes32
function recipient(bytes29 _message) internal pure returns (bytes32) {
return _message.index(40, 32);
}
/// @notice Returns message's recipient field as an address
function recipientAddress(bytes29 _message)
*/
function leaf(bytes calldata _message, uint256 _leafIndex)
internal
pure
returns (address)
returns (bytes32)
{
return TypeCasts.bytes32ToAddress(recipient(_message));
return keccak256(abi.encodePacked(_message, _leafIndex));
}
/// @notice Returns message's body field as bytes29 (refer to TypedMemView library for details on bytes29 type)
function body(bytes29 _message) internal pure returns (bytes29) {
return _message.slice(PREFIX_LENGTH, _message.len() - PREFIX_LENGTH, 0);
/**
* @notice Decode raw message bytes into structured message fields.
* @dev Efficiently slices calldata into structured message fields.
* @param _message Raw bytes of message contents.
* @return origin Domain of home chain
* @return sender Address of sender as bytes32
* @return destination Domain of destination chain
* @return recipient Address of recipient on destination chain as bytes32
* @return body Raw bytes of message body
*/
function destructure(bytes calldata _message)
internal
pure
returns (
uint32 origin,
bytes32 sender,
uint32 destination,
bytes32 recipient,
bytes calldata body
)
{
return (
uint32(bytes4(_message[0:4])),
bytes32(_message[4:36]),
uint32(bytes4(_message[36:40])),
bytes32(_message[40:72]),
bytes(_message[72:])
);
}
function leaf(bytes29 _message, uint256 _leafIndex)
/**
* @notice Decode raw message bytes into structured message fields.
* @dev Efficiently slices calldata into structured message fields.
* @param _message Raw bytes of message contents.
* @return origin Domain of home chain
* @return sender Address of sender as address (bytes20)
* @return destination Domain of destination chain
* @return recipient Address of recipient on destination chain as address (bytes20)
* @return body Raw bytes of message body
*/
function destructureAddresses(bytes calldata _message)
internal
view
returns (bytes32)
pure
returns (
uint32,
address,
uint32,
address,
bytes calldata
)
{
return
messageHash(
origin(_message),
sender(_message),
destination(_message),
recipient(_message),
TypedMemView.clone(body(_message)),
_leafIndex
);
(
uint32 _origin,
bytes32 _sender,
uint32 destination,
bytes32 _recipient,
bytes calldata body
) = destructure(_message);
return (
_origin,
_sender.bytes32ToAddress(),
destination,
_recipient.bytes32ToAddress(),
body
);
}
}

@ -1,20 +1,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;
import "@summa-tx/memview-sol/contracts/TypedMemView.sol";
library TypeCasts {
using TypedMemView for bytes;
using TypedMemView for bytes29;
function coerceBytes32(string memory _s)
internal
pure
returns (bytes32 _b)
{
_b = bytes(_s).ref(0).index(0, uint8(bytes(_s).length));
}
// treat it as a null-terminated string of max 32 bytes
function coerceString(bytes32 _buf)
internal

@ -17,7 +17,8 @@
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "^0.7.14",
"ts-node": "^10.1.0",
"typechain": "^5.0.0"
"typechain": "^5.0.0",
"typescript": "^4.3.5"
},
"version": "0.1.1",
"main": "dist/index.js",
@ -35,8 +36,8 @@
"license": "MIT OR Apache-2.0",
"dependencies": {
"@abacus-network/utils": "^0.1.1",
"@openzeppelin/contracts": "^3.4.2",
"@openzeppelin/contracts-upgradeable": "~3.4.2",
"@openzeppelin/contracts": "^4.6.0",
"@openzeppelin/contracts-upgradeable": "^4.6.0",
"@summa-tx/memview-sol": "^2.0.0",
"ts-generator": "^0.1.1"
}

@ -74,8 +74,8 @@ __metadata:
"@abacus-network/utils": ^0.1.1
"@nomiclabs/hardhat-ethers": ^2.0.1
"@nomiclabs/hardhat-waffle": ^2.0.1
"@openzeppelin/contracts": ^3.4.2
"@openzeppelin/contracts-upgradeable": ~3.4.2
"@openzeppelin/contracts": ^4.6.0
"@openzeppelin/contracts-upgradeable": ^4.6.0
"@summa-tx/memview-sol": ^2.0.0
"@typechain/ethers-v5": ~7.0.0
"@typechain/hardhat": ^2.0.1
@ -93,6 +93,7 @@ __metadata:
ts-generator: ^0.1.1
ts-node: ^10.1.0
typechain: ^5.0.0
typescript: ^4.3.5
languageName: unknown
linkType: soft
@ -3064,6 +3065,13 @@ __metadata:
languageName: node
linkType: hard
"@openzeppelin/contracts-upgradeable@npm:^4.6.0":
version: 4.6.0
resolution: "@openzeppelin/contracts-upgradeable@npm:4.6.0"
checksum: f9802c9cccf31bd475412ba5d862ed15eed5352302c30b29c38f84aed2dcfe0d957687935a72068f3d44292a4a55b0ff26cd018b2e14a47f16f74f087009aa29
languageName: node
linkType: hard
"@openzeppelin/contracts-upgradeable@npm:~3.4.2":
version: 3.4.2
resolution: "@openzeppelin/contracts-upgradeable@npm:3.4.2"
@ -3071,7 +3079,14 @@ __metadata:
languageName: node
linkType: hard
"@openzeppelin/contracts@npm:^3.4.2, @openzeppelin/contracts@npm:~3.4.2":
"@openzeppelin/contracts@npm:^4.6.0":
version: 4.6.0
resolution: "@openzeppelin/contracts@npm:4.6.0"
checksum: 1de06211b279d7aef2bb9abbdd58eb80c71256f7e888a10855ea23bb06ef8723b22fb550d06af60247dfbd7f0f23de9821732012d7541a823339070a8442d1db
languageName: node
linkType: hard
"@openzeppelin/contracts@npm:~3.4.2":
version: 3.4.2
resolution: "@openzeppelin/contracts@npm:3.4.2"
checksum: 0c90f029fe50a49643588e4c8670dae3bbf31795133a6ddce9bdcbc258486332700bb732287baabf7bf807f39182fe8ea2ffa19aa5caf359b1b9c0f083280748

Loading…
Cancel
Save