From 5ae6eca48ccf10d08062a3538fc100ce6728fdb4 Mon Sep 17 00:00:00 2001 From: NicholasDotSol Date: Tue, 18 Feb 2020 09:14:31 -0600 Subject: [PATCH 1/5] implement approvedToLog Calls `TBTCDepositToken.exists` to ensure that the caller is a minted TDT. TBTCDepositToken is set via one-time function setTbtcDepositToken --- implementation/contracts/DepositLog.sol | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/implementation/contracts/DepositLog.sol b/implementation/contracts/DepositLog.sol index 2701aa31d..b75aa22a3 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, @@ -87,15 +93,23 @@ 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 + /// and 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); } // From def02d293d80abb3e027ba93634858270571b13e Mon Sep 17 00:00:00 2001 From: NicholasDotSol Date: Tue, 18 Feb 2020 09:15:25 -0600 Subject: [PATCH 2/5] Set TBTCSystemStub for loggin Set via TBTCSystemStub.initialize() --- implementation/contracts/system/TBTCSystem.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/implementation/contracts/system/TBTCSystem.sol b/implementation/contracts/system/TBTCSystem.sol index 4404e01de..48f8d0867 100644 --- a/implementation/contracts/system/TBTCSystem.sol +++ b/implementation/contracts/system/TBTCSystem.sol @@ -79,6 +79,7 @@ contract TBTCSystem is Ownable, ITBTCSystem, DepositLog { _keepThreshold, _keepSize ); + setTbtcDepositToken(_tbtcDepositToken); _initialized = true; allowNewDeposits = true; } From bf12df2530ecaaa2b5597f1548c04b4275a6c50f Mon Sep 17 00:00:00 2001 From: NicholasDotSol Date: Tue, 18 Feb 2020 09:17:37 -0600 Subject: [PATCH 3/5] Remove approvedToLog testing override Regular approvedToLog can be used instead of the override for better testing accuracy --- implementation/test/contracts/deposit/TBTCSystemStub.sol | 5 ----- 1 file changed, 5 deletions(-) diff --git a/implementation/test/contracts/deposit/TBTCSystemStub.sol b/implementation/test/contracts/deposit/TBTCSystemStub.sol index d654eb4ee..d2ebf37db 100644 --- a/implementation/test/contracts/deposit/TBTCSystemStub.sol +++ b/implementation/test/contracts/deposit/TBTCSystemStub.sol @@ -23,11 +23,6 @@ contract TBTCSystemStub is TBTCSystem { return oraclePrice; } - // override parent - function approvedToLog(address) public pure returns (bool) { - return true; - } - function requestNewKeep(uint256, uint256, uint256) external payable returns (address _keepAddress) { return keepAddress; } From 447b1f3d24fe41ce7c939cfba837fd2027db39bb Mon Sep 17 00:00:00 2001 From: NicholasDotSol Date: Tue, 18 Feb 2020 09:20:41 -0600 Subject: [PATCH 4/5] and -> an --- implementation/contracts/DepositLog.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/implementation/contracts/DepositLog.sol b/implementation/contracts/DepositLog.sol index b75aa22a3..9a1cdef3b 100644 --- a/implementation/contracts/DepositLog.sol +++ b/implementation/contracts/DepositLog.sol @@ -94,7 +94,7 @@ contract DepositLog { /// @notice Checks if an address is an allowed logger /// @dev checks tbtcDepositToken to see if the caller represents - /// and existing deposit. + /// 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 From c3582a2ce431435bcab6ffa88aff5a9e447f9483 Mon Sep 17 00:00:00 2001 From: Antonio Salazar Cardozo Date: Fri, 13 Mar 2020 15:15:14 -0400 Subject: [PATCH 5/5] Fix some Solidity formatting issues --- implementation/contracts/DepositLog.sol | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/implementation/contracts/DepositLog.sol b/implementation/contracts/DepositLog.sol index e8d2a9119..15367a29a 100644 --- a/implementation/contracts/DepositLog.sol +++ b/implementation/contracts/DepositLog.sol @@ -2,6 +2,7 @@ pragma solidity ^0.5.10; import {TBTCDepositToken} from "./system/TBTCDepositToken.sol"; + contract DepositLog { /* TODO: review events, see what new information should be added @@ -11,10 +12,10 @@ contract DepositLog { Everyone should be able to ENTIRELY rely on log messages */ - // `TBTCDepositToken` mints a token for every new Deposit. + // `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, @@ -114,12 +115,15 @@ contract DepositLog { return tbtcDepositToken.exists(uint256(_caller)); } - /// @notice Sets the tbtcDepositToken contract. - /// @dev The contract is used by `approvedToLog` to check if the + /// @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"); + require( + address(tbtcDepositToken) == address(0), + "tbtcDepositToken is already set" + ); tbtcDepositToken = TBTCDepositToken(_tbtcDepositTokenAddress); }