Deliverable 3
Developing and Testing the Registration Smart Contract
Mayuri Shimpi (mayuripraveen.shimpi@sjsu.edu)
Registration Phase
During the registration phase, the client discloses their real-world identity, specifically their social security number (SSN), to the credit bureau. The registration process involves various entities:
- Borrower: This is an actual individual with a unique SSN and an associated Ethereum address.
- Notary: Serving as a trusted real-world entity, the notary validates the user's identity, credit score, and Ethereum address. Following validation, the notary divides the user's identity into secret shares for multiple auditors. The notary then initiates the credit bureau smart contract, establishing an initial credit score for the borrower. This score comprises the saved real-world score and a point in a credit space, the details of which will be explained in the next section. It is assumed that the notary does not retain the association between the borrower and their Ethereum address, except for the secret shares sent to the auditors.
- Auditors: Responsible for storing shares of the borrower's real-world identity, auditors are trusted entities. It is expected that they do not disclose their share of the secret unless specified by the protocol. For simplicity, the assumption is made that the set of auditors is small, fixed, and publicly known. These assumptions could potentially be relaxed with additional infrastructure.
- Registration Smart Contract (RSC): The RSC maintains a mapping between Ethereum addresses and associated credit scoring information. This additional information includes the credit score linked to the hashed identity, a timestamp indicating when this association was established, and a point within the credit scoring space. The RSC is tasked with connecting lenders and borrowers, tracking loans and repayments, and updating the borrower's credit score. Importantly, only the notary has the authority to invoke specific methods of this smart contract.
Functions for this smart contracts
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
contract Registration {
struct Auditor {
address auditorAddress;
bool initialized;
}
uint public balance;
address private _notary;
mapping(address => bool) _scoreInitialized;
mapping(address => uint) private _creditScores;
mapping(address => uint) _scoreTimestamps;
mapping(address => Auditor) private _auditors;
mapping(address => uint) public _realWorldIds;
constructor() {
_notary = msg.sender;
}
// This function can only be called once per address.
function initScoreLedger(address borrower, uint ficoScore, uint timestamp) public payable{
require(!_scoreInitialized[borrower], "Credit score already initialized for this address");
_creditScores[borrower] = ficoScore;
_scoreTimestamps[borrower] = timestamp;
_scoreInitialized[borrower] = true;
// Distribute secret to auditors
}
function verifyUnusedAddress(address borrower) public view returns (bool) {
return (!_scoreInitialized[borrower]);
}
function getScore(address client) public view returns (uint) {
// Version 1, no encryption of scores
return _creditScores[client];
}
function addAuditor(address auditor) public {
require(!_auditors[auditor].initialized, "Auditor already added");
_auditors[auditor] = Auditor(auditor, true);
}
Unit test cases to test these functions:
const assert = require('assert');
const { Web3 } = require('web3');
const ganache = require('ganache');
const web3 = new Web3(ganache.provider());
const {interface, bytecode} = require('../compile')
let register;
let accounts
beforeEach(async () =>{
accounts = await web3.eth.getAccounts();
register = await new web3.eth.Contract(JSON.parse(interface))
.deploy( {data: bytecode})
.send({from: accounts[0], gas: 1000000})
});
describe(" register",() =>{
it("Deploys a contract", () =>{
assert.ok(register.options.address);
});
it('should check the balance of accounts', async () => {
for (let i = 0; i < accounts.length; i++) {
const balance = await web3.eth.getBalance(accounts[i]);
console.log(`Balance of accounts[${i}]: ${balance} ETH`);}
});
});
|