Research Article

Lolisa: Formal Syntax and Semantics for a Subset of the Solidity Programming Language in Mathematical Tool Coq

Algorithm 1

Partial source code of case study contract.
Solidity 0.4.8;
function example () public payable {
 uint index = indexes[msg.sender];
 uint open;
 uint close; …
 if (privileges[msg.sender]) {
  open = privilegeOpen;
  close = privilegeClose;
 …} else {
  open = ordinaryOpen;
  close = ordinaryClose;…}
 if (now < open || now > close) {
  throw(); }
 if (subscription + rate > TOKEN_TARGET_AMOUNT) {
  throw (); }
 …
 if (msg.value <= finalLimit) {
  safe.transfer(msg.value);
  deposits[index] + = msg.value;
  subscription + = msg.value / 1000000000000000000 ∗ rate;
  Transfer(msg.sender, msg.value); } else {
  safe.transfer(finalLimit);
  deposits[index] + = finalLimit;
  subscription + = finalLimit / 1000000000000000000 ∗ rate;
  Transfer(msg.sender, finalLimit);
  msg.sender.transfer(msg.value - finalLimit);
 }
}