Use OZ's ReentrancyGuardUpgradeable in Inbox (#499)

* Put entered into its own slot to prevent SLOADing before each SSTORE

* Use OZ ReentrancyGuardUpgradeable

Co-authored-by: Yorke Rhodes <yorke@useabacus.network>
pull/526/head
Trevor Porter 3 years ago committed by GitHub
parent 969c51bdcc
commit 099cd93cec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      solidity/core/contracts/Inbox.sol

@ -10,13 +10,16 @@ import {TypeCasts} from "../libs/TypeCasts.sol";
import {IMessageRecipient} from "../interfaces/IMessageRecipient.sol";
import {IInbox} from "../interfaces/IInbox.sol";
// ============ External Imports ============
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
/**
* @title Inbox
* @author Celo Labs Inc.
* @notice Track root updates on Outbox, prove and dispatch messages to end
* recipients.
*/
contract Inbox is IInbox, Version0, Mailbox {
contract Inbox is IInbox, ReentrancyGuardUpgradeable, Version0, Mailbox {
// ============ Libraries ============
using MerkleLib for MerkleLib.Tree;
@ -37,15 +40,13 @@ contract Inbox is IInbox, Version0, Mailbox {
// Domain of outbox chain
uint32 public override remoteDomain;
// re-entrancy guard
uint8 private entered;
// Mapping of message leaves to MessageStatus
mapping(bytes32 => MessageStatus) public messages;
// ============ Upgrade Gap ============
// gap for upgrade safety
uint256[47] private __GAP;
uint256[48] private __GAP;
// ============ Events ============
@ -74,8 +75,8 @@ contract Inbox is IInbox, Version0, Mailbox {
public
initializer
{
__ReentrancyGuard_init();
__Mailbox_initialize(_validatorManager);
entered = 1;
remoteDomain = _remoteDomain;
}
@ -114,11 +115,7 @@ contract Inbox is IInbox, Version0, Mailbox {
bytes32[32] calldata _proof,
uint256 _index,
bytes calldata /* _sovereignData */
) external override {
// check re-entrancy guard
require(entered == 1, "!reentrant");
entered = 0;
) external override nonReentrant {
bytes32 _messageHash = _message.leaf(_index);
// ensure that message has not been processed
require(
@ -135,8 +132,6 @@ contract Inbox is IInbox, Version0, Mailbox {
require(cachedCheckpoints[_calculatedRoot] >= _index, "!cache");
_process(_message, _messageHash);
emit Process(_messageHash, _index, _proof);
// reset re-entrancy guard
entered = 1;
}
// ============ Internal Functions ============

Loading…
Cancel
Save