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