Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for _origin implicit transition parameter #921

Merged
merged 3 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 3 additions & 2 deletions src/base/Cashflow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1938,8 +1938,9 @@ struct
let empty_local_env = AssocDictionary.make_dict () in
let implicit_local_env =
AssocDictionary.insert MessagePayload.amount_label Money
(AssocDictionary.insert MessagePayload.sender_label NotMoney
empty_local_env)
(AssocDictionary.insert MessagePayload.origin_label NotMoney
(AssocDictionary.insert MessagePayload.sender_label NotMoney
empty_local_env))
in
let init_local_env =
List.fold_left comp_params ~init:implicit_local_env
Expand Down
16 changes: 15 additions & 1 deletion src/base/ContractUtil.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ module MessagePayload = struct

let sender_label = "_sender"

let origin_label = "_origin"

let recipient_label = "_recipient"

let eventname_label = "_eventname"
Expand Down Expand Up @@ -69,6 +71,12 @@ module MessagePayload = struct
Some (pure a)
| _ -> None)

let get_origin =
get_value_for_entry origin_label (function
| ByStrX bs as a when CULiteral.Bystrx.width bs = address_length ->
Some (pure a)
| _ -> None)

let get_amount =
get_value_for_entry amount_label (function
| UintLit (Uint128L i) -> (
Expand Down Expand Up @@ -142,13 +150,19 @@ module ScillaContractUtil (SR : Rep) (ER : Rep) = struct
ER.address_rep,
bystrx_typ address_length )
in
let origin =
( CUIdentifier.mk_id
(label_name_of_string MessagePayload.origin_label)
ER.address_rep,
bystrx_typ address_length )
in
let amount =
( CUIdentifier.mk_id
(label_name_of_string MessagePayload.amount_label)
ER.uint128_rep,
uint128_typ )
in
amount :: sender :: cparams
amount :: origin :: sender :: cparams

let msg_mandatory_field_types =
[
Expand Down
2 changes: 2 additions & 0 deletions src/base/GasUseAnalysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,8 @@ struct
let si a t = mk_typed_id a t in
let all_params =
[
( si ContractUtil.MessagePayload.origin_label (bystrx_typ 20),
bystrx_typ 20 );
( si ContractUtil.MessagePayload.sender_label (bystrx_typ 20),
bystrx_typ 20 );
(si ContractUtil.MessagePayload.amount_label uint128_typ, uint128_typ);
Expand Down
7 changes: 6 additions & 1 deletion src/base/JSON.ml
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ module Message = struct
let tags = member_exn tag_label json |> to_string_exn in
let amounts = member_exn amount_label json |> to_string_exn in
let senders = member_exn sender_label json |> to_string_exn in
let origins = member_exn origin_label json |> to_string_exn in
(* Make tag, amount and sender into a literal *)
let tag = (tag_label, build_prim_lit_exn JSONType.string_typ tags) in
let amount =
Expand All @@ -393,9 +394,13 @@ module Message = struct
( sender_label,
build_prim_lit_exn (JSONType.bystrx_typ address_length) senders )
in
let origin =
( origin_label,
build_prim_lit_exn (JSONType.bystrx_typ address_length) origins )
in
let pjlist = member_exn "params" json |> to_list_exn in
let params = List.map pjlist ~f:jobj_to_statevar in
tag :: amount :: sender :: params
tag :: amount :: origin :: sender :: params

(* Same as message_to_jstring, but instead gives out raw json, not it's string *)
let message_to_json message =
Expand Down
4 changes: 3 additions & 1 deletion src/base/SanityChecker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ struct
match
List.find c.comp_params ~f:(fun (s, _) ->
String.(
as_string s = amount_label || as_string s = sender_label))
as_string s = amount_label
|| as_string s = sender_label
|| as_string s = origin_label))
with
| Some (s, _) ->
e
Expand Down
8 changes: 6 additions & 2 deletions src/eval/Eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -445,19 +445,23 @@ let rec stmt_eval conf stmts =
and try_apply_as_procedure conf proc proc_rest actuals =
(* Create configuration for procedure call *)
let sender = GlobalName.parse_simple_name MessagePayload.sender_label in
let origin = GlobalName.parse_simple_name MessagePayload.origin_label in
let amount = GlobalName.parse_simple_name MessagePayload.amount_label in
let%bind sender_value =
fromR @@ Configuration.lookup conf (mk_loc_id sender)
in
let%bind origin_value =
fromR @@ Configuration.lookup conf (mk_loc_id origin)
in
let%bind amount_value =
fromR @@ Configuration.lookup conf (mk_loc_id amount)
in
let%bind proc_conf =
Configuration.bind_all
{ conf with env = conf.init_env; procedures = proc_rest }
( sender :: amount
( origin :: sender :: amount
:: List.map proc.comp_params ~f:(fun id_typ -> get_id (fst id_typ)) )
(sender_value :: amount_value :: actuals)
(origin_value :: sender_value :: amount_value :: actuals)
in
let%bind conf' = stmt_eval proc_conf proc.comp_body in
(* Reset configuration *)
Expand Down
11 changes: 6 additions & 5 deletions tests/runner/UintParam/message_1.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"_tag": "Uint128Test",
"_amount": "-1",
"_sender" : "0x12345678901234567890123456789012345678ab",
"_sender": "0x12345678901234567890123456789012345678ab",
"params": [
{
"vname" : "x",
"type" : "Uint128",
"value" : "0"
"vname": "x",
"type": "Uint128",
"value": "0"
}
]
],
"_origin": "0x12345678901234567890123456789012345678ab"
}
11 changes: 6 additions & 5 deletions tests/runner/UintParam/message_2.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"_tag": "Uint128Test",
"_amount": "0",
"_sender" : "0x12345678901234567890123456789012345678ab",
"_sender": "0x12345678901234567890123456789012345678ab",
"params": [
{
"vname" : "x",
"type" : "Uint128",
"value" : "-1"
"vname": "x",
"type": "Uint128",
"value": "-1"
}
]
],
"_origin": "0x12345678901234567890123456789012345678ab"
}
11 changes: 6 additions & 5 deletions tests/runner/UintParam/message_3.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"_tag": "Uint256Test",
"_amount": "0",
"_sender" : "0x12345678901234567890123456789012345678ab",
"_sender": "0x12345678901234567890123456789012345678ab",
"params": [
{
"vname" : "x",
"type" : "Uint256",
"value" : "-1"
"vname": "x",
"type": "Uint256",
"value": "-1"
}
]
],
"_origin": "0x12345678901234567890123456789012345678ab"
}
2 changes: 1 addition & 1 deletion tests/runner/UintParam/output_1.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"gas_remaining": "7969",
"gas_remaining": "7962",
"errors": [
{
"error_message": "Invalid Uint128 value -1 in JSON",
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/UintParam/output_2.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"gas_remaining": "7969",
"gas_remaining": "7962",
"errors": [
{
"error_message": "Invalid Uint128 value -1 in JSON",
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/UintParam/output_3.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"gas_remaining": "7969",
"gas_remaining": "7962",
"errors": [
{
"error_message": "Invalid Uint256 value -1 in JSON",
Expand Down
5 changes: 3 additions & 2 deletions tests/runner/auction/message_1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"_tag": "Bid",
"_amount": "100",
"_sender" : "0x12345678901234567890123456789012345678ab",
"params": []
"_sender": "0x12345678901234567890123456789012345678ab",
"params": [],
"_origin": "0x12345678901234567890123456789012345678ab"
}
5 changes: 3 additions & 2 deletions tests/runner/auction/message_2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"_tag": "Bid",
"_amount": "200",
"_sender" : "0x12345678901234567890123456789012345678ab",
"params": []
"_sender": "0x12345678901234567890123456789012345678ab",
"params": [],
"_origin": "0x12345678901234567890123456789012345678ab"
}
5 changes: 3 additions & 2 deletions tests/runner/auction/message_3.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"_tag": "Bid",
"_amount": "50",
"_sender" : "0x12345678901234567890123456789012345678cd",
"params": []
"_sender": "0x12345678901234567890123456789012345678cd",
"params": [],
"_origin": "0x12345678901234567890123456789012345678cd"
}
5 changes: 3 additions & 2 deletions tests/runner/auction/message_4.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"_tag": "Bid",
"_amount": "500",
"_sender" : "0x12345678901234567890123456789012345678cd",
"params": []
"_sender": "0x12345678901234567890123456789012345678cd",
"params": [],
"_origin": "0x12345678901234567890123456789012345678cd"
}
5 changes: 3 additions & 2 deletions tests/runner/auction/message_5.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"_tag": "Bid",
"_amount": "500",
"_sender" : "0x12345678901234567890123456789012345678cd",
"params": []
"_sender": "0x12345678901234567890123456789012345678cd",
"params": [],
"_origin": "0x12345678901234567890123456789012345678cd"
}
5 changes: 3 additions & 2 deletions tests/runner/auction/message_6.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"_tag": "Withdraw",
"_amount": "0",
"_sender" : "0x12345678901234567890123456789012345678ab",
"params": []
"_sender": "0x12345678901234567890123456789012345678ab",
"params": [],
"_origin": "0x12345678901234567890123456789012345678ab"
}
5 changes: 3 additions & 2 deletions tests/runner/auction/message_7.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"_tag": "AuctionEnd",
"_amount": "0",
"_sender" : "0x12345678901234567890123456789012345678ab",
"params": []
"_sender": "0x12345678901234567890123456789012345678ab",
"params": [],
"_origin": "0x12345678901234567890123456789012345678ab"
}
5 changes: 3 additions & 2 deletions tests/runner/auction/message_8.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"_tag": "AuctionEnd",
"_amount": "0",
"_sender" : "0x12345678901234567890123456789012345678ab",
"params": []
"_sender": "0x12345678901234567890123456789012345678ab",
"params": [],
"_origin": "0x12345678901234567890123456789012345678ab"
}
2 changes: 1 addition & 1 deletion tests/runner/auction/output_1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7923",
"gas_remaining": "7915",
"_accepted": "true",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/auction/output_2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7917",
"gas_remaining": "7910",
"_accepted": "true",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/auction/output_3.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7927",
"gas_remaining": "7920",
"_accepted": "false",
"messages": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/auction/output_4.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7930",
"gas_remaining": "7923",
"_accepted": "false",
"messages": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/auction/output_5.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7931",
"gas_remaining": "7923",
"_accepted": "false",
"messages": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/auction/output_6.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7943",
"gas_remaining": "7936",
"_accepted": "false",
"messages": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/auction/output_7.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7943",
"gas_remaining": "7936",
"_accepted": "false",
"messages": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/auction/output_8.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7926",
"gas_remaining": "7919",
"_accepted": "false",
"messages": [
{
Expand Down
5 changes: 3 additions & 2 deletions tests/runner/bookstore/message_1.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"_tag": "AddMember",
"_amount": "0",
"_sender" : "0x1234567890123456789012345678901234567890",
"_sender": "0x1234567890123456789012345678901234567890",
"params": [
{
"vname": "member_address",
Expand All @@ -18,5 +18,6 @@
"type": "Uint32",
"value": "2"
}
]
],
"_origin": "0x1234567890123456789012345678901234567890"
}
5 changes: 3 additions & 2 deletions tests/runner/bookstore/message_10.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"_tag": "AddBook",
"_amount": "0",
"_sender" : "0x1234567890123456789012345678901234567890",
"_sender": "0x1234567890123456789012345678901234567890",
"params": [
{
"vname": "book_title",
Expand All @@ -18,5 +18,6 @@
"type": "Uint32",
"value": "2"
}
]
],
"_origin": "0x1234567890123456789012345678901234567890"
}
Loading