Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #467 from keep-network/log_auth
Browse files Browse the repository at this point in the history
implement approvedToLog check

Checks that a caller is a Deposit address by calling TBTCDepositToken.exists.

setTbtcDepositToken sets up the tbtcDepositToken contract. This setup is performed during TBTCSystem.initialize.
  • Loading branch information
Shadowfiend authored Mar 16, 2020
2 parents 46d4450 + c3582a2 commit 12d3e32
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
27 changes: 22 additions & 5 deletions implementation/contracts/DepositLog.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pragma solidity ^0.5.10;

import {TBTCDepositToken} from "./system/TBTCDepositToken.sol";


contract DepositLog {
/*
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}

//
Expand Down
1 change: 1 addition & 0 deletions implementation/contracts/system/TBTCSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ contract TBTCSystem is Ownable, ITBTCSystem, DepositLog {
_keepThreshold,
_keepSize
);
setTbtcDepositToken(_tbtcDepositToken);
_initialized = true;
allowNewDeposits = true;
}
Expand Down
5 changes: 0 additions & 5 deletions implementation/contracts/test/deposit/TBTCSystemStub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 12d3e32

Please sign in to comment.