Skip to content

Commit

Permalink
Simple & Advanced timestamping and msg.sender check - integration tes…
Browse files Browse the repository at this point in the history
…t updated
  • Loading branch information
Ramsi88 committed Apr 13, 2024
1 parent b5e6469 commit 951502d
Show file tree
Hide file tree
Showing 5 changed files with 494 additions and 339 deletions.
71 changes: 16 additions & 55 deletions contracts/Recovery.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ contract Recovery {
}

modifier onlyOwner() {
require(isOwner[msg.sender] || isOwner[tx.origin], "not owner");
require(isOwner[msg.sender], "not owner");
_;
}

Expand All @@ -81,7 +81,7 @@ contract Recovery {
}

modifier notConfirmed(uint _txIndex) {
require(!isConfirmed[_txIndex][tx.origin], "tx already confirmed");
require(!isConfirmed[_txIndex][msg.sender], "tx already confirmed");
_;
}

Expand All @@ -107,10 +107,6 @@ contract Recovery {

isOwner[owner] = true;

// Owners Auto-whitelisting
//whitelistedToAddresses[owner] = true;
//whitelistedAddressesList.push(owner);

owners.push(owner);
}

Expand Down Expand Up @@ -145,7 +141,7 @@ contract Recovery {
})
);

emit SubmitTransaction(tx.origin, txIndex, _to, _value, _data);
emit SubmitTransaction(msg.sender, txIndex, _to, _value, _data);
}

/**
Expand All @@ -156,9 +152,9 @@ contract Recovery {
function confirmTransaction(uint _txIndex) public onlyOwner txExists(_txIndex) notExecuted(_txIndex) notConfirmed(_txIndex) {
Transaction storage transaction = transactions[_txIndex];
transaction.numConfirmations += 1;
isConfirmed[_txIndex][tx.origin] = true;
isConfirmed[_txIndex][msg.sender] = true;

emit ConfirmTransaction(tx.origin, _txIndex);
emit ConfirmTransaction(msg.sender, _txIndex);
}

/**
Expand All @@ -169,12 +165,12 @@ contract Recovery {
function revokeConfirmation(uint _txIndex) public onlyOwner txExists(_txIndex) notExecuted(_txIndex) {
Transaction storage transaction = transactions[_txIndex];

require(isConfirmed[_txIndex][tx.origin], "tx not confirmed");
require(isConfirmed[_txIndex][msg.sender], "tx not confirmed");

transaction.numConfirmations -= 1;
isConfirmed[_txIndex][tx.origin] = false;
isConfirmed[_txIndex][msg.sender] = false;

emit RevokeConfirmation(tx.origin, _txIndex);
emit RevokeConfirmation(msg.sender, _txIndex);
}

/**
Expand All @@ -198,8 +194,10 @@ contract Recovery {
require(success, "tx failed");

transaction.executed = true;

transaction.timestamp = block.timestamp;

emit ExecuteTransaction(tx.origin, _txIndex);
emit ExecuteTransaction(msg.sender, _txIndex);
}

/**
Expand Down Expand Up @@ -233,7 +231,7 @@ contract Recovery {
* @param _txIndex The index of the transaction that needs to be retrieved
* @custom:return Returns a Transaction structure as (address to, uint value, bytes data, bool executed, uint numConfirmations)
*/
function getTransaction(uint _txIndex) public view returns(address to, uint value, bytes memory data, bool executed, uint numConfirmations, uint blockHeight) {
function getTransaction(uint _txIndex) public view returns(address to, uint value, bytes memory data, bool executed, uint numConfirmations, uint blockHeight, uint timestamp) {
Transaction storage transaction = transactions[_txIndex];

return (
Expand All @@ -242,7 +240,8 @@ contract Recovery {
transaction.data,
transaction.executed,
transaction.numConfirmations,
transaction.blockHeight
transaction.blockHeight,
transaction.timestamp
);
}

Expand Down Expand Up @@ -305,51 +304,13 @@ contract Recovery {
* @notice Fallback function triggered when the contract is receiving Ether and msg.data is empty
*/
receive() external payable {
emit Deposit(tx.origin, msg.value, address(this).balance);
emit Deposit(msg.sender, msg.value, address(this).balance);
}

/**
* @notice Fallback function triggered when the contract is receiving Ether and msg.data is not empty
*/
fallback() external payable {
emit Deposit(tx.origin, msg.value, address(this).balance);
emit Deposit(msg.sender, msg.value, address(this).balance);
}

/**
* @notice Utility function to decode and check erc20 serialized calldata
function checkData(bytes calldata encodedData) external view returns (bool) {
uint len = encodedData.length;
bool decoded = false;
if (len >= 4 && len % 2 == 0) {
bytes memory selector = bytes(abi.encode(bytes(encodedData[0:4])));
bytes memory transfer = bytes(abi.encode(bytes(hex"a9059cbb")));
bytes memory approve = bytes(abi.encode(bytes(hex"095ea7b3")));
bytes memory transferFrom = bytes(abi.encode(bytes(hex"23b872dd")));
bytes memory mint = bytes(abi.encode(bytes(hex"40c10f19")));
if (
keccak256(transfer) == keccak256(selector) ||
keccak256(approve) == keccak256(selector) ||
keccak256(transferFrom) == keccak256(selector) ||
keccak256(mint) == keccak256(selector)
) {
bool passed = bool(
keccak256(transfer) == keccak256(selector) ||
keccak256(approve) == keccak256(selector) ||
keccak256(transferFrom) == keccak256(selector) ||
keccak256(mint) == keccak256(selector)
);
if (passed) {
address payable to = abi.decode(encodedData[4:],(address));
require(whitelistedToAddresses[to], "Calldata not allowed or address not whitelisted!");
require(!blacklistedToAddresses[to], "Address in calldata is blacklisted!");
decoded = true;
}
}
}
return decoded;
}
*/
}
5 changes: 4 additions & 1 deletion contracts/TrustyAdvanced.sol
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ contract TrustyAdvanced {

transaction.executed = true;

transaction.timestamp = block.timestamp;

unlock();

emit ExecuteTransaction(msg.sender, _txIndex);
Expand Down Expand Up @@ -333,7 +335,7 @@ contract TrustyAdvanced {
* @param _txIndex The index of the transaction that needs to be retrieved
* @custom:return Returns a Transaction structure as (address to, uint value, bytes data, bool executed, uint numConfirmations)
*/
function getTransaction(uint _txIndex) public view returns(address to, uint value, bytes memory data, bool executed, uint numConfirmations, uint blockHeight, uint timeLock) {
function getTransaction(uint _txIndex) public view returns(address to, uint value, bytes memory data, bool executed, uint numConfirmations, uint blockHeight, uint timestamp, uint timeLock) {
Transaction storage transaction = transactions[_txIndex];

return (
Expand All @@ -343,6 +345,7 @@ contract TrustyAdvanced {
transaction.executed,
transaction.numConfirmations,
transaction.blockHeight,
transaction.timestamp,
transaction.timeLock
);
}
Expand Down
36 changes: 14 additions & 22 deletions contracts/TrustyFactoryAdvanced.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import "./TrustyAdvanced.sol";
contract TrustyFactoryAdvanced is Ownable {

// Trusty indexed array
//TrustySimple[] public contracts;
TrustySimple[] public contractsSimple;
TrustyAdvanced[] public contracts;

uint256 public totalTrusty = 0;
Expand Down Expand Up @@ -49,20 +49,14 @@ contract TrustyFactoryAdvanced is Ownable {
whitelistedAddresses[msg.sender] = true;
numAddressesWhitelisted++;
}

/**
* @notice This method is used to create a Trusty multisignature
* @param _owners Array of owners' addresses
* @param _nTX Minimum number of confirmations required to execute a transaction
*/
function createContract(address[] memory _owners, uint _nTX, string memory _id, address[] memory _whitelist, address _recovery, uint _blocklock) payable public notWhitelisted {
/*
function createContract(address[] memory _owners, uint _nTX, string memory _id) payable public notWhitelisted {
if(_priceEnabled) {
require(msg.value >= _price, "Ether sent is not enough");
}
TrustyAdvanced trusty = new TrustyAdvanced(_owners, _nTX, _id, _whitelist, _recovery, _blocklock);
//TrustySimple trusty = new TrustySimple(_owners, _nTX, _id);

contracts.push(trusty);
TrustySimple trusty = new TrustySimple(_owners, _nTX, _id);
contractsSimple.push(trusty);
trustyID[totalTrusty] = _id;
Expand All @@ -80,20 +74,20 @@ contract TrustyFactoryAdvanced is Ownable {
totalTrusty++;
}

*/
/**
* @notice This method is used to create a Trusty multisignature
* @param _owners Array of owners' addresses
* @param _nTX Minimum number of confirmations required to execute a transaction
function createContractB(address[] memory _owners, uint _nTX, string memory _id, address[] memory _whitelist, address _recovery, uint _blocklock) payable public notWhitelisted {
*/
function createContract(address[] memory _owners, uint _nTX, string memory _id, address[] memory _whitelist, address _recovery, uint _blocklock) payable public notWhitelisted {
if(_priceEnabled) {
require(msg.value >= _price, "Ether sent is not enough");
}
//TrustyAdvanced trusty = new TrustyAdvanced(_owners, _nTX, _id, _whitelist, _recovery, _blocklock);
TrustyAdvanced trusty = new TrustyAdvanced(_owners, _nTX, _id, _whitelist, _recovery, _blocklock);
//TrustySimple trusty = new TrustySimple(_owners, _nTX, _id);

contractsAdvanced.push(trusty);
contracts.push(trusty);

trustyID[totalTrusty] = _id;

Expand All @@ -111,7 +105,7 @@ contract TrustyFactoryAdvanced is Ownable {

totalTrusty++;
}
*/

/**
* @notice This method is used to make a deposit on a Trusty multisignature
* @param _contractIndex The Trusty contract index that will be funded
Expand All @@ -128,7 +122,6 @@ contract TrustyFactoryAdvanced is Ownable {
* @return address[] Returns the Trusty's owners' addresses array
*/
function contractReadOwners(uint256 _contractIndex) public view returns(address[] memory) {
//Trusty trusty = Trusty(Trusty[_contractIndex]);
return contracts[_contractIndex].getOwners();
}

Expand All @@ -138,7 +131,6 @@ contract TrustyFactoryAdvanced is Ownable {
* @return uint256 Returns the Trusty's balance
*/
function contractReadBalance(uint256 _contractIndex) public view returns(uint256) {
//Trusty trusty = Trusty(Trusty[_contractIndex]);
return contracts[_contractIndex].getBalance();
}

Expand Down Expand Up @@ -168,7 +160,7 @@ contract TrustyFactoryAdvanced is Ownable {
* @param _txIndex The transaction index of the contract's index specified
* @custom:return bool Returns a Transaction structure as (address to, uint value, bytes data, bool executed, uint numConfirmations)
*/
function getTx(uint256 _contractIndex, uint _txIndex) public view returns(address, uint, bytes memory, bool, uint, uint, uint) {
function getTx(uint256 _contractIndex, uint _txIndex) public view returns(address, uint, bytes memory, bool, uint, uint, uint, uint) {
return contracts[_contractIndex].getTransaction(_txIndex);
}

Expand Down
Loading

0 comments on commit 951502d

Please sign in to comment.