Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #610 from tokencard/remove-oraclize
Browse files Browse the repository at this point in the history
Remove Oraclize
  • Loading branch information
riccardopersiani authored Sep 16, 2020
2 parents 531525a + 40dd5a6 commit b122bf7
Show file tree
Hide file tree
Showing 45 changed files with 675 additions and 4,571 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This, version 3.3.1, of the *Consumer Contract Wallet* utilises the library/prox

The *Consumer Contract Wallet* protects users by limiting their exposure to theft in the event that their private key becoming compromised. This version also brings 'batched meta-transactions' to the list of features of the contract wallet. Batched meta-transactions are flexible to the point where gas can be removed from equation or can be approximately paid for in any ERC20 token. By batching up meta-transactions we will be able to build a more compelling user experience, by utilising the composability of Smart Contract calls on Ethereum.

Each user deploys their own proxy contract, i.e. their contract wallet, that uses the logic defined in ([wallet.sol](/contracts/wallet.sol)) that in turn interacts with the *TokenWhitelist* ([tokenWhitelist.sol](/contracts/tokenWhitelist.sol)) to get token exchange rates to enforce a user-defined daily spend limit. The exchange rates in the *TokenWhitelist* contract are periodically updated using an exchange rate *Oracle* ([oracle.sol](/contracts/oracle.sol)) that builds upon the [Provable Things Ethereum APIs](https://github.com/provable-things/ethereum-api) and [CryptoCompare's APIs](https://min-api.cryptocompare.com/).
Each user deploys their own proxy contract, i.e. their contract wallet, that uses the logic defined in ([wallet.sol](/contracts/wallet.sol)) that in turn interacts with the *TokenWhitelist* ([tokenWhitelist.sol](/contracts/tokenWhitelist.sol)) to get token exchange rates to enforce a user-defined daily spend limit. The exchange rates in the *TokenWhitelist* contract are periodically updated using an exchange rate *Oracle* ([oracle.sol](/contracts/oracle.sol)) that builds upon [CryptoCompare's APIs](https://min-api.cryptocompare.com/).

Service discovery in the *Consumer Contract Wallet* is performed via the use of the [Ethereum Name Service (ENS)](https://ens.domains/). For example, ENS is used to resolve the location of the *TokenWhitelist* contract, as well as to resolve the location of the *Controller* ([controller.sol](contracts/controller.sol)) contract. The *TokenWhitelist* is a list of tokens and their exchange rates that defines the set of tokens that are protected within a user's wallet. It also determines which tokens can be used to load fiat on to a user's Monolith card. Card load transactions are peformed by sending assets to the ([licence.sol](/contracts/licence.sol)) contract that in turn takes a 1% fee and adds it to the ([holder.sol](/contracts/holder.sol)) contract. The tokens sent to the holder contract are "cash 'n' burnable" by the ([TKN ERC-20 Contract](https://etherscan.io/token/0xaaaf91d9b90df800df4f55c205fd6989c977e73a)) in conjunction with the *TKN Holder* Contract. This *Controller* contract is used for administrative purposes only, rest assured this has no access to user's funds. The controllers are used to perform 2FA functionality as well as administrative tasks on the *Oracle* and on the *TokenWhitelist*.

Expand Down Expand Up @@ -95,7 +95,7 @@ It should be noted that this codebase makes heavy use of inheritance.

[licence.sol](/contracts/licence.sol) is the *TKN Licence* contract, and it is used to take a 1% fee of all loads of the user's TokenCard so that it can be sent to the *TKN Holder* contract. This contract is aware of the CryptoFloat where the remaining tokens are to be kept for Token Group Ltd for the loading of the TokenCards. It is also aware of the address of the *TKN Holder* contract that is used to back TKN. The *TKN Licence* contract has been created in a way to allow for a DAO to change some of its configured features, this is there to future proof the implementation; see ([licence inheritance diagram](/docs/licence.inheritance.png)).

[oracle.sol](/contracts/oracle.sol) is an exchange rate *Oracle* contract that gets exchange rates for a set of supported ERC20 tokens. Exchange rates are updated periodically by using the signed Crypto Compare API through the [Provable](https://provable.xyz/) oracle service. The list of tokens is managed by the *TokenWhitelist*, the *Oracle* merely updates exchange rates; see ([oracle inheritance diagram](/docs/oracle.inheritance.png)).
[oracle.sol](/contracts/oracle.sol) is an exchange rate *Oracle* contract that gets exchange rates for a set of supported ERC20 tokens. Exchange rates are updated periodically by using the signed Crypto Compare API. The list of tokens is managed by the *TokenWhitelist*, the *Oracle* merely updates exchange rates; see ([oracle inheritance diagram](/docs/oracle.inheritance.png)).

[tokenWhitelist.sol](/contracts/tokenWhitelist.sol) The list of tokens used in this system is managed in the *TokenWhitelist*. The *Controller* can be used to add and remove tokens from the *TokenWhitelist*, they also have the ability to set flags on the specific tokens, e.g. `loadable` (means that a token is loadable on the TokenCard) or `redeemable` (means that a token is redeemable in the *TKN Holder* contract); see ([tokenWhitelist inheritance diagram](/docs/tokenWhitelist.inheritance.png)).

Expand Down
3 changes: 0 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ contracts_0_6=(
'mocks/gasToken'
'mocks/isValidSignatureExporter'
'mocks/nonCompliantToken'
'mocks/oraclize'
'mocks/parseIntScientificExporter'
'mocks/token'
'mocks/tokenWhitelistableExporter'
Expand Down Expand Up @@ -81,8 +80,6 @@ contracts=(
"mocks/bytesUtilsExporter/BytesUtilsExporter mocks/bytesUtilsExporter.go BytesUtilsExporter mocks"
"mocks/isValidSignatureExporter/IsValidSignatureExporter mocks/isValidSignatureExporter.go IsValidSignatureExporter mocks"
"mocks/nonCompliantToken/NonCompliantToken mocks/nonCompliantToken.go NonCompliantToken mocks"
"mocks/oraclize/OraclizeConnector mocks/oraclizeConnector.go OraclizeConnector mocks"
"mocks/oraclize/OraclizeAddrResolver mocks/oraclizeAddrResolver.go OraclizeAddrResolver mocks"
"mocks/parseIntScientificExporter/ParseIntScientificExporter mocks/parseIntScientificExporter.go ParseIntScientificExporter mocks"
"mocks/token/Token mocks/token.go Token mocks"
"mocks/tokenWhitelistableExporter/TokenWhitelistableExporter mocks/tokenWhitelistableExporter.go TokenWhitelistableExporter mocks"
Expand Down
31 changes: 31 additions & 0 deletions contracts/externals/ECDSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,37 @@ library ECDSA {
return signer;
}

function recoverNonMalleable(bytes32 hash, bytes memory signature) internal pure returns (address) {
// Check the signature length
if (signature.length != 65) {
revert("ECDSA: invalid signature length");
}

// Divide the signature in r, s and v variables
bytes32 r;
bytes32 s;
uint8 v;

// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
// solhint-disable-next-line no-inline-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}

if (v != 27 && v != 28) {
revert("ECDSA: invalid signature 'v' value");
}

// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
require(signer != address(0), "ECDSA: invalid signature");

return signer;
}

/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* replicates the behavior of the
Expand Down
Loading

0 comments on commit b122bf7

Please sign in to comment.