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
ee50d5ed
Commit
ee50d5ed
authored
May 14, 2019
by
Jakob Botsch Nielsen
Browse files
Rename some things for technical report
parent
7c0f29b5
Pipeline
#12352
failed with stage
in 1 minute and 31 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/Blockchain.v
View file @
ee50d5ed
...
...
@@ -20,11 +20,12 @@ Definition Amount := Z.
Bind
Scope
Z_scope
with
Amount
.
Class
ChainBase
Types
:=
build_chain_base
_types
{
Class
ChainBase
:=
build_chain_base
{
Address
:
Type
;
address_eqb
:
Address
->
Address
->
bool
;
address_eqb_spec
:
forall
(
a
b
:
Address
),
Bool
.
reflect
(
a
=
b
)
(
address_eqb
a
b
);
address_eqb_spec
:
forall
(
a
b
:
Address
),
Bool
.
reflect
(
a
=
b
)
(
address_eqb
a
b
);
address_eqdec
:>
stdpp
.
base
.
EqDecision
Address
;
address_countable
:>
countable
.
Countable
Address
;
address_ote
:>
OakTypeEquivalence
Address
;
...
...
@@ -48,7 +49,7 @@ Global Ltac destruct_address_eq :=
end
.
Section
Blockchain
.
Context
{
BaseTypes
:
ChainBase
Types
}
.
Context
{
BaseTypes
:
ChainBase
}
.
Lemma
address_eq_refl
x
:
address_eqb
x
x
=
true
.
...
...
@@ -66,12 +67,6 @@ Proof. destruct_address_eq; auto; congruence. Qed.
Record
ContractDeployment
:=
build_contract_deployment
{
deployment_version
:
Version
;
(
*
todo
:
model
any
type
/
constraints
so
we
can
have
this
.
Right
now
the
problem
is
that
Congress
messages
can
contain
_
any_
oak
value
(
for
the
congress
to
send
out
),
so
there
is
no
bijection
from
its
message
type
to
oak
type
.
deployment_msg_ty
:
OakType
;
deployment_state_ty
:
OakType
;
*
)
deployment_setup
:
OakValue
;
}
.
...
...
@@ -108,7 +103,7 @@ Record Chain :=
(
*
Two
chains
are
said
to
be
equivalent
if
they
are
extensionally
equal
.
We
will
later
require
that
all
deployed
contracts
respect
this
relation
.
This
equivalence
is
equality
if
un
ivalence
is
assumed
.
*
)
This
equivalence
is
equality
if
f
un
ext
is
assumed
.
*
)
Record
ChainEquiv
(
c1
c2
:
Chain
)
:
Prop
:=
build_chain_equiv
{
header_eq
:
block_header
c1
=
block_header
c2
;
...
...
@@ -206,24 +201,25 @@ where Address -> WeakContract would be some operation that the chain provides
to
allow
access
to
contracts
in
deployments
.
*
)
with
WeakContract
:=
|
build_weak_contract
(
version
:
Version
)
(
init
:
Chain
->
ContractCallContext
->
OakValue
->
option
OakValue
)
(
*
Init
respects
chain
equivalence
*
)
(
init_proper
:
Proper
(
ChainEquiv
==>
eq
==>
eq
==>
eq
)
init
)
(
receive
:
Chain
->
ContractCallContext
->
OakValue
(
*
state
*
)
->
option
OakValue
(
*
message
*
)
->
option
(
OakValue
*
list
ActionBody
))
(
*
And
so
does
receive
*
)
(
receive_proper
:
Proper
(
ChainEquiv
==>
eq
==>
eq
==>
eq
==>
eq
)
receive
).
|
build_weak_contract
(
version
:
Version
)
(
init
:
Chain
->
ContractCallContext
->
OakValue
(
*
setup
*
)
->
option
OakValue
)
(
*
Init
respects
chain
equivalence
*
)
(
init_proper
:
Proper
(
ChainEquiv
==>
eq
==>
eq
==>
eq
)
init
)
(
receive
:
Chain
->
ContractCallContext
->
OakValue
(
*
state
*
)
->
option
OakValue
(
*
message
*
)
->
option
(
OakValue
*
list
ActionBody
))
(
*
And
so
does
receive
*
)
(
receive_proper
:
Proper
(
ChainEquiv
==>
eq
==>
eq
==>
eq
==>
eq
)
receive
).
Definition
wc_version
(
wc
:
WeakContract
)
:
Version
:=
let
(
v
,
_
,
_
,
_
,
_
)
:=
wc
in
v
.
...
...
@@ -267,25 +263,25 @@ use and interact with when they want deployment. We keep the weak contract
only
"internally"
for
blockchains
,
while
any
strongly
-
typed
contract
can
be
converted
to
and
from
*
)
Record
Contract
(
s
etup
_ty
msg_ty
s
tate
_ty
:
Type
)
`
{
setup_eq
:
OakTypeEquivalence
s
etup
_ty
}
`
{
msg_eq
:
OakTypeEquivalence
m
sg
_ty
}
`
{
state_eq
:
OakTypeEquivalence
s
tate
_ty
}
:=
(
S
etup
Msg
S
tate
:
Type
)
`
{
OakTypeEquivalence
S
etup
}
`
{
OakTypeEquivalence
M
sg
}
`
{
OakTypeEquivalence
S
tate
}
:=
build_contract
{
version
:
Version
;
init
:
Chain
->
ContractCallContext
->
s
etup
_ty
->
option
s
tate
_ty
;
S
etup
->
option
S
tate
;
init_proper
:
Proper
(
ChainEquiv
==>
eq
==>
eq
==>
eq
)
init
;
receive
:
Chain
->
ContractCallContext
->
s
tate
_ty
->
option
m
sg
_ty
->
option
(
s
tate
_ty
*
list
ActionBody
);
S
tate
->
option
M
sg
->
option
(
S
tate
*
list
ActionBody
);
receive_proper
:
Proper
(
ChainEquiv
==>
eq
==>
eq
==>
eq
==>
eq
)
receive
;
}
.
...
...
@@ -296,11 +292,11 @@ Arguments receive {_ _ _ _ _ _}.
Arguments
build_contract
{
_
_
_
_
_
_
}
.
Program
Definition
contract_to_weak_contract
{
s
etup
_ty
msg_ty
s
tate
_ty
:
Type
}
`
{
setup_eq
:
OakTypeEquivalence
s
etup
_ty
}
`
{
msg_eq
:
OakTypeEquivalence
m
sg
_ty
}
`
{
state_eq
:
OakTypeEquivalence
s
tate
_ty
}
(
c
:
Contract
s
etup
_ty
msg_ty
s
tate
_ty
)
:
WeakContract
:=
{
S
etup
Msg
S
tate
:
Type
}
`
{
OakTypeEquivalence
S
etup
}
`
{
OakTypeEquivalence
M
sg
}
`
{
OakTypeEquivalence
S
tate
}
(
c
:
Contract
S
etup
Msg
S
tate
)
:
WeakContract
:=
let
weak_init
chain
ctx
oak_setup
:=
do
setup
<-
deserialize
oak_setup
;
do
state
<-
c
.(
init
)
chain
ctx
setup
;
...
...
@@ -343,33 +339,33 @@ Coercion contract_to_weak_contract : Contract >-> WeakContract.
(
*
Deploy
a
strongly
typed
contract
with
some
amount
and
setup
*
)
Definition
create_deployment
{
s
etup
_ty
msg_ty
s
tate
_ty
:
Type
}
`
{
OakTypeEquivalence
s
etup
_ty
}
`
{
OakTypeEquivalence
m
sg
_ty
}
`
{
OakTypeEquivalence
s
tate
_ty
}
{
S
etup
Msg
S
tate
:
Type
}
`
{
OakTypeEquivalence
S
etup
}
`
{
OakTypeEquivalence
M
sg
}
`
{
OakTypeEquivalence
S
tate
}
(
amount
:
Amount
)
(
contract
:
Contract
s
etup
_ty
msg_ty
s
tate
_ty
)
(
setup
:
s
etup
_ty
)
:
ActionBody
:=
(
contract
:
Contract
S
etup
Msg
S
tate
)
(
setup
:
S
etup
)
:
ActionBody
:=
act_deploy
amount
contract
(
serialize
setup
).
(
*
The
contract
interface
is
the
main
mechanism
allowing
a
deployed
contract
to
interact
with
another
deployed
contract
.
This
hides
the
ugly
details
of
everything
being
OakValue
away
from
contracts
.
*
)
Record
ContractInterface
{
s
etup
_ty
msg_ty
s
tate
_ty
:
Type
}
:=
Record
ContractInterface
{
S
etup
Msg
S
tate
:
Type
}
:=
build_contract_interface
{
(
*
The
address
of
the
contract
being
interfaced
with
*
)
contract_address
:
Address
;
(
*
Version
of
the
contract
*
)
contract_version
:
Version
;
(
*
The
setup
that
was
passed
when
the
contract
was
deployed
*
)
contract_setup
:
s
etup
_ty
;
contract_setup
:
S
etup
;
(
*
Obtain
the
state
at
some
point
of
time
*
)
get_state
:
Chain
->
option
s
tate
_ty
;
get_state
:
Chain
->
option
S
tate
;
(
*
Make
an
action
transferring
money
to
the
contract
without
a
message
*
)
transfer
:
Amount
->
ActionBody
;
(
*
Make
an
action
calling
the
contract
*
)
call
:
Amount
->
m
sg
_ty
->
ActionBody
;
call
:
Amount
->
M
sg
->
ActionBody
;
}
.
Arguments
ContractInterface
_
_
_
:
clear
implicits
.
...
...
@@ -377,14 +373,14 @@ Arguments ContractInterface _ _ _ : clear implicits.
Definition
get_contract_interface
(
chain
:
Chain
)
(
addr
:
Address
)
(
s
etup
_ty
msg_ty
s
tate
_ty
:
Type
)
`
{
OakTypeEquivalence
s
etup
_ty
}
`
{
OakTypeEquivalence
m
sg
_ty
}
`
{
OakTypeEquivalence
s
tate
_ty
}
:
option
(
ContractInterface
s
etup
_ty
msg_ty
s
tate
_ty
)
:=
(
S
etup
Msg
S
tate
:
Type
)
`
{
OakTypeEquivalence
S
etup
}
`
{
OakTypeEquivalence
M
sg
}
`
{
OakTypeEquivalence
S
tate
}
:
option
(
ContractInterface
S
etup
Msg
S
tate
)
:=
do
'
build_contract_deployment
ver
ov_setup
<-
contract_deployment
chain
addr
;
do
setup
<-
deserialize
ov_setup
;
let
ifc_get_state
chain
:=
deserialize
=<<
(
contract_state
chain
addr
)
in
let
ifc_get_state
chain
:=
contract_state
chain
addr
>>=
deserialize
in
let
ifc_transfer
:=
act_transfer
addr
in
let
ifc_call
amount
msg
:=
act_call
addr
amount
(
serialize
msg
)
in
Some
{|
contract_address
:=
addr
;
...
...
@@ -722,28 +718,28 @@ Record ChainState :=
}
.
Inductive
ChainEvent
:
ChainState
->
ChainState
->
Type
:=
|
evt_block
:
forall
{
prev
:
ChainState
}
{
header
:
BlockHeader
}
{
baker
:
Address
}
{
next
:
ChainState
}
,
chain_state_queue
prev
=
[]
->
IsValidNextBlock
header
(
block_header
prev
)
->
Forall
ActIsFromAccount
(
chain_state_queue
next
)
->
EnvironmentEquiv
next
(
add_new_block_header
header
baker
prev
)
->
ChainEvent
prev
next
|
evt_step
:
forall
{
prev
:
ChainState
}
{
act
:
Action
}
{
acts
:
list
Action
}
{
next
:
ChainState
}
{
new_acts
:
list
Action
}
,
chain_state_queue
prev
=
act
::
acts
->
ChainStep
prev
act
next
new_acts
->
chain_state_queue
next
=
new_acts
++
acts
->
ChainEvent
prev
next
|
evt_block
:
forall
{
prev
:
ChainState
}
{
header
:
BlockHeader
}
{
baker
:
Address
}
{
next
:
ChainState
}
,
chain_state_queue
prev
=
[]
->
IsValidNextBlock
header
(
block_header
prev
)
->
Forall
ActIsFromAccount
(
chain_state_queue
next
)
->
EnvironmentEquiv
next
(
add_new_block_header
header
baker
prev
)
->
ChainEvent
prev
next
|
evt_step
:
forall
{
prev
:
ChainState
}
{
act
:
Action
}
{
acts
:
list
Action
}
{
next
:
ChainState
}
{
new_acts
:
list
Action
}
,
chain_state_queue
prev
=
act
::
acts
->
ChainStep
prev
act
next
new_acts
->
chain_state_queue
next
=
new_acts
++
acts
->
ChainEvent
prev
next
|
evt_permute
:
forall
{
prev
new
:
ChainState
}
,
chain_state_env
prev
=
chain_state_env
new
->
...
...
@@ -936,7 +932,7 @@ Class ChainBuilderType :=
(
finalized_height
:
nat
)
:
option
builder_type
;
builder_
trac
e
(
b
:
builder_type
)
:
builder_
reachabl
e
(
b
:
builder_type
)
:
reachable
(
build_chain_state
(
builder_env
b
)
[]);
}
.
...
...
src/ChainedList.v
View file @
ee50d5ed
...
...
@@ -6,12 +6,12 @@ also a snoc list. Note that this is not unlike fhlist from CPDT,
except
we
place
further
restrictions
on
it
.
*
)
From
SmartContracts
Require
Import
Automation
.
Section
ChainedList
.
Context
{
p
oint
:
Type
}
{
l
ink
:
p
oint
->
p
oint
->
Type
}
.
Context
{
P
oint
:
Type
}
{
L
ink
:
P
oint
->
P
oint
->
Type
}
.
Inductive
ChainedList
:
p
oint
->
p
oint
->
Type
:=
|
clnil
:
forall
{
elm
}
,
ChainedList
elm
elm
Inductive
ChainedList
:
P
oint
->
P
oint
->
Type
:=
|
clnil
:
forall
{
p
}
,
ChainedList
p
p
|
snoc
:
forall
{
from
mid
to
}
,
ChainedList
from
mid
->
l
ink
mid
to
->
ChainedList
from
to
.
ChainedList
from
mid
->
L
ink
mid
to
->
ChainedList
from
to
.
Fixpoint
clist_app
{
from
mid
to
}
...
...
src/Circulation.v
View file @
ee50d5ed
...
...
@@ -8,7 +8,7 @@ From RecordUpdate Require Import RecordSet.
Import
ListNotations
.
Section
Circulation
.
Context
{
ChainBase
Types
:
ChainBase
Types
}
.
Context
{
ChainBase
:
ChainBase
}
.
Context
`
{
Finite
Address
}
.
Definition
circulation
(
chain
:
Chain
)
:=
...
...
src/Congress.v
View file @
ee50d5ed
...
...
@@ -16,7 +16,7 @@ Import ListNotations.
Import
RecordSetNotations
.
Section
Congress
.
Context
{
BaseTypes
:
ChainBase
Types
}
.
Context
{
BaseTypes
:
ChainBase
}
.
Local
Open
Scope
Z
.
Set
Primitive
Projections
.
...
...
@@ -890,7 +890,7 @@ Corollary congress_txs_after_block
length
(
outgoing_txs
new
addr
)
<=
num_acts_created_in_proposals
new
addr
.
Proof
.
intros
add_block
contract
congress_at_addr
.
pose
proof
(
congress_txs_well_behaved
_
_
(
builder_
trac
e
new
)
congress_at_addr
).
pose
proof
(
congress_txs_well_behaved
_
_
(
builder_
reachabl
e
new
)
congress_at_addr
).
cbn
in
*
.
lia
.
Qed
.
...
...
src/LocalBlockchain.v
View file @
ee50d5ed
...
...
@@ -24,7 +24,7 @@ Local Open Scope bool.
Definition
AddrSize
:
N
:=
2
^
128.
Definition
ContractAddrBase
:
N
:=
AddrSize
/
2.
Global
Instance
LocalChainBase
Types
:
ChainBase
Types
:=
Global
Instance
LocalChainBase
:
ChainBase
:=
{|
Address
:=
BoundedN
AddrSize
;
address_eqb
:=
BoundedN
.
eqb
;
address_eqb_spec
:=
BoundedN
.
eqb_spec
;
...
...
@@ -511,12 +511,12 @@ Global Instance LocalChainBuilderDepthFirst : ChainBuilderType :=
builder_initial
:=
lcb_initial
;
builder_env
lcb
:=
lcb_lc
lcb
;
builder_add_block
:=
add_block
true
;
builder_
trac
e
:=
lcb_trace
;
|}
.
builder_
reachabl
e
:=
lcb_trace
;
|}
.
Definition
LocalChainBuilderBreadthFirst
:
ChainBuilderType
:=
{|
builder_type
:=
LocalChainBuilder
;
builder_initial
:=
lcb_initial
;
builder_env
lcb
:=
lcb_lc
lcb
;
builder_add_block
:=
add_block
false
;
builder_
trac
e
:=
lcb_trace
;
|}
.
builder_
reachabl
e
:=
lcb_trace
;
|}
.
End
LocalBlockchain
.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment