diff --git a/implementation/contracts/DepositLog.sol b/implementation/contracts/DepositLog.sol index bd6d86b99..15367a29a 100644 --- a/implementation/contracts/DepositLog.sol +++ b/implementation/contracts/DepositLog.sol @@ -1,5 +1,7 @@ pragma solidity ^0.5.10; +import {TBTCDepositToken} from "./system/TBTCDepositToken.sol"; + contract DepositLog { /* @@ -10,6 +12,10 @@ contract DepositLog { Everyone should be able to ENTIRELY rely on log messages */ + // `TBTCDepositToken` mints a token for every new Deposit. + // If a token exists for a given ID, we know it is a valid Deposit address. + TBTCDepositToken tbtcDepositToken; + // This event is fired when we init the deposit event Created( address indexed _depositContractAddress, @@ -99,15 +105,26 @@ contract DepositLog { // /// @notice Checks if an address is an allowed logger - /// @dev Calls the system to check if the caller is a Deposit + /// @dev checks tbtcDepositToken to see if the caller represents + /// an existing deposit. /// We don't require this, so deposits are not bricked if the system borks /// @param _caller The address of the calling contract /// @return True if approved, otherwise false /* solium-disable-next-line no-empty-blocks */ - function approvedToLog(address _caller) public pure returns (bool) { - /* TODO: auth via system */ - _caller; - return true; + function approvedToLog(address _caller) public view returns (bool) { + return tbtcDepositToken.exists(uint256(_caller)); + } + + /// @notice Sets the tbtcDepositToken contract. + /// @dev The contract is used by `approvedToLog` to check if the + /// caller is a Deposit contract. This should only be called once. + /// @param _tbtcDepositTokenAddress The address of the tbtcDepositToken. + function setTbtcDepositToken(address _tbtcDepositTokenAddress) public { + require( + address(tbtcDepositToken) == address(0), + "tbtcDepositToken is already set" + ); + tbtcDepositToken = TBTCDepositToken(_tbtcDepositTokenAddress); } // diff --git a/implementation/contracts/system/TBTCSystem.sol b/implementation/contracts/system/TBTCSystem.sol index 622994624..11a209ac2 100644 --- a/implementation/contracts/system/TBTCSystem.sol +++ b/implementation/contracts/system/TBTCSystem.sol @@ -94,6 +94,7 @@ contract TBTCSystem is Ownable, ITBTCSystem, DepositLog { _keepThreshold, _keepSize ); + setTbtcDepositToken(_tbtcDepositToken); _initialized = true; allowNewDeposits = true; } diff --git a/implementation/contracts/test/deposit/TBTCSystemStub.sol b/implementation/contracts/test/deposit/TBTCSystemStub.sol index fa2e77319..cc8440ac1 100644 --- a/implementation/contracts/test/deposit/TBTCSystemStub.sol +++ b/implementation/contracts/test/deposit/TBTCSystemStub.sol @@ -26,9 +26,4 @@ contract TBTCSystemStub is TBTCSystem { function requestNewKeep(uint256, uint256, uint256) external payable returns (address _keepAddress) { return keepAddress; } - - // override parent - function approvedToLog(address) public pure returns (bool) { - return true; - } }