From 5c08bec5e47854261c8823c3493e11bdf12b1f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Tue, 11 Oct 2022 22:02:58 +0200 Subject: [PATCH 1/3] Proto/Michelson/Gas: give a positive cost to the BALANCE instruction --- src/proto_alpha/lib_protocol/michelson_v1_gas.ml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_protocol/michelson_v1_gas.ml b/src/proto_alpha/lib_protocol/michelson_v1_gas.ml index e0e406b87e2c..38b80c962ea5 100644 --- a/src/proto_alpha/lib_protocol/michelson_v1_gas.ml +++ b/src/proto_alpha/lib_protocol/michelson_v1_gas.ml @@ -123,6 +123,9 @@ module Cost_of = struct let cost_N_IApply rec_flag = if rec_flag then S.safe_int 220 else S.safe_int 140 + (* model N_IBalance *) + let cost_N_IBalance = S.safe_int 10 + (* model N_IBlake2b *) (* Approximating 1.120804 x term *) let cost_N_IBlake2b size = @@ -1306,6 +1309,8 @@ module Cost_of = struct let amount = atomic_step_cost cost_N_IAmount + let balance = atomic_step_cost cost_N_IBalance + let chain_id = atomic_step_cost cost_N_IChainId let ticket = atomic_step_cost cost_N_ITicket @@ -1572,9 +1577,6 @@ module Cost_of = struct let concat_bytes total_bytes = atomic_step_cost S.(add (S.safe_int 100) (S.shift_right total_bytes 1)) - (* Cost of access taken care of in Contract_storage.get_balance_carbonated *) - let balance = Gas.free - (* Cost of Unpack pays two integer comparisons, and a Bytes slice *) let unpack bytes = let blen = Bytes.length bytes in -- GitLab From 749094e54cd9424cc932304a81ae0b0afac25f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Tue, 11 Oct 2022 22:24:49 +0200 Subject: [PATCH 2/3] Tests/Python: regenerate regression traces --- ...xe009ab79e8b84ef0e55c43a9a857214d8761e67b.7da5c9014e.out | 4 ++-- ...tract_opcodes.TestContractOpcodes::test_balance[0.5].out | 6 +++--- ...ontract_opcodes.TestContractOpcodes::test_balance[0].out | 6 +++--- ...ract_opcodes.TestContractOpcodes::test_balance[1000].out | 6 +++--- ...ontract_opcodes.TestContractOpcodes::test_balance[1].out | 6 +++--- ...act_opcodes.TestContractOpcodes::test_balance[1e-06].out | 6 +++--- ...ontract_opcodes.TestContractOpcodes::test_balance[5].out | 6 +++--- ...s.TestContractOpcodes::test_balance[8000000000000.0].out | 6 +++--- ...ract_input_output[balance.tz-111-Unit-4000000000000].out | 6 +++--- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_slice_success[(Pair 0xe009ab79e8b84ef0e55c43a9a857214d8761e67b.7da5c9014e.out b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_slice_success[(Pair 0xe009ab79e8b84ef0e55c43a9a857214d8761e67b.7da5c9014e.out index d73e376618a7..b9df79fcf233 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_slice_success[(Pair 0xe009ab79e8b84ef0e55c43a9a857214d8761e67b.7da5c9014e.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_onchain_opcodes.TestContractOnchainOpcodes::test_slice_success[(Pair 0xe009ab79e8b84ef0e55c43a9a857214d8761e67b.7da5c9014e.out @@ -1,7 +1,7 @@ tests_alpha/test_contract_onchain_opcodes.py::TestContractOnchainOpcodes::test_slice_success[(Pair 0xe009ab79e8b84ef0e55c43a9a857214d8761e67b75ba63500a5694fb2ffe174acc2de22d01ccb7259342437f05e1987949f0ad82e9f32e9a0b79cb252d7f7b8236ad728893f4e7150742eefdbeda254970f9fcd92c6228c178e1a923e5600758eb83f2a05edd0be7625657901f2ba81eaf145d003dbef78e33f43a32a3788bdf0501000000085341554349535345 "spsig1PPUFZucuAQybs5wsqsNQ68QNgFaBnVKMFaoZZfi1BtNnuCAWnmL9wVy5HfHkR6AeodjVGxpBVVSYcJKyMURn6K1yknYLm")] Node is bootstrapped. -Estimated gas: 3595.324 units (will add 100 for safety) +Estimated gas: 3595.334 units (will add 100 for safety) Estimated storage: 257 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -29,7 +29,7 @@ This sequence of operations was run: Updated storage: [OPERATION_HASH]48f709699019725ba Storage size: 578 bytes - Consumed gas: 2595.324 + Consumed gas: 2595.334 Internal operations: Internal Transaction: Amount: ꜩ1000 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[0.5].out b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[0.5].out index a9ccd828c40f..eec483839a4b 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[0.5].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[0.5].out @@ -11,11 +11,11 @@ trace [ (Pair Unit 0) ] - location: 7 (remaining gas: 1039995.723 units remaining) [ ] - - location: 8 (remaining gas: 1039995.723 units remaining) + - location: 8 (remaining gas: 1039995.713 units remaining) [ 500000 ] - - location: 9 (remaining gas: 1039995.713 units remaining) + - location: 9 (remaining gas: 1039995.703 units remaining) [ {} 500000 ] - - location: 11 (remaining gas: 1039995.703 units remaining) + - location: 11 (remaining gas: 1039995.693 units remaining) [ (Pair {} 500000) ] diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[0].out b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[0].out index c13fa69bb55c..8c7c4dbe4ee1 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[0].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[0].out @@ -11,11 +11,11 @@ trace [ (Pair Unit 0) ] - location: 7 (remaining gas: 1039995.723 units remaining) [ ] - - location: 8 (remaining gas: 1039995.723 units remaining) + - location: 8 (remaining gas: 1039995.713 units remaining) [ 0 ] - - location: 9 (remaining gas: 1039995.713 units remaining) + - location: 9 (remaining gas: 1039995.703 units remaining) [ {} 0 ] - - location: 11 (remaining gas: 1039995.703 units remaining) + - location: 11 (remaining gas: 1039995.693 units remaining) [ (Pair {} 0) ] diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[1000].out b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[1000].out index bf614c2e684f..f7edacace175 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[1000].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[1000].out @@ -11,11 +11,11 @@ trace [ (Pair Unit 0) ] - location: 7 (remaining gas: 1039995.723 units remaining) [ ] - - location: 8 (remaining gas: 1039995.723 units remaining) + - location: 8 (remaining gas: 1039995.713 units remaining) [ 1000000000 ] - - location: 9 (remaining gas: 1039995.713 units remaining) + - location: 9 (remaining gas: 1039995.703 units remaining) [ {} 1000000000 ] - - location: 11 (remaining gas: 1039995.703 units remaining) + - location: 11 (remaining gas: 1039995.693 units remaining) [ (Pair {} 1000000000) ] diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[1].out b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[1].out index 792094d124c4..3b4aaad003c2 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[1].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[1].out @@ -11,11 +11,11 @@ trace [ (Pair Unit 0) ] - location: 7 (remaining gas: 1039995.723 units remaining) [ ] - - location: 8 (remaining gas: 1039995.723 units remaining) + - location: 8 (remaining gas: 1039995.713 units remaining) [ 1000000 ] - - location: 9 (remaining gas: 1039995.713 units remaining) + - location: 9 (remaining gas: 1039995.703 units remaining) [ {} 1000000 ] - - location: 11 (remaining gas: 1039995.703 units remaining) + - location: 11 (remaining gas: 1039995.693 units remaining) [ (Pair {} 1000000) ] diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[1e-06].out b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[1e-06].out index a5cb9f25da08..cf11c25ce395 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[1e-06].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[1e-06].out @@ -11,11 +11,11 @@ trace [ (Pair Unit 0) ] - location: 7 (remaining gas: 1039995.723 units remaining) [ ] - - location: 8 (remaining gas: 1039995.723 units remaining) + - location: 8 (remaining gas: 1039995.713 units remaining) [ 1 ] - - location: 9 (remaining gas: 1039995.713 units remaining) + - location: 9 (remaining gas: 1039995.703 units remaining) [ {} 1 ] - - location: 11 (remaining gas: 1039995.703 units remaining) + - location: 11 (remaining gas: 1039995.693 units remaining) [ (Pair {} 1) ] diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[5].out b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[5].out index a5896a8463be..ed4d948ccaec 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[5].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[5].out @@ -11,11 +11,11 @@ trace [ (Pair Unit 0) ] - location: 7 (remaining gas: 1039995.723 units remaining) [ ] - - location: 8 (remaining gas: 1039995.723 units remaining) + - location: 8 (remaining gas: 1039995.713 units remaining) [ 5000000 ] - - location: 9 (remaining gas: 1039995.713 units remaining) + - location: 9 (remaining gas: 1039995.703 units remaining) [ {} 5000000 ] - - location: 11 (remaining gas: 1039995.703 units remaining) + - location: 11 (remaining gas: 1039995.693 units remaining) [ (Pair {} 5000000) ] diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[8000000000000.0].out b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[8000000000000.0].out index 472399fd5d5c..1ce6d7a299a1 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[8000000000000.0].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_balance[8000000000000.0].out @@ -11,11 +11,11 @@ trace [ (Pair Unit 0) ] - location: 7 (remaining gas: 1039995.723 units remaining) [ ] - - location: 8 (remaining gas: 1039995.723 units remaining) + - location: 8 (remaining gas: 1039995.713 units remaining) [ 8000000000000000000 ] - - location: 9 (remaining gas: 1039995.713 units remaining) + - location: 9 (remaining gas: 1039995.703 units remaining) [ {} 8000000000000000000 ] - - location: 11 (remaining gas: 1039995.703 units remaining) + - location: 11 (remaining gas: 1039995.693 units remaining) [ (Pair {} 8000000000000000000) ] diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[balance.tz-111-Unit-4000000000000].out b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[balance.tz-111-Unit-4000000000000].out index 3dcff5104715..c3fff51cb699 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[balance.tz-111-Unit-4000000000000].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract_opcodes.TestContractOpcodes::test_contract_input_output[balance.tz-111-Unit-4000000000000].out @@ -11,11 +11,11 @@ trace [ (Pair Unit 111) ] - location: 7 (remaining gas: 1039995.723 units remaining) [ ] - - location: 8 (remaining gas: 1039995.723 units remaining) + - location: 8 (remaining gas: 1039995.713 units remaining) [ 4000000000000 ] - - location: 9 (remaining gas: 1039995.713 units remaining) + - location: 9 (remaining gas: 1039995.703 units remaining) [ {} 4000000000000 ] - - location: 11 (remaining gas: 1039995.703 units remaining) + - location: 11 (remaining gas: 1039995.693 units remaining) [ (Pair {} 4000000000000) ] -- GitLab From 76b94a81410b52bc11980226164f892d5b4705c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Cauderlier?= Date: Wed, 12 Oct 2022 13:54:06 +0200 Subject: [PATCH 3/3] Tests/Tezt: reset regression traces --- .../self_address_transfer.ml/Alpha- Self address transfer.out | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tezt/tests/expected/self_address_transfer.ml/Alpha- Self address transfer.out b/tezt/tests/expected/self_address_transfer.ml/Alpha- Self address transfer.out index 4fb824805e83..65eb8c2a3411 100644 --- a/tezt/tests/expected/self_address_transfer.ml/Alpha- Self address transfer.out +++ b/tezt/tests/expected/self_address_transfer.ml/Alpha- Self address transfer.out @@ -101,7 +101,7 @@ Contract memorized as self_address_receiver.tz. ./octez-client --mode mockup --wait none transfer 0 from bootstrap2 to '[CONTRACT_HASH]' --burn-cap 2 --arg '"[CONTRACT_HASH]"' Node is bootstrapped. -Estimated gas: 4691.615 units (will add 100 for safety) +Estimated gas: 4691.625 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[OPERATION_HASH]' @@ -127,7 +127,7 @@ This sequence of operations was run: This transaction was successfully applied Updated storage: Unit Storage size: 82 bytes - Consumed gas: 2575.775 + Consumed gas: 2575.785 Internal operations: Internal Transaction: Amount: ꜩ0 -- GitLab