How to Manually Test Solidity Code Converted into F-star?

  • Thread starter Thread starter zak100
  • Start date Start date
  • Tags Tags
    Code Test
AI Thread Summary
The discussion centers on the challenges of verifying and validating Solidity code through conversion to F* (F-star). The original Solidity code for a simple banking contract includes functions for depositing, withdrawing, and checking balances. The user seeks guidance on manually testing this code, as they are unable to find a converter to F*. A response suggests that similar to Java's JUnit framework, manual testing involves creating test cases that exercise the code's logic, comparing actual outputs to expected results.The user provides a translated version of the Solidity code into F* and reports an error related to unchecked send results during analysis. They seek further assistance in understanding and resolving this issue. The conversation highlights the complexities of transitioning from Solidity to F* and the need for effective testing methods to ensure code reliability.
zak100
Messages
462
Reaction score
11
Hi,
I read a research paper for verification and validation of solidity code. It uses F* (F-star). However, it has to convert the solidity code into F-star. I can't find the converter. Can some body please guide me how to manually test the code? Code is given below:
Code:
  contract MyBank {

  mapping (address)==>uint) balances;

  function Deposit() {

  balances[msg.sender] += msg.value;

  }|

  function Withdraw(uint amount) {

  if(balances[msg.sender] >=amount) {

  msg.sender.send(amount);

  balances[msg.sender] -= amount;

}

}

function Balance() constant returns(uint) {

return balances[msg.sender];

}

A quick response is really appreciated.

Zulfi.
 
Technology news on Phys.org
I don’t know if this will help but when doing java code we can setup junit tests to exercise the code. This is a somewhat manual process best done with an IDE like Netbeans or Eclipse. Junit is a framework for writing th testcases. It doesn’t read your code and write them.

I imagine whatever you’re referring to does the same thing. You have to look at your code and write inputs that exercise the conditional and looping logic and then compare actual output to expected output.
 
Hi,
Thanks for your reply.

Hi,
What I understand is that:
Initially balance is zero. Then store some value in the balance using msg.value : let's suppose 500. & let's suppose in Withdraw(700) it checks that balance is greater than amount so it sends the amount & deducts balance which seems fine. However a conversion of the code into F* is shown below (from research paper: https://www.cs.umd.edu/~aseem/solidetherplas.pdf)

Code:
module MyBank
open Solidity
type state = f balances: mapping address uint; g
val store : state = fbalances = ref empty mapg
let deposit () : Eth unit =
update map store.balances msg.sender
(add (lookup store.balances msg.sender) msg.value)
let withdraw (amount:uint) : Eth unit =
if (ge (lookup store.balances msg.sender) amount) then
send msg.sender amount;
update map store.balances msg.sender
(sub (lookup store.balances msg.sender) amount)
let balance () : Eth uint =
lookup store.balances msg.sender

and when its analyzed using F*, it gives following error:

Using the effect system of F*, we now show how to detect
some vulnerable patterns such as unchecked send results in
translated contracts.
The base construction is a combined
exception and state monad (see [9] for details) with the
following signature:
EST (a:Type) = h0:heap // input heap
->send failed:bool // send failure flag
->Tot (option (a * heap) // result and new heap, or exception
* bool) // new failure flag

return (a:Type) (x:a) : EST a =
fun h0 b0->Some (x, h0), b0

bind (a:Type) (b:Type) (f:EST a) (g:a->EST b) : EST b =
fun h0 b0->
match f h0 b0 with
| None, b1->None, b1 // exception in f: no output heap
| Some (x, h1), b1->g x h1 b1 // run g, carry failure flag

Some body please guide me.

Zulfi.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
What percentage of programmers have learned to touch type? Have you? Do you think it's important, not just for programming, but for more-than-casual computer users generally? ChatGPT didn't have much on it ("Research indicates that less than 20% of people can touch type fluently, with many relying on the hunt-and-peck method for typing ."). 'Hunt-and-peck method' made me smile. It added, "For programmers, touch typing is a valuable skill that can enhance speed, accuracy, and focus. While...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
8
Views
6K
Back
Top