Careful Decrypting
contract BadContract {
//...
function balanceOf() public returns (uint64 balance){
ctUint64 balance = balances[msg.sender];
gtUint64 balanceGt = MpcCore.onBoard(balance);
// SHOULD NEVER BE CALLED
// A SIMPLE CALL TO GETBALANCE REVEALS THE BALANCE TO EVERYBODY
return MpcCore.decrypt(balanceGt);
}
//...
}contract GoodContract {
//...
function balanceOf() public returns (ctUint64 balance){
ctUint64 balance = balances[msg.sender];
// The balance is saved encrypted using the system key. However, to allow
// the user to access it, the balance needs to be re-encrypted using the user key.
// Therefore, we decrypt the balance (onBoard) and then encrypt it again using
// the user key (offBoardToUser).
gtUint64 balanceGt = MpcCore.onBoard(balance);
return MpcCore.offBoardToUser(balanceGt, msg.sender);
}
//...
}Last updated
Was this helpful?