Metropolis Casper Solidity interface

Dear all,

we have been writing the Solidity interface for the upcoming Metropolis Casper contract.

This is a key component for anyone looking to interact with the Casper contract. In fact our work should make it easier for developers to build applications on top of Casper.

The interface allows visually understand how the contract works and what the RPC calls to the EVM should have to adhere to. You will be able to read the full interface, with the alternative contract written as an interface (here we are showing the Solidity interface and many might not be familiar with it), on our dedicated Casper Github repo.

What we believe crucial is to bridge the gap from Viper to Solidity, two different languages for writing Smart Contract on Ethereum. The Casper contract is written in Viper, but the Solidity language is being adopted by many developers. Viper and Solidity differ in the implementations of a few parameters, hence it is really important to properly define them.

In order to guarantee smooth interfacing, we would like to get your feedback as well and looking for you to contribute to this project.

//! Casper Interface /* && Casper Interface contract */.
//! By Gabriele Rigo (RigoBlock, Rigo Investment Sagl), 2017.
//! Released under the Apache Licence 2.

pragma solidity ^0.4.16;

//this is the Casper Interface

interface Casper {

// EVENTS


// NON-CONSTANT METHODS

//function initiate(uint128 _epoch_length, uint128 _withdrawal_delay, address _owner, address _sighasher, address _purity_checker, uint8 _base_interest_factor, uint8 _base_penalty_factor);
function initiate_epoch(uint128 epoch);
function deposit(address validation_addr, address withdrawal_addr) payable; //would be nice to have: returns (bool success) {}
function logout(bytes logout_msg);
function withdraw(uint128 validator_index); //would be nice to have: returns (bool success) {}
function proc_reward(uint128 validator_index, uint16 reward);
function prepare(bytes prepare_msg);
function commit(bytes commit_msg);
function double_prepare_slash(bytes prepare1, bytes prepare2);
function prepare_commit_inconsistency_slash(bytes prepare_msg, bytes commit_msg);


// CONSTANT METHODS

//function balance_of(address validator) constant returns (uint) {} //would be nice to have balances by address in addition of balances by validator_index

function get_deposit_size(uint128 validator_index) constant returns (uint128);
function get_total_curdyn_deposits() constant returns (uint128);
function get_total_prevdyn_deposits() constant returns (uint128);
function get_recommended_ancestry_hash() constant returns (bytes32);
function get_recommended_source_epoch() constant returns (uint128);
function get_recommended_source_ancestry_hash() constant returns (bytes32);
//function get_main_hash_prepared_frac() constant returns (uint8);
//function get_main_hash_committed_frac() constant returns (uint8);

// IMPLIED CONSTANT METHODS
// they get auto-generated by viper when a variable is declared public

//function get_validators__deposit(uint128 arg0) constant returns (uint8); //or returns (uint decimal)
function get_validators__dynasty_start(uint128 arg0) constant returns (uint128);
function get_validatos__dynasty_end(uint128 arg0) constant returns (uint128);
function get_validators__addr(uint128 arg0) constant returns (address);
function get_validators__withdrawal_address(uint128 arg0) constant returns (address);
function get_validators__prev_commit_epoch(uint128 arg0) constant returns (uint128);

function get_nextValidatorIndex() constant returns (uint128);
function get_dynasty() constant returns (uint128);
//function get_next_dynasty_wei_delta() constant returns (uint8); //returns a decimal
//function get_second_next_dynasty_wei_delta() constant returns (uint8); //returns a decimal

function get_dynasty_start_epoch(uint128 arg0) constant returns (uint128);
function get_dynasty_in_epoch(uint128 arg0) constant returns (uint128);

//function get_consensus_messages__cur_cyn_prepares(uint128 args0, bytes32 arg1) constant returns (uint8); //returns decimal
function get_consensus_messages__prepare_bitmap(uint128 args0, bytes32 arg1, uint128 arg2) constant returns (uint256); //returns num256
//function get_consensus_messages__prev_dyn_prepares(uint128 args0, bytes32 arg1) constant returns (uint8); //returns decimal
function get_consensus_messages__ancestry_hash_justified(uint128 args0, bytes32 arg1) constant returns (bool);
//function get_consensus_messages__cur_dyn_commits(uint128 args0, bytes32 arg1) constant returns (uint8); //returns decimal
//function get_consensus_messages__prev_dyn_commits(uint128 args0, bytes32 arg1) constant returns (uint8); //returns decimal (wei/m)

function get_ancestry_hashes(uint128 arg0) constant returns (bytes32);
function get_main_has_justified() constant returns (bool);
function get_main_hash_finalized() constant returns (bool);
//function get_deposit_scale_factor(uint128 arg0) constant returns (uint8); //returns decimal
function get_epoch_lenght() constant returns (uint128);
function get_current_epoch() constant returns (uint128);
function get_last_finalized_epoch() constant returns (uint128);
function get_last_justified_epoch() constant returns (uint128);
function get_expected_source_epoch() constant returns (uint128);
//function get_reward_factor() constant returns (uint8); //returns decimal
//function get_base_interest_factor() constant returns (uint8); returns decimal
//function get_base_penalty_factor() constant returns (uint8); //returns decimal
//function get_current_penalty_factor() constant returns (uint8); //returns decimal
}

If you are familiar with the Casper Viper implementation, you might notice we have proposed some minor additions, which we would like to explain:

  1. on the deposit and withdraw function, we propose a boolean return value. This helps prevent any transaction which would throw;
  2. we propose the function ‘balance_of(address validator) returns (uint)’. This function helps track users’ balances by address. If Casper is an ERC20 token, that function will be added by default, however how the inputs have to be served is important information.

A special thank goes to Danny Ryan, who has provided feedback on our first version.

On current discrepancies between Viper and Solidity:

  1. conversion of decimals from Viper to Solidity, under analysis solution using uint8 in Solidity (does not have decimals) as convention;
  2. bytes1000, bytes1024 from Viper to Solidity, currently using generic bytes in Solidity.

Further work will be done on writing the documentation for the Casper contract calls. This is a small project which will be completely open source.

In the RigoBlock context, we will also offer support for Metropolis testing and are looking to run a machine 24/7 for that.

Full compatibility means that our users will be able to create their own Gabcoin and perform pooled Proof-of-Stake mining. Gabcoins are our decentralized pools of tokens and their sole use now is holding cryptocurrencies (Ether at the moment, looking to extend it to all ERC20 tokens). With the advent of Metropolis, Gabcoins creators will be able to perform pooled Proof-of-Stake mining with the Gabcoins’ Ether.

We believe Gabcoins are addressing one problem more or less anyone holding Ether on behalf of others has experienced: how do I segregate third party holdings? How can I have the minimum possible access to other people’s cryptos? How can I monitor how much I am holding for each users?

We understand many of you are holding cryptos on behalf of Family&Friends and are not really happy of having full responsibility over all of the assets, plus do not have a system to organize all holdings. With Gabcoins we are addressing this very issue. You can find more information about us on our website.