Skip to content

Commit 92756ab

Browse files
committed
fix resource logic functions
1 parent 1b2ccba commit 92756ab

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

AVM/Class/Translation/Logics.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ private def Constructor.Message.logicFun
1818
let newObjData := constr.body argsData |>.value vals
1919
let consumedResObjs := Logic.selectObjectResources args.consumed
2020
let createdResObjs := Logic.selectObjectResources args.created
21-
Logic.checkResourcesData [newObjData.toSomeObjectData] consumedResObjs
22-
&& Logic.checkResourcesData [newObjData.toSomeObjectData] createdResObjs
21+
let! [newObjRes] := createdResObjs
22+
let uid : ObjectId := newObjRes.nonce.value
23+
Logic.checkResourceValues [newObjData.toObjectValue uid] consumedResObjs
24+
&& Logic.checkResourceValues [newObjData.toObjectValue uid] createdResObjs
2325
&& Logic.checkResourcesEphemeral consumedResObjs
2426
&& Logic.checkResourcesPersistent createdResObjs
2527
&& constr.invariant argsData
@@ -38,7 +40,7 @@ private def Destructor.Message.logicFun
3840
let createdResObjs := Logic.selectObjectResources args.created
3941
let! [selfRes] := consumedResObjs
4042
let try selfObj : Object classId.label := Object.fromResource selfRes
41-
Logic.checkResourcesData [selfObj.toSomeObjectData] createdResObjs
43+
Logic.checkResourceValues [selfObj.toObjectValue] createdResObjs
4244
&& Logic.checkResourcesPersistent consumedResObjs
4345
&& Logic.checkResourcesEphemeral createdResObjs
4446
&& destructor.invariant selfObj argsData
@@ -61,7 +63,7 @@ private def Method.Message.logicFun
6163
let body := method.body selfObj argsData
6264
let try vals : body.params.Product := tryCast msg.vals
6365
let createdObject : Object classId.label := body |>.value vals
64-
Logic.checkResourcesData [createdObject.toSomeObjectData] createdResObjs
66+
Logic.checkResourceValues [createdObject.toObjectValue] createdResObjs
6567
&& Logic.checkResourcesPersistent consumedResObjs
6668
&& Logic.checkResourcesPersistent createdResObjs
6769

@@ -111,5 +113,3 @@ def Method.Message.logic
111113
def logic {lab : Ecosystem.Label} {classId : lab.ClassId} (cl : Class classId) : Anoma.Logic :=
112114
{ reference := classId.label.logicRef,
113115
function := logicFun cl }
114-
115-
end AVM.Class

AVM/Logic.lean

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@ def filterOutDummy (resources : List Anoma.Resource.{u, v}) : List Anoma.Resourc
1111
resources.filter (not ∘ Action.isDummyResource)
1212

1313
/-- Checks that the number of objects and resources match, and that the
14-
resources' quantity, value and labels match the objects' data and labels.
15-
This check is used in the constructor and method message logics. Dummy resources
16-
in the `resources` list are ignored. -/
17-
def checkResourcesData (objectData : List SomeObjectData) (resources : List Anoma.Resource) : Bool :=
14+
quantity, value and labels of each resource match the corresponding object.
15+
This check is used in the constructor, destructor and method message logics.
16+
Dummy resources in the `resources` list are ignored. -/
17+
def checkResourceValues (objectValues : List ObjectValue) (resources : List Anoma.Resource) : Bool :=
1818
let resources' := Logic.filterOutDummy resources
19-
objectData.length == resources'.length
20-
&& List.and (List.zipWith resourceDataEq objectData resources')
19+
objectValues.length == resources'.length
20+
&& List.and (List.zipWith resourceValueEq objectValues resources')
2121
where
22-
resourceDataEq (sdata : SomeObjectData) (res : Anoma.Resource) : Bool :=
22+
resourceValueEq (sdata : ObjectValue) (res : Anoma.Resource) : Bool :=
2323
sdata.label === res.label &&
2424
sdata.label.logicRef == res.logicRef &&
2525
sdata.data.quantity == res.quantity &&
26-
let try privateFields := tryCast sdata.data.privateFields
27-
res.value == privateFields
26+
let try resVal : Object.Resource.Value sdata.label := tryCast res.value
27+
resVal.privateFields == sdata.data.privateFields &&
28+
resVal.uid == sdata.uid
2829

2930
def checkResourcesEphemeral (resources : List Anoma.Resource) : Bool :=
3031
Logic.filterOutDummy resources |>.all Anoma.Resource.isEphemeral

AVM/Object.lean

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@ instance ObjectData.inhabited (lab : Class.Label) : Inhabited (ObjectData lab) w
1616
instance ObjectData.hasTypeRep (lab : Class.Label) : TypeRep (ObjectData lab) where
1717
rep := Rep.composite "AVM.ObjectData" [Rep.atomic lab.name]
1818

19-
structure SomeObjectData where
19+
structure ObjectValue where
2020
{label : Class.Label}
21+
uid : ObjectId
2122
data : ObjectData label
2223

23-
instance SomeObjectData.hasTypeRep : TypeRep SomeObjectData where
24-
rep := Rep.atomic "AVM.SomeObjectData"
25-
26-
instance SomeObjectData.hasBEq : BEq SomeObjectData where
27-
beq a b := a.label === b.label && a.data === b.data
28-
29-
def ObjectData.toSomeObjectData {lab : Class.Label} (data : ObjectData lab) : SomeObjectData := {data}
24+
def ObjectData.toObjectValue {lab : Class.Label} (uid : ObjectId) (data : ObjectData lab) : ObjectValue :=
25+
⟨uid, data⟩
3026

3127
/-- Represents a concrete object, translated into a resource. For class
3228
represetation (object description), see `AVM.Class`. -/
@@ -52,9 +48,8 @@ instance SomeObject.hasBEq : BEq SomeObject where
5248

5349
def Object.toSomeObject {lab : Class.Label} (object : Object lab) : SomeObject := ⟨object⟩
5450

55-
def Object.toSomeObjectData {lab : Class.Label} (object : Object lab) : SomeObjectData := ⟨object.data⟩
56-
57-
def SomeObject.toSomeObjectData (object : SomeObject) : SomeObjectData := ⟨object.object.data⟩
51+
def Object.toObjectValue {lab : Class.Label} (obj : Object lab) : ObjectValue :=
52+
obj.data.toObjectValue obj.uid
5853

5954
structure Object.Resource.Label where
6055
/-- The label of the class -/

Anoma/Nonce.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Anoma.NullifierKey
55
namespace Anoma
66

77
structure Nonce where
8-
nat : Nat
8+
value : Nat
99
deriving BEq
1010

1111
instance Nonce.hasTypeRep : TypeRep Nonce where
@@ -15,4 +15,4 @@ instance Nonce.instInhabited : Inhabited Nonce where
1515
default := ⟨0
1616

1717
def Nonce.todo : Nonce where
18-
nat := 0
18+
value := 0

0 commit comments

Comments
 (0)