Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CVLByExample/Events/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Reasoning about Solidity events

This directory demonstrates how to reason about Solidity events with the Prover.
The Prover cannot natively reason about events, therefore a workaround is needed.

The workaround is to wrap the `emits` of Solidity `events` into an internal function and then apply internal summarization to reason about the emitted event.

See `contracts/Auction.sol` for the original code that uses an event and take a look at `contract/AuctionFixed.sol` for code that uses the workaround.

-
Run this configuration via:

```certoraRun runAuctionFixed.conf```

[A report of this run](https://prover.certora.com/output/53900/4ffdad0c20094a729d830bfb1b460f3e?anonymousKey=b345ea4d1fe4b3631442c0f110e926a58f47ee9b)


37 changes: 37 additions & 0 deletions CVLByExample/Events/certora/specs/Auction.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @title Reasoning about Solidity events example
*
* This is an example specification for reasoning about events in CVL.
*/

methods {
function emitBidEvent(address from) internal => cvlEmitBidEvent(from);
}

persistent ghost bool isEventEmitted;
persistent ghost address emittedEventAddress;

function cvlEmitBidEvent(address from){
isEventEmitted = true;
emittedEventAddress = from;
}

/**
* This rule checks that an event is emitted
*/
rule eventIsEmitted() {
env e;
isEventEmitted = false;
bid(e);
assert isEventEmitted;
}

/**
* This rule checks that the emitted event address is the one
* that initiated the bid operation.
*/
rule eventEmitsMsgSender() {
env e;
bid(e);
assert emittedEventAddress == e.msg.sender;
}
8 changes: 8 additions & 0 deletions CVLByExample/Events/contracts/Auction.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract Auction
{
event BidEvent(address from);
function bid() public
{
emit BidEvent(msg.sender);
}
}
13 changes: 13 additions & 0 deletions CVLByExample/Events/contracts/AuctionFixed.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
contract AuctionFixed
{
event BidEvent(address from);
function bid() public
{
emitBidEvent(msg.sender);
}

function emitBidEvent(address from) internal
{
emit BidEvent(from);
}
}
8 changes: 8 additions & 0 deletions CVLByExample/Events/runAuctionFixed.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"files": [
"contracts/AuctionFixed.sol",
],
"verify": "AuctionFixed:certora/specs/Auction.spec",
"msg": "Reasoning about Solidity events",
"rule_sanity" : "basic" // check there is a trace satisfying the rule.
}