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

Remove gas charges related to source file and input JSONs #1036

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion src/base/JSON.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ let build_prim_lit_exn t v =
mk_invalid_json ("Invalid " ^ pp_typ t ^ " value " ^ v ^ " in JSON")
in
let build_prim_literal_of_type t v =
match build_prim_literal t v with Some v' -> v' | None -> raise (exn ())
try
match build_prim_literal t v with Some v' -> v' | None -> raise (exn ())
with Invalid_argument _ -> raise (exn ())
in
match t with
| PrimType pt -> build_prim_literal_of_type pt v
Expand Down
31 changes: 1 addition & 30 deletions src/eval/Runner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -368,36 +368,7 @@ let run_with_args args =
FilePath.check_extension args.input
GlobalConfig.StdlibTracker.file_extn_library
in
let initial_gas_limit = Uint64.mul args.gas_limit Gas.scale_factor in
let gas_remaining =
(* Subtract gas based on (contract+init) size / message size. *)
if is_deployment then
let cost' =
UnixLabels.((stat args.input).st_size + (stat args.input_init).st_size)
in
let cost = Uint64.of_int cost' in
if Uint64.compare initial_gas_limit cost < 0 then
fatal_error_gas_scale Gas.scale_factor
(mk_error0
(sprintf "Ran out of gas when parsing contract/init files.\n"))
Uint64.zero
else Uint64.sub initial_gas_limit cost
else
let cost = Uint64.of_int (UnixLabels.stat args.input_message).st_size in
(* libraries can only be deployed, not "run". *)
if is_library then
fatal_error_gas_scale Gas.scale_factor
(mk_error0
(sprintf
"Cannot run a library contract. They can only be deployed\n"))
Uint64.zero
else if Uint64.compare initial_gas_limit cost < 0 then
fatal_error_gas_scale Gas.scale_factor
(mk_error0 (sprintf "Ran out of gas when parsing message.\n"))
Uint64.zero
else Uint64.sub initial_gas_limit cost
in

let gas_remaining = Uint64.mul args.gas_limit Gas.scale_factor in
if is_library then deploy_library args gas_remaining
else
match FEParser.parse_cmodule args.input with
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "gas_remaining": "7825" }
{ "gas_remaining": "7995" }
2 changes: 1 addition & 1 deletion tests/runner/Polynetwork/output_1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "2984",
"gas_remaining": "3681",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/Polynetwork/output_2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "4621",
"gas_remaining": "5212",
"_accepted": "false",
"messages": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/Polynetwork/output_25.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"gas_remaining": "7198",
"gas_remaining": "7895",
"errors": [
{
"error_message":
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/Polynetwork/output_26.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"gas_remaining": "4685",
"gas_remaining": "5276",
"errors": [
{
"error_message":
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/Polynetwork/output_27.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"gas_remaining": "3642",
"gas_remaining": "4613",
"errors": [
{
"error_message":
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/Polynetwork/output_28.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"gas_remaining": "2318",
"gas_remaining": "3793",
"errors": [
{
"error_message":
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/Polynetwork/output_3.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "1843",
"gas_remaining": "2813",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/Polynetwork/output_4.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "2254",
"gas_remaining": "3730",
"_accepted": "false",
"messages": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/TestLib2/init_output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "gas_remaining": "7881" }
{ "gas_remaining": "7993" }
2 changes: 1 addition & 1 deletion tests/runner/TestLib2/init_wrong_version_output.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"gas_remaining": "7869",
"gas_remaining": "7981",
"errors": [
{
"error_message": "Scilla version mismatch\n",
Expand Down
2 changes: 2 additions & 0 deletions tests/runner/Testcontracts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ let build_misc_tests env =
[
"-init";
tests_dir_file env.tests_dir test_ctxt ("init_bad" ^ snum ^. "json");
"-gaslimit";
testsuit_gas_limit;
jjcnn marked this conversation as resolved.
Show resolved Hide resolved
"-libdir";
"src" ^/ "stdlib";
"-jsonerrors";
Expand Down
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": "7962",
"gas_remaining": "7999",
"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": "7962",
"gas_remaining": "7999",
"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": "7962",
"gas_remaining": "7999",
"errors": [
{
"error_message": "Invalid Uint256 value -1 in JSON",
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/addfunds/output_1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7944",
"gas_remaining": "7988",
"_accepted": "true",
"messages": [],
"states": [ { "vname": "_balance", "type": "Uint128", "value": "100" } ],
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/addfunds_proxy/output_1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7951",
"gas_remaining": "7975",
"_accepted": "true",
"messages": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/addfunds_proxy/output_2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7958",
"gas_remaining": "7983",
"_accepted": "true",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_eq_test/output_1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7930",
"gas_remaining": "7992",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_eq_test/output_10.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7943",
"gas_remaining": "7986",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_eq_test/output_11.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7935",
"gas_remaining": "7977",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_eq_test/output_2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7930",
"gas_remaining": "7992",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_eq_test/output_3.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7931",
"gas_remaining": "7993",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_eq_test/output_4.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7931",
"gas_remaining": "7992",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_eq_test/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": "7992",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_eq_test/output_6.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7948",
"gas_remaining": "7990",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_eq_test/output_7.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7945",
"gas_remaining": "7987",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_eq_test/output_8.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7923",
"gas_remaining": "7985",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_eq_test/output_9.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7918",
"gas_remaining": "7980",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"gas_remaining": "7867",
"gas_remaining": "7999",
"errors": [
{
"error_message": "Address type not allowed in json file",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"gas_remaining": "7877",
"gas_remaining": "7999",
"errors": [
{
"error_message": "Address type not allowed in json file",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"gas_remaining": "7880",
"gas_remaining": "7998",
"errors": [
{
"error_message":
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_list_as_cparam/init_ipc_output.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "63044",
"gas_remaining": "63988",
"_accepted": "false",
"messages": null,
"states": [ { "vname": "_balance", "type": "Uint128", "value": "0" } ],
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_list_traversal/output_1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7896",
"gas_remaining": "7977",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_list_traversal/output_2.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7901",
"gas_remaining": "7981",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/address_list_traversal/output_3.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7891",
"gas_remaining": "7972",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
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": "7915",
"gas_remaining": "7938",
"_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": "7910",
"gas_remaining": "7933",
"_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": "7920",
"gas_remaining": "7943",
"_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": "7923",
"gas_remaining": "7946",
"_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": "7923",
"gas_remaining": "7946",
"_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": "7936",
"gas_remaining": "7959",
"_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": "7936",
"gas_remaining": "7959",
"_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": "7919",
"gas_remaining": "7943",
"_accepted": "false",
"messages": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/runner/bookstore/output_1.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scilla_major_version": "0",
"gas_remaining": "7904",
"gas_remaining": "7975",
"_accepted": "false",
"messages": [],
"states": [
Expand Down
Loading