Theory Casino
theory Casino
imports Solidity_Main "HOL-Eisbach.Eisbach" "HOL-Eisbach.Eisbach_Tools"
begin
section ‹Casino Contract›
text ‹
In the following we verify the Casino contract from the VerifyThis Long-Term Challenge:
🌐‹https://verifythis.github.io/02casino/›
🌐‹https://verifythis.github.io/ltc/02casino/›.
›
subsection ‹Specification›
text ‹
In the following we describe the specification of the contract.
›
text ‹
Method modifiers are formalized as abbreviations.
They need to be formalized in the Solidity context to provide access to various contextual information.
›
abbreviation "state ≡ STR ''state''"
abbreviation "operator ≡ STR ''operator''"
abbreviation "player ≡ STR ''player''"
abbreviation "pot ≡ STR ''pot''"
abbreviation "hashedNumber ≡ STR ''hashedNumber''"
abbreviation "bet ≡ STR ''bet''"
abbreviation "guess ≡ STR ''guess''"
abbreviation "hashNum ≡ STR ''hashNum''"
abbreviation "secret ≡ STR ''secret''"
abbreviation "bet_old ≡ STR ''bet_old''"
abbreviation "secretNumber ≡ STR ''secretNumber''"
abbreviation "amount ≡ STR ''amount''"
abbreviation "IDLE ≡ 0"
abbreviation "GAME_AVAILABLE ≡ 1"
abbreviation "BET_PLACED ≡ 2"
abbreviation "HEADS ≡ 0"
abbreviation "TAILS ≡ 1"
abbreviation "CoinT ≡ SType.TValue TSint"
abbreviation "StateT ≡ SType.TValue TSint"
abbreviation "AddressT ≡ SType.TValue TAddress"
abbreviation "IntT ≡ SType.TValue TSint"
abbreviation "Bytes32T ≡ SType.TValue (TBytes 32)"
context Solidity
begin
abbreviation byOperator::"(unit, ex, 'a state) state_monad" where
"byOperator ≡ assert Err (λs. storage_data.Value (valtype.Address msg_sender) = state.Storage s this operator)"
abbreviation inState:: "'a valtype ⇒ (unit, ex, 'a state) state_monad" where
"inState st ≡ assert Err (λs. state.Storage s this state = storage_data.Value st)"
abbreviation noActiveBet::"(unit, ex, ('a, 'b) state_scheme) state_monad" where
"noActiveBet ≡ assert Err (λs. state.Storage s this state ≠ storage_data.Value (Uint 2))"
end
text ‹
The contract can now be specified using the "contract" command.
This command requires the following:
▪ A sequence of member variables
▪ A constructor
▪ A sequence of methods
›