Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
concordium
smart-contract-interactions
Commits
f0c73550
Commit
f0c73550
authored
Mar 04, 2019
by
Jakob Botsch Nielsen
Browse files
Update Blockchain.v and get Congress to build
parent
24dc7f0d
Pipeline
#11033
failed with stage
in 4 minutes and 29 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/Blockchain.v
View file @
f0c73550
From
Coq
Require
Import
String
.
From
Coq
Require
OrderedTypeEx
.
From
SmartContracts
Require
Import
Oak
.
From
SmartContracts
Require
Import
Monads
.
Definition
a
ddress
:=
nat
.
Definition
A
ddress
:=
nat
.
Delimit
Scope
address_scope
with
address
.
Bind
Scope
address_scope
with
a
ddress
.
Bind
Scope
address_scope
with
A
ddress
.
Module
Address
.
Definition
eqb
:=
Nat
.
eqb
.
Module
as_modern_OT
:=
PeanoNat
.
Nat
.
Module
as_old_OT
:=
OrderedTypeEx
.
Nat_as_OT
.
End
Address
.
Infix
"=?"
:=
Address
.
eqb
(
at
level
70
)
:
address_scope
.
Definition
a
mount
:=
nat
.
Definition
b
lock
_i
d
:=
nat
.
Definition
b
lock
_h
ash
:=
string
.
Definition
v
ersion
:=
nat
.
Definition
A
mount
:=
nat
.
Definition
B
lock
I
d
:=
nat
.
Definition
B
lock
H
ash
:=
string
.
Definition
V
ersion
:=
nat
.
Inductive
tx_body
:=
|
Empty
:
tx_body
.
Record
contract_call_details
:=
Record
ContractDeployment
:=
{
from
:
address
;
to
:
address
;
value
:
amount
deployment_version
:
Version
;
deployment_msg_ty
:
OakType
;
deployment_state_ty
:
OakType
;
deployment_setup
:
OakValue
;
}
.
Record
block_header
:=
{
blockNumber
:
block_id
Inductive
TxBody
:=
|
tx_empty
|
tx_deploy
(
deployment
:
ContractDeployment
)
|
tx_call
(
message
:
OakValue
).
Record
Tx
:=
build_tx
{
tx_from
:
Address
;
tx_to
:
Address
;
tx_amount
:
Amount
;
tx_body
:
TxBody
;
}
.
Record
block
:=
{
header
:
block_header
Record
BlockHeader
:=
build_block_header
{
block_number
:
BlockId
;
block_hash
:
BlockHash
;
}
.
Record
chain
:=
{
headBlock
:
block
Record
Block
:=
build_block
{
block_header
:
BlockHeader
;
block_txs
:
list
Tx
;
}
.
Inductive
Chain
:=
build_chain
{
get_chain_at
:
BlockId
->
option
Chain
;
get_block_at
:
BlockId
->
option
Block
;
head_block
:
Block
;
get_incoming_txs
:
Address
->
list
unit
;
get_outgoing_txs
:
Address
->
list
unit
;
get_contract_deployment
:
Address
->
option
ContractDeployment
;
get_contract_state
:
Address
->
option
OakValue
;
}
.
Inductive
ContractCallContext
:=
build_contract_call_ctx
{
(
*
Chain
*
)
ctx_chain
:
Chain
;
(
*
Address
sending
the
funds
*
)
ctx_from
:
Address
;
(
*
Address
of
the
contract
being
called
*
)
ctx_contract_address
:
Address
;
(
*
Amount
of
GTU
passed
in
call
*
)
ctx_amount
:
Amount
;
}
.
Inductive
Contract
:
Type
->
Type
->
Type
->
Type
:=
|
build_contract
:
forall
(
setup_ty
msg_ty
state_ty
:
Type
),
Version
->
(
setup_ty
->
ContractCallContext
->
option
state_ty
)
->
(
*
init
*
)
(
state_ty
->
ContractCallContext
->
option
msg_ty
->
option
(
state_ty
*
list
ChainAction
))
->
(
*
receive
*
)
Contract
setup_ty
msg_ty
state_ty
with
ChainAction
:=
|
act_transfer
(
to
:
Address
)
(
amount
:
Amount
)
|
act_deploy
:
forall
setup_ty
msg_ty
state_ty
,
Contract
setup_ty
msg_ty
state_ty
->
setup_ty
->
ChainAction
|
act_call
(
to
:
Address
)
(
amount
:
Amount
)
(
msg
:
OakValue
).
Definition
contract_version
{
A
B
C
:
Type
}
(
c
:
Contract
A
B
C
)
:=
let
'
build_contract
_
_
_
ver
_
_
:=
c
in
ver
.
Definition
contract_init
{
A
B
C
:
Type
}
(
c
:
Contract
A
B
C
)
:=
let
'
build_contract
_
_
_
_
init
_
:=
c
in
init
.
Definition
contract_receive
{
A
B
C
:
Type
}
(
c
:
Contract
A
B
C
)
:=
let
'
build_contract
_
_
_
_
_
recv
:=
c
in
recv
.
Record
ContractInterface
(
setup_ty
msg_ty
state_ty
:
Type
)
:=
build_contract_interface
{
contract_address
:
Address
;
setup
:
setup_ty
;
get_state
:
Chain
->
option
state_ty
;
transfer
:
Amount
->
ChainAction
;
call
:
Amount
->
msg_ty
->
ChainAction
;
}
.
(
*
todo
:
this
should
be
easier
--
we
want
actual
strong
typed
interface
by
equivalence
of
oak
type
(
iterated
product
,
for
instance
)
to
types
in
contracts
.
Right
now
the
interface
received
allows
you
only
to
interact
with
a
contrat
using
interpreted
types
.
*
)
Definition
get_contract_interface
(
setup_oty
msg_oty
state_oty
:
OakType
)
(
chain
:
Chain
)
(
addr
:
Address
)
:
option
(
ContractInterface
(
interp_type
setup_oty
)
(
interp_type
msg_oty
)
(
interp_type
state_oty
))
:=
do
deployment
<-
chain
.(
get_contract_deployment
)
addr
;
let
(
deploy_setup_oty
,
deploy_setup
)
:=
deployment
.(
deployment_setup
)
in
match
eq_oak_type_dec
setup_oty
deploy_setup_oty
,
eq_oak_type_dec
msg_oty
deployment
.(
deployment_msg_ty
),
eq_oak_type_dec
state_oty
deployment
.(
deployment_state_ty
)
with
|
left
_
,
left
_
,
left
_
=>
Some
{|
contract_address
:=
addr
;
setup
:=
let
x
:
interp_type
setup_oty
:=
ltac
:
(
subst
;
exact
deploy_setup
)
in
x
;
get_state
futureChain
:=
do
val
<-
futureChain
.(
get_contract_state
)
addr
;
extract_oak_value
state_oty
val
;
transfer
:=
act_transfer
addr
;
call
amt
msg
:=
act_call
addr
amt
(
build_oak_value
msg_oty
msg
)
|}
|
_
,
_
,
_
=>
None
end
.
\ No newline at end of file
src/Congress.v
View file @
f0c73550
...
...
@@ -2,211 +2,201 @@ From Coq Require Import String.
From
Coq
Require
Import
List
.
From
Coq
Require
Import
ZArith
.
From
Coq
Require
Import
Program
.
Basics
.
From
Coq
Require
MSets
FMapAVL
.
From
Coq
Require
OrderedTypeEx
.
From
Containers
Require
Import
OrderedTypeEx
.
From
Containers
Require
Import
MapInterface
.
From
Containers
Require
Import
SetInterface
.
From
SmartContracts
Require
Import
Blockchain
.
From
SmartContracts
Require
Import
Oak
.
From
SmartContracts
Require
Import
Monads
.
From
RecordUpdate
Require
Import
RecordUpdate
.
Import
MapNotations
.
Import
ListNotations
.
Import
RecordSetNotations
.
Open
Scope
Z
.
Print
Visibility
.
Definition
TxOut
:=
nat
.
Definition
ProposalId
:=
nat
.
Module
AddressSet
:=
MSetAVL
.
Make
Address
.
as_modern_OT
.
Module
NatKeyedMap
:=
FMapAVL
.
Make
OrderedTypeEx
.
Nat_as_OT
.
Module
AddressKeyedMap
:=
FMapAVL
.
Make
Address
.
as_old_OT
.
Record
Proposal
:=
{
tx
s
:
list
TxOut
;
votes
:
Address
KeyedMap
.
t
Z
;
vote
R
esult
:
Z
;
proposed
I
n
:
b
lock
_id
build_proposal
{
action
s
:
list
ChainAction
;
votes
:
Map
[
Address
,
Z
]
;
vote
_r
esult
:
Z
;
proposed
_i
n
:
B
lock
Id
;
}
.
Instance
eta
P
roposal
:
Settable
_
:=
Instance
eta
_p
roposal
:
Settable
_
:=
mkSettable
((
constructor
B
uild_
P
roposal
)
<*>
tx
s
((
constructor
b
uild_
p
roposal
)
<*>
action
s
<*>
votes
<*>
vote
R
esult
<*>
proposed
I
n
)
%
set
.
<*>
vote
_r
esult
<*>
proposed
_i
n
)
%
set
table
.
Record
Rules
:=
{
min
V
ote
C
ount
P
ermille
:
Z
;
margin
N
eeded
P
ermille
:
Z
;
debating
P
eriod
InB
locks
:
Z
build_rules
{
min
_v
ote
_c
ount
_p
ermille
:
Z
;
margin
_n
eeded
_p
ermille
:
Z
;
debating
_p
eriod
_in_b
locks
:
Z
;
}
.
Record
Setup
:=
{
setup
R
ules
:
Rules
build_setup
{
setup
_r
ules
:
Rules
;
}
.
Inductive
Msg
:=
|
TransferOwnership
:
a
ddress
->
Msg
|
TransferOwnership
:
A
ddress
->
Msg
|
ChangeRules
:
Rules
->
Msg
|
AddMember
:
a
ddress
->
Msg
|
RemoveMember
:
a
ddress
->
Msg
|
CreateProposal
:
list
TxOut
->
Msg
|
AddMember
:
A
ddress
->
Msg
|
RemoveMember
:
A
ddress
->
Msg
|
CreateProposal
:
list
ChainAction
->
Msg
|
VoteForProposal
:
ProposalId
->
Msg
|
VoteAgainstProposal
:
ProposalId
->
Msg
|
RetractVote
:
ProposalId
->
Msg
|
FinishProposal
:
ProposalId
->
Msg
.
Record
State
:=
{
owner
:
a
ddress
;
state
R
ules
:
Rules
;
proposals
:
NatKeyedMap
.
t
Proposal
;
next
P
roposal
I
d
:
ProposalId
;
members
:
Address
Set
.
t
build_state
{
owner
:
A
ddress
;
state
_r
ules
:
Rules
;
proposals
:
Map
[
nat
,
Proposal
]
;
next
_p
roposal
_i
d
:
ProposalId
;
members
:
SetInterface
.
set
Address
;
}
.
Instance
eta
S
tate
:
Settable
_
:=
Instance
eta
_s
tate
:
Settable
_
:=
mkSettable
((
constructor
B
uild_
S
tate
)
<*>
owner
<*>
state
R
ules
((
constructor
b
uild_
s
tate
)
<*>
owner
<*>
state
_r
ules
<*>
proposals
<*>
next
P
roposal
I
d
<*>
members
)
%
set
.
<*>
next
_p
roposal
_i
d
<*>
members
)
%
set
table
.
Definition
version
:
v
ersion
:=
1
%
nat
.
Definition
validate
R
ules
(
rules
:
Rules
)
:
bool
:=
(
rules
.(
min
V
ote
C
ount
P
ermille
)
>=?
0
)
&&
(
rules
.(
min
V
ote
C
ount
P
ermille
)
<=?
1000
)
&&
(
rules
.(
margin
N
eeded
P
ermille
)
>=?
0
)
&&
(
rules
.(
margin
N
eeded
P
ermille
)
<=?
1000
)
&&
(
rules
.(
debating
P
eriod
InB
locks
)
>=?
0
).
Definition
init
(
chain
:
c
hain
)
(
details
:
c
ontract
_c
all
_details
)
(
setup
:
Setup
)
:
option
State
:=
if
validate
R
ules
setup
.(
setup
R
ules
)
then
Some
{|
owner
:=
details
.(
from
)
;
state
R
ules
:=
setup
.(
setup
R
ules
)
;
proposals
:=
NatKeyedMap
.
empty
_
;
next
P
roposal
I
d
:=
1
%
nat
;
members
:=
AddressSet
.
empty
|}
Definition
version
:
V
ersion
:=
1
%
nat
.
Definition
validate
_r
ules
(
rules
:
Rules
)
:
bool
:=
(
rules
.(
min
_v
ote
_c
ount
_p
ermille
)
>=?
0
)
&&
(
rules
.(
min
_v
ote
_c
ount
_p
ermille
)
<=?
1000
)
&&
(
rules
.(
margin
_n
eeded
_p
ermille
)
>=?
0
)
&&
(
rules
.(
margin
_n
eeded
_p
ermille
)
<=?
1000
)
&&
(
rules
.(
debating
_p
eriod
_in_b
locks
)
>=?
0
).
Definition
init
(
chain
:
C
hain
)
(
ctx
:
C
ontract
C
all
Context
)
(
setup
:
Setup
)
:
option
State
:=
if
validate
_r
ules
setup
.(
setup
_r
ules
)
then
Some
{|
owner
:=
ctx
.(
ctx_
from
);
state
_r
ules
:=
setup
.(
setup
_r
ules
);
proposals
:=
[]
%
map
;
next
_p
roposal
_i
d
:=
1
%
nat
;
members
:=
{}%
set
|}
else
None
.
Definition
addProposal
(
txs
:
list
TxOut
)
(
chain
:
chain
)
(
state
:
State
)
:
State
:=
let
id
:=
state
.(
nextProposalId
)
in
let
headBlock
:=
chain
.(
headBlock
)
in
let
proposal
:=
{|
txs
:=
txs
;
votes
:=
AddressKeyedMap
.
empty
_
;
voteResult
:=
0
;
proposedIn
:=
headBlock
.(
header
).(
blockNumber
)
|}
in
let
newProposals
:=
NatKeyedMap
.
add
id
proposal
state
.(
proposals
)
in
state
[
proposals
:=
newProposals
][
nextProposalId
:=
(
id
+
1
)
%
nat
].
Local
Definition
option_bind
{
A
B
:
Type
}
(
f
:
A
->
option
B
)
(
v
:
option
A
)
:
option
B
:=
match
v
with
|
Some
val
=>
f
val
|
None
=>
None
end
.
Local
Notation
"'do' X <- A ; B"
:=
(
option_bind
(
fun
X
=>
B
)
A
)
(
at
level
200
,
X
ident
,
A
at
level
100
,
B
at
level
200
).
Local
Notation
ret
:=
Some
.
Definition
voteProposal
(
voter
:
address
)
Definition
add_proposal
(
actions
:
list
ChainAction
)
(
chain
:
Chain
)
(
state
:
State
)
:
State
:=
let
id
:=
state
.(
next_proposal_id
)
in
let
head_block
:=
chain
.(
head_block
)
in
let
proposal
:=
{|
actions
:=
actions
;
votes
:=
[]
%
map
;
vote_result
:=
0
;
proposed_in
:=
head_block
.(
block_header
).(
block_number
)
|}
in
let
new_proposals
:=
state
.(
proposals
)[
id
<-
proposal
]
%
map
in
state
[[
proposals
:=
new_proposals
]][[
next_proposal_id
:=
(
id
+
1
)
%
nat
]].
Definition
vote_on_proposal
(
voter
:
Address
)
(
pid
:
ProposalId
)
(
vote
:
Z
)
(
state
:
State
)
:
option
State
:=
do
proposal
<-
NatKeyedMap
.
find
pid
state
.(
proposals
)
;
let
old
V
ote
:=
match
AddressKeyedMap
.
find
voter
proposal
.(
votes
)
with
|
Some
old
Vote
=>
old
Vote
do
proposal
<-
state
.(
proposals
)
[
pid
]
%
map
;
let
old
_v
ote
:=
match
proposal
.(
votes
)
[
voter
]
%
map
with
|
Some
old
=>
old
|
None
=>
0
end
in
let
new
V
otes
:=
AddressKeyedMap
.
add
vote
r
vote
proposal
.(
votes
)
in
let
new
V
ote
R
esult
:=
proposal
.(
vote
R
esult
)
-
old
V
ote
+
vote
in
let
new
P
roposal
:=
proposal
[
votes
:=
new
V
otes
][
vote
R
esult
:=
new
V
ote
R
esult
]
in
ret
(
set
proposals
(
NatKeyedMap
.
add
pid
new
P
roposal
)
state
).
let
new
_v
otes
:=
proposal
.(
vote
s
)[
vote
r
<-
vote
]
%
map
in
let
new
_v
ote
_r
esult
:=
proposal
.(
vote
_r
esult
)
-
old
_v
ote
+
vote
in
let
new
_p
roposal
:=
proposal
[
[
votes
:=
new
_v
otes
]
]
[
[
vote
_r
esult
:=
new
_v
ote
_r
esult
]
]
in
Some
(
state
[[
proposals
::=
MapInterface
.
add
pid
new
_p
roposal
]]
).
Definition
retract
V
ote
(
voter
:
a
ddress
)
Definition
retract
_v
ote
(
voter
:
A
ddress
)
(
pid
:
ProposalId
)
(
state
:
State
)
:
option
State
:=
do
proposal
<-
NatKeyedMap
.
find
pid
state
.(
proposals
)
;
do
old
V
ote
<-
AddressKeyedMap
.
find
voter
proposal
.(
votes
)
;
let
new
V
otes
:=
AddressKeyedMap
.
remove
voter
proposal
.(
votes
)
in
let
new
V
ote
R
esult
:=
proposal
.(
vote
R
esult
)
-
old
V
ote
in
let
new
P
roposal
:=
proposal
[
votes
:=
new
V
otes
][
vote
R
esult
:=
new
V
ote
R
esult
]
in
ret
(
set
proposals
(
NatKeyedMap
.
add
pid
new
P
roposal
)
state
).
Definition
finish
P
roposal
do
proposal
<-
state
.(
proposals
)
[
pid
]
%
map
;
do
old
_v
ote
<-
proposal
.(
votes
)
[
voter
]
%
map
;
let
new
_v
otes
:=
MapInterface
.
remove
voter
proposal
.(
votes
)
in
let
new
_v
ote
_r
esult
:=
proposal
.(
vote
_r
esult
)
-
old
_v
ote
in
let
new
_p
roposal
:=
proposal
[
[
votes
:=
new
_v
otes
]
]
[
[
vote
_r
esult
:=
new
_v
ote
_r
esult
]
]
in
Some
(
state
[[
proposals
::=
MapInterface
.
add
pid
new
_p
roposal
]]
).
Definition
finish
_p
roposal
(
pid
:
ProposalId
)
(
state
:
State
)
(
chain
:
c
hain
)
:
option
(
State
*
list
TxOut
)
:=
do
proposal
<-
NatKeyedMap
.
find
pid
state
.(
proposals
)
;
let
rules
:=
state
.(
state
R
ules
)
in
let
debate
E
nd
:=
(
Z
.
of_nat
proposal
.(
proposed
I
n
))
+
rules
.(
debating
P
eriod
InB
locks
)
in
let
cur
B
lock
:=
chain
.(
head
B
lock
)
in
if
(
Z
.
of_nat
cur
B
lock
.(
header
).(
block
N
umber
))
<?
debate
E
nd
then
(
chain
:
C
hain
)
:
option
(
State
*
list
ChainAction
)
:=
do
proposal
<-
state
.(
proposals
)
[
pid
]
%
map
;
let
rules
:=
state
.(
state
_r
ules
)
in
let
debate
_e
nd
:=
(
Z
.
of_nat
proposal
.(
proposed
_i
n
))
+
rules
.(
debating
_p
eriod
_in_b
locks
)
in
let
cur
_b
lock
:=
chain
.(
head
_b
lock
)
in
if
(
Z
.
of_nat
cur
_b
lock
.(
block_
header
).(
block
_n
umber
))
<?
debate
_e
nd
then
None
else
let
newState
:=
set
proposals
(
NatKeyedMap
.
remove
pid
)
state
in
let
totalVotesForProposal
:=
Z
.
of_nat
(
AddressKeyedMap
.
cardinal
proposal
.(
votes
))
in
let
totalMembers
:=
Z
.
of_nat
(
AddressSet
.
cardinal
state
.(
members
))
in
let
ayeVotes
:=
(
proposal
.(
voteResult
)
+
totalVotesForProposal
)
/
2
in
let
voteCountPermille
:=
totalVotesForProposal
*
1000
/
totalMembers
in
let
ayePermille
:=
ayeVotes
*
1000
/
totalVotesForProposal
in
let
enoughVoters
:=
voteCountPermille
>=?
rules
.(
minVoteCountPermille
)
in
let
enoughAyes
:=
ayePermille
>=?
rules
.(
marginNeededPermille
)
in
let
responseTxs
:=
if
(
enoughVoters
&&
enoughAyes
)
%
bool
then
proposal
.(
txs
)
else
[]
in
ret
(
newState
,
responseTxs
).
let
new_state
:=
state
[[
proposals
::=
MapInterface
.
remove
pid
]]
in
let
total_votes_for_proposal
:=
Z
.
of_nat
(
MapInterface
.
cardinal
proposal
.(
votes
))
in
let
total_members
:=
Z
.
of_nat
(
SetInterface
.
cardinal
state
.(
members
))
in
let
aye_votes
:=
(
proposal
.(
vote_result
)
+
total_votes_for_proposal
)
/
2
in
let
vote_count_permille
:=
total_votes_for_proposal
*
1000
/
total_members
in
let
aye_permille
:=
aye_votes
*
1000
/
total_votes_for_proposal
in
let
enough_voters
:=
vote_count_permille
>=?
rules
.(
min_vote_count_permille
)
in
let
enough_ayes
:=
aye_permille
>=?
rules
.(
margin_needed_permille
)
in
let
response_acts
:=
if
(
enough_voters
&&
enough_ayes
)
%
bool
then
proposal
.(
actions
)
else
[
]
in
Some
(
new_state
,
response_acts
).
Definition
receive
(
chain
:
c
hain
)
(
chain
:
C
hain
)
(
state
:
State
)
(
details
:
c
ontract
_c
all
_details
)
(
maybe
M
sg
:
option
Msg
)
:
option
(
State
*
list
TxOut
)
:=
let
sender
:=
details
.(
from
)
in
let
is
F
rom
O
wner
:=
(
sender
=?
state
.(
owner
))
%
address
in
let
is
F
rom
M
ember
:=
AddressSet
.
mem
sender
state
.(
members
)
in
let
without
Tx
s
:=
option_map
(
fun
new
S
tate
=>
(
new
S
tate
,
[]))
in
match
is
F
rom
O
wner
,
is
F
rom
M
ember
,
maybe
M
sg
with
|
true
,
_
,
Some
(
TransferOwnership
new
O
wner
)
=>
Some
(
state
[
owner
:=
new
O
wner
],
[])
|
true
,
_
,
Some
(
ChangeRules
new
R
ules
)
=>
if
validate
R
ules
new
R
ules
then
Some
(
state
[
state
R
ules
:=
new
R
ules
],
[])
(
ctx
:
C
ontract
C
all
Context
)
(
maybe
_m
sg
:
option
Msg
)
:
option
(
State
*
list
ChainAction
)
:=
let
sender
:=
ctx
.(
ctx_
from
)
in
let
is
_f
rom
_o
wner
:=
(
sender
=?
state
.(
owner
))
%
address
in
let
is
_f
rom
_m
ember
:=
(
sender
\
in
state
.(
members
)
)
%
set
in
let
without
_action
s
:=
option_map
(
fun
new
_s
tate
=>
(
new
_s
tate
,
[
]))
in
match
is
_f
rom
_o
wner
,
is
_f
rom
_m
ember
,
maybe
_m
sg
with
|
true
,
_
,
Some
(
TransferOwnership
new
_o
wner
)
=>
Some
(
state
[
[
owner
:=
new
_o
wner
]
]
,
[
])
|
true
,
_
,
Some
(
ChangeRules
new
_r
ules
)
=>
if
validate
_r
ules
new
_r
ules
then
Some
(
state
[
[
state
_r
ules
:=
new
_r
ules
]
]
,
[
])
else
None
|
true
,
_
,
Some
(
AddMember
newMember
)
=>
let
newMembers
:=
AddressSet
.
add
newMember
state
.(
members
)
in
Some
(
state
[
members
:=
newMembers
],
[])
|
true
,
_
,
Some
(
AddMember
new_member
)
=>
Some
(
state
[[
members
::=
SetInterface
.
add
new_member
]],
[
])
|
true
,
_
,
Some
(
RemoveMember
oldMember
)
=>
let
newMembers
:=
AddressSet
.
remove
oldMember
state
.(
members
)
in
Some
(
state
[
members
:=
newMembers
],
[])
|
true
,
_
,
Some
(
RemoveMember
old_member
)
=>
Some
(
state
[[
members
::=
SetInterface
.
remove
old_member
]],
[
])
|
_
,
true
,
Some
(
CreateProposal
tx
s
)
=>
Some
(
add
P
roposal
tx
s
chain
state
,
[])
|
_
,
true
,
Some
(
CreateProposal
action
s
)
=>
Some
(
add
_p
roposal
action
s
chain
state
,
[
])
|
_
,
true
,
Some
(
VoteForProposal
pid
)
=>
without
Tx
s
(
vote
P
roposal
sender
pid
1
state
)
without
_action
s
(
vote
_on_p
roposal
sender
pid
1
state
)
|
_
,
true
,
Some
(
VoteAgainstProposal
pid
)
=>
without
Tx
s
(
vote
P
roposal
sender
pid
(
-
1
)
state
)
without
_action
s
(
vote
_on_p
roposal
sender
pid
(
-
1
)
state
)
|
_
,
true
,
Some
(
RetractVote
pid
)
=>
without
Tx
s
(
retract
V
ote
sender
pid
state
)
without
_action
s
(
retract
_v
ote
sender
pid
state
)
|
_
,
_
,
Some
(
FinishProposal
pid
)
=>
finish
P
roposal
pid
state
chain
finish
_p
roposal
pid
state
chain
|
_
,
_
,
_
=>
None
...
...
src/Monads.v
0 → 100644
View file @
f0c73550
Definition
option_bind
{
A
B
:
Type
}
(
f
:
A
->
option
B
)
(
v
:
option
A
)
:
option
B
:=
match
v
with
|
Some
val
=>
f
val
|
None
=>
None
end
.
Notation
"'do' X <- A ; B"
:=
(
option_bind
(
fun
X
=>
B
)
A
)
(
at
level
200
,
X
ident
,
A
at
level
100
,
B
at
level
200
).
Notation
"'do' X : T <- A ; B"
:=
(
option_bind
(
fun
x
:
T
=>
B
)
A
)
(
at
level
200
,
X
ident
,
A
at
level
100
,
B
at
level
200
).
\ No newline at end of file
src/Oak.v
View file @
f0c73550
...
...
@@ -20,7 +20,7 @@ Program Instance empty_set_strict_order
Solve
Obligations
with
contradiction
.
Program
Instance
empty_set_ordered_type
:
UsualOrderedType
Empty_set
.
Solve
Obligations
with
contradiction
.
Local
Fixpoint
interp_type_with_ordering
(
t
:
OakType
)
:
{
T
:
Type
&
OrderedType
T
}
:=
match
t
with
|
oak_empty
=>
existT
OrderedType
Empty_set
_
...
...
@@ -56,7 +56,7 @@ Record OakValue :=
oak_value
:
interp_type
oak_value_type
;
}
.
Definition
oak_value
_extract
(
t
:
OakType
)
(
value
:
OakValue
)
:
option
(
interp_type
t
).
Definition
extract_
oak_value
(
t
:
OakType
)
(
value
:
OakValue
)
:
option
(
interp_type
t
).
Proof
.
destruct
value
as
[
ty
val
].
destruct
(
eq_oak_type_dec
t
ty
).
...
...
@@ -82,18 +82,18 @@ Definition test_map2 : OakValue :=
(
oak_map
(
oak_map
oak_int
oak_int
)
oak_int
)
[][[][
5
<-
10
][
6
<-
10
][
5
<-
15
]
<-
15
]
%
Z
.
Compute
(
oak_value
_extract
oak_bool
test_bool
)
:
option
bool
.
Compute
(
oak_value
_extract
oak_int
test_bool
)
:
option
Z
.
Compute
(
oak_value
_extract
oak_bool
test_int
)
:
option
bool
.
Compute
(
oak_value
_extract
oak_int
test_int
)
:
option
Z
.
Compute
(
oak_value
_extract
(
oak_set
oak_int
)
test_set
)
:
option
(
set
Z
).
Compute
(
extract_
oak_value
oak_bool
test_bool
)
:
option
bool
.
Compute
(
extract_
oak_value
oak_int
test_bool
)
:
option
Z
.
Compute
(
extract_
oak_value
oak_bool
test_int
)
:
option
bool
.
Compute
(
extract_
oak_value
oak_int
test_int
)
:
option
Z
.
Compute
(
extract_
oak_value
(
oak_set
oak_int
)
test_set
)
:
option
(
set
Z
).
Compute
(
oak_value
_extract
(
extract_
oak_value
(
oak_map
(
oak_map
oak_int
oak_int
)
oak_int
)
test_map2
)
:
option
Map
[
Map
[
Z
,
Z
],
Z
].
Compute
(
option_map
SetInterface
.
elements
(
oak_value
_extract
(
oak_set
oak_int
)
test_set
)).
Compute
(
option_map
elements
(
oak_value
_extract
(
oak_map
oak_int
oak_int
)
test_map
)).
Compute
(
option_map
SetInterface
.
elements
(
extract_
oak_value
(
oak_set
oak_int
)
test_set
)).
Compute
(
option_map
elements
(
extract_
oak_value
(
oak_map
oak_int
oak_int
)
test_map
)).
*
)
\ No newline at end of file
vendor/record-update/RecordSet.v
View file @
f0c73550
...
...
@@ -19,7 +19,7 @@ Definition applicative_ap {E}
forall
(
x
:
Reader
E
A
),
Reader
E
(
fun
e
=>
B
e
(
x
e
))
:=
fun
x
=>
fun
e
=>
f
e
(
x
e
).
Module
ApplicativeNotations
.
Delimit
Scope
settable_scope
with
set
.
Delimit
Scope
settable_scope
with
set
table
.
Infix
"<*>"
:=
(
applicative_ap
)
(
at
level
11
,
left
associativity
)
:
settable_scope
.
End
ApplicativeNotations
.
...
...
@@ -90,8 +90,8 @@ Hint Extern 1 (Setter _) => SetInstance_t : typeclass_instances.
Module
RecordSetNotations
.
Delimit
Scope
record_set
with
rs
.
Open
Scope
rs
.
Notation
"x [ proj := v ]"
:=
(
set
proj
(
constructor
v
)
x
)
(
at
level
8
,
left
associativity
)
:
record_set
.
Notation
"x [ proj ::= f ]"
:=
(
set
proj
f
x
)
(
at
level
8
,
f
at
next
level
,
left
associativity
)
:
record_set
.
Notation
"x [
[
proj := v
]
]"
:=
(
set
proj
(
constructor
v
)
x
)
(
at
level
12
,
left
associativity
)
:
record_set
.
Notation
"x [
[
proj ::= f
]
]"
:=
(
set
proj
f
x
)
(
at
level
12
,
f
at
next
level
,
left
associativity
)
:
record_set
.
End
RecordSetNotations
.
Write
Preview