From 7db25aff6bfd1740d730810f8834cfa65514d47c Mon Sep 17 00:00:00 2001 From: Imnik11 Date: Thu, 3 Feb 2022 13:47:10 +0530 Subject: [PATCH 01/20] Added derive_address fn a/p ARCH specs --- lib/archethic/crypto.ex | 29 +++++++++++++++++++++++++++++ lib/archethic/crypto/id.ex | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/lib/archethic/crypto.ex b/lib/archethic/crypto.ex index 86c93e891..cb1472fcc 100755 --- a/lib/archethic/crypto.ex +++ b/lib/archethic/crypto.ex @@ -68,6 +68,13 @@ defmodule ArchEthic.Crypto do """ @type versioned_hash :: <<_::8, _::_*8>> + @typedoc """ + Binary representing a hash prepend by two bytes + - first byte to identify the curve type + - second byte to identify hash algorithm of the generated hash + """ + @type prepended_hash :: <<_::16, _::_*8>> + @typedoc """ Binary representing a key prepend by two bytes: - to identify the elliptic curve for a key @@ -899,6 +906,28 @@ defmodule ArchEthic.Crypto do defp do_hash(data, :sha3_512), do: :crypto.hash(:sha3_512, data) defp do_hash(data, :blake2b), do: :crypto.hash(:blake2b, data) + @doc """ + Generate an address as per ARCHEthic specification + + The fist-byte representing the curve type second-byte representing hash algorithm used and rest is the hash of publicKey as per ARCHEthic specifications . + + ## Examples + + iex> Crypto.derive_address(<<0, 0, 157, 113, 213, 254, 97, 210, 136, 32, 204, 38, 221, 110, 231, 27, 163, 73, 150, 202, 185, 91, 170, 254, 165, 166, 45, 60, 50, 23, 27, 157, 72, 46>>) + <<0, 0, 237, 169, 64, 209, 51, 194, 0, 226, 46, 145, 26, 40, 146, 74, 122, 110, 128, 42, 139, 127, 93, 18, 43, 122, 169, 201, 243, 117, 73, 18, 230, 168>> + + iex> Crypto.derive_address(<<1, 0, 4, 248, 44, 107, 181, 219, 4, 20, 188, 213, 46, 31, 29, 116, 140, 39, 108, 242, 117, 190, 25, 128, 173, 250, 36, 119, 76, 23, 39, 168, 210, 107, 180, 174, 216, 221, 151, 80, 232, 26, 8, 236, 107, 115, 135, 147, 42, 38, 86, 78, 197, 95, 163, 64, 214, 91, 47, 62, 99, 103, 63, 150, 41, 25, 39>>, :blake2b) + <<1, 4, 26, 243, 32, 71, 95, 147, 6, 64, 254, 170, 221, 155, 83, 216, 75, 147, 255, 23, 33, 219, 222, 211, 162, 67, 100, 63, 75, 101, 183, 247, 158, 80, 169, 78, 112, 131, 176, 191, 40, 87, 45, 96, 181, 185, 74, 55, 85, 138, 240, 110, 164, 165, 219, 183, 138, 173, 188, 124, 125, 216, 194, 106, 186, 204>> + """ + @spec derive_address(publicKey :: key(), algo :: supported_hash()) :: prepended_hash() + def derive_address(publicKey, algo \\ Application.get_env(:archethic, ArchEthic.Crypto)[:default_hash]) do + <> = publicKey + + publicKey + |>hash(algo) + |>ID.prepend_curve(curve_type) + end + @doc """ Hash the data using the storage nonce stored in memory """ diff --git a/lib/archethic/crypto/id.ex b/lib/archethic/crypto/id.ex index 6b1e11739..8f183acd4 100755 --- a/lib/archethic/crypto/id.ex +++ b/lib/archethic/crypto/id.ex @@ -90,6 +90,10 @@ defmodule ArchEthic.Crypto.ID do <> end + @spec prepend_curve(Crypto.versioned_hash(), binary()) :: Crypto.prepended_hash() + def prepend_curve(hash, curve_type) do + <> + end @doc """ Prepend each keys by the identifying curve and the origin From ff5c7367f75c946b1e41d6b2bd38f07dcdf43959 Mon Sep 17 00:00:00 2001 From: Imnik11 Date: Thu, 3 Feb 2022 13:47:48 +0530 Subject: [PATCH 02/20] Fix formatting --- lib/archethic/crypto.ex | 9 ++++++--- lib/archethic/crypto/id.ex | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/archethic/crypto.ex b/lib/archethic/crypto.ex index cb1472fcc..28c21b57d 100755 --- a/lib/archethic/crypto.ex +++ b/lib/archethic/crypto.ex @@ -920,12 +920,15 @@ defmodule ArchEthic.Crypto do <<1, 4, 26, 243, 32, 71, 95, 147, 6, 64, 254, 170, 221, 155, 83, 216, 75, 147, 255, 23, 33, 219, 222, 211, 162, 67, 100, 63, 75, 101, 183, 247, 158, 80, 169, 78, 112, 131, 176, 191, 40, 87, 45, 96, 181, 185, 74, 55, 85, 138, 240, 110, 164, 165, 219, 183, 138, 173, 188, 124, 125, 216, 194, 106, 186, 204>> """ @spec derive_address(publicKey :: key(), algo :: supported_hash()) :: prepended_hash() - def derive_address(publicKey, algo \\ Application.get_env(:archethic, ArchEthic.Crypto)[:default_hash]) do + def derive_address( + publicKey, + algo \\ Application.get_env(:archethic, ArchEthic.Crypto)[:default_hash] + ) do <> = publicKey publicKey - |>hash(algo) - |>ID.prepend_curve(curve_type) + |> hash(algo) + |> ID.prepend_curve(curve_type) end @doc """ diff --git a/lib/archethic/crypto/id.ex b/lib/archethic/crypto/id.ex index 8f183acd4..6c276cdf8 100755 --- a/lib/archethic/crypto/id.ex +++ b/lib/archethic/crypto/id.ex @@ -94,6 +94,7 @@ defmodule ArchEthic.Crypto.ID do def prepend_curve(hash, curve_type) do <> end + @doc """ Prepend each keys by the identifying curve and the origin From 87b6a5cf1e8f0f3af087ab213fcb7448c575ea7d Mon Sep 17 00:00:00 2001 From: Imnik11 Date: Thu, 3 Feb 2022 14:00:00 +0530 Subject: [PATCH 03/20] Fix credo --- lib/archethic/crypto.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/archethic/crypto.ex b/lib/archethic/crypto.ex index 28c21b57d..cbb15ac05 100755 --- a/lib/archethic/crypto.ex +++ b/lib/archethic/crypto.ex @@ -919,14 +919,14 @@ defmodule ArchEthic.Crypto do iex> Crypto.derive_address(<<1, 0, 4, 248, 44, 107, 181, 219, 4, 20, 188, 213, 46, 31, 29, 116, 140, 39, 108, 242, 117, 190, 25, 128, 173, 250, 36, 119, 76, 23, 39, 168, 210, 107, 180, 174, 216, 221, 151, 80, 232, 26, 8, 236, 107, 115, 135, 147, 42, 38, 86, 78, 197, 95, 163, 64, 214, 91, 47, 62, 99, 103, 63, 150, 41, 25, 39>>, :blake2b) <<1, 4, 26, 243, 32, 71, 95, 147, 6, 64, 254, 170, 221, 155, 83, 216, 75, 147, 255, 23, 33, 219, 222, 211, 162, 67, 100, 63, 75, 101, 183, 247, 158, 80, 169, 78, 112, 131, 176, 191, 40, 87, 45, 96, 181, 185, 74, 55, 85, 138, 240, 110, 164, 165, 219, 183, 138, 173, 188, 124, 125, 216, 194, 106, 186, 204>> """ - @spec derive_address(publicKey :: key(), algo :: supported_hash()) :: prepended_hash() + @spec derive_address(public_key :: key(), algo :: supported_hash()) :: prepended_hash() def derive_address( - publicKey, + public_key, algo \\ Application.get_env(:archethic, ArchEthic.Crypto)[:default_hash] ) do - <> = publicKey + <> = public_key - publicKey + public_key |> hash(algo) |> ID.prepend_curve(curve_type) end From c5b09ddfef597e3831d891a22c438d4e03364d12 Mon Sep 17 00:00:00 2001 From: Imnik11 Date: Mon, 14 Feb 2022 12:25:28 +0530 Subject: [PATCH 04/20] Replacing hash with derive_address fn --- lib/archethic/account/mem_tables_loader.ex | 2 +- lib/archethic/beacon_chain.ex | 2 +- lib/archethic/bootstrap.ex | 8 +-- lib/archethic/crypto.ex | 15 +++++ lib/archethic/election.ex | 8 +-- .../mining/pending_transaction_validation.ex | 2 +- lib/archethic/p2p.ex | 6 +- lib/archethic/release_task.ex | 66 +++++++++---------- .../transaction_handler.ex | 2 +- lib/archethic/shared_secrets/node_renewal.ex | 4 +- .../transaction_chain/transaction.ex | 8 +-- .../regression/benchmarks/p2p_message.ex | 2 +- lib/archethic/utils/regression/playbook.ex | 4 +- .../regression/playbooks/smart_contract.ex | 2 +- .../utils/regression/playbooks/uco.ex | 2 +- .../controllers/faucet_controller.ex | 2 +- 16 files changed, 75 insertions(+), 60 deletions(-) diff --git a/lib/archethic/account/mem_tables_loader.ex b/lib/archethic/account/mem_tables_loader.ex index e3bc4d2f6..fdae6d8f2 100644 --- a/lib/archethic/account/mem_tables_loader.ex +++ b/lib/archethic/account/mem_tables_loader.ex @@ -73,7 +73,7 @@ defmodule ArchEthic.Account.MemTablesLoader do } } }) do - previous_address = Crypto.hash(previous_public_key) + previous_address = Crypto.derive_address(previous_public_key) UCOLedger.spend_all_unspent_outputs(previous_address) NFTLedger.spend_all_unspent_outputs(previous_address) diff --git a/lib/archethic/beacon_chain.ex b/lib/archethic/beacon_chain.ex index 741e20a93..1ad0fe717 100644 --- a/lib/archethic/beacon_chain.ex +++ b/lib/archethic/beacon_chain.ex @@ -174,7 +174,7 @@ defmodule ArchEthic.BeaconChain do Crypto.hash([subset, <>]) ) - Crypto.hash(pub) + Crypto.derive_address(pub) end @doc """ diff --git a/lib/archethic/bootstrap.ex b/lib/archethic/bootstrap.ex index 3f0c211a3..0d640307e 100644 --- a/lib/archethic/bootstrap.ex +++ b/lib/archethic/bootstrap.ex @@ -32,10 +32,10 @@ defmodule ArchEthic.Bootstrap do reward_address = case Keyword.get(args, :reward_address) do nil -> - Crypto.hash(Crypto.first_node_public_key()) + Crypto.derive_address(Crypto.first_node_public_key()) "" -> - Crypto.hash(Crypto.first_node_public_key()) + Crypto.derive_address(Crypto.first_node_public_key()) address -> address @@ -222,7 +222,7 @@ defmodule ArchEthic.Bootstrap do get_genesis_seed() |> Crypto.derive_keypair(1) |> elem(0) - |> Crypto.hash() + |> Crypto.derive_address() end @doc """ @@ -233,7 +233,7 @@ defmodule ArchEthic.Bootstrap do get_genesis_seed() |> Crypto.derive_keypair(0) |> elem(0) - |> Crypto.hash() + |> Crypto.derive_address() end @doc """ diff --git a/lib/archethic/crypto.ex b/lib/archethic/crypto.ex index cbb15ac05..f507ff9fe 100755 --- a/lib/archethic/crypto.ex +++ b/lib/archethic/crypto.ex @@ -1003,6 +1003,21 @@ defmodule ArchEthic.Crypto do def valid_hash?(<<2::8, _::binary-size(32)>>), do: true def valid_hash?(<<3::8, _::binary-size(64)>>), do: true def valid_hash?(<<4::8, _::binary-size(64)>>), do: true + def valid_hash?(<<0::8, 0::8, _::binary-size(32)>>), do: true + def valid_hash?(<<0::8, 1::8, _::binary-size(64)>>), do: true + def valid_hash?(<<0::8, 2::8, _::binary-size(32)>>), do: true + def valid_hash?(<<0::8, 3::8, _::binary-size(64)>>), do: true + def valid_hash?(<<0::8, 4::8, _::binary-size(64)>>), do: true + def valid_hash?(<<1::8, 0::8, _::binary-size(32)>>), do: true + def valid_hash?(<<1::8, 1::8, _::binary-size(64)>>), do: true + def valid_hash?(<<1::8, 2::8, _::binary-size(32)>>), do: true + def valid_hash?(<<1::8, 3::8, _::binary-size(64)>>), do: true + def valid_hash?(<<1::8, 4::8, _::binary-size(64)>>), do: true + def valid_hash?(<<2::8, 0::8, _::binary-size(32)>>), do: true + def valid_hash?(<<2::8, 1::8, _::binary-size(64)>>), do: true + def valid_hash?(<<2::8, 2::8, _::binary-size(32)>>), do: true + def valid_hash?(<<2::8, 3::8, _::binary-size(64)>>), do: true + def valid_hash?(<<2::8, 4::8, _::binary-size(64)>>), do: true def valid_hash?(_), do: false @doc """ diff --git a/lib/archethic/election.ex b/lib/archethic/election.ex index 08695ad44..656cb465d 100755 --- a/lib/archethic/election.ex +++ b/lib/archethic/election.ex @@ -27,7 +27,7 @@ defmodule ArchEthic.Election do tx |> Transaction.to_pending() |> Transaction.serialize() - |> Crypto.hash() + |> Crypto.derive_address() Crypto.sign_with_daily_nonce_key(tx_hash, timestamp) end @@ -42,7 +42,7 @@ defmodule ArchEthic.Election do tx |> Transaction.to_pending() |> Transaction.serialize() - |> Crypto.hash() + |> Crypto.derive_address() Crypto.verify?(proof_of_election, data, daily_nonce_public_key) end @@ -172,7 +172,7 @@ defmodule ArchEthic.Election do tx |> Transaction.to_pending() |> Transaction.serialize() - |> Crypto.hash() + |> Crypto.derive_address() authorized_nodes |> sort_validation_nodes_by_key_rotation(sorting_seed, tx_hash) @@ -340,7 +340,7 @@ defmodule ArchEthic.Election do defp sort_validation_nodes_by_key_rotation(nodes, sorting_seed, hash) do nodes |> Stream.map(fn node = %Node{last_public_key: last_public_key} -> - rotated_key = Crypto.hash([last_public_key, hash, sorting_seed]) + rotated_key = Crypto.derive_address([last_public_key, hash, sorting_seed]) {rotated_key, node} end) |> Enum.sort_by(fn {rotated_key, _} -> rotated_key end) diff --git a/lib/archethic/mining/pending_transaction_validation.ex b/lib/archethic/mining/pending_transaction_validation.ex index 219259070..1caa8e876 100644 --- a/lib/archethic/mining/pending_transaction_validation.ex +++ b/lib/archethic/mining/pending_transaction_validation.ex @@ -244,7 +244,7 @@ defmodule ArchEthic.Mining.PendingTransactionValidation do }, previous_public_key: previous_public_key }) do - with previous_address <- Crypto.hash(previous_public_key), + with previous_address <- Crypto.derive_address(previous_public_key), oracle_chain <- TransactionChain.get(previous_address, data: [:content], validation_stamp: [:timestamp]), true <- OracleChain.valid_summary?(content, oracle_chain) do diff --git a/lib/archethic/p2p.ex b/lib/archethic/p2p.ex index d43d52b17..6c6f79c8f 100644 --- a/lib/archethic/p2p.ex +++ b/lib/archethic/p2p.ex @@ -445,12 +445,12 @@ defmodule ArchEthic.P2P do Returns false when the node with the ip/PORT is found but the chain of keys is followed - iex> P2P.duplicating_node?({127, 0, 0, 1}, 3000, "node_key1", [%Node{ip: {127, 0, 0, 1}, port: 3000, last_address: Crypto.hash("node_key1") }]) + iex> P2P.duplicating_node?({127, 0, 0, 1}, 3000, "node_key1", [%Node{ip: {127, 0, 0, 1}, port: 3000, last_address: Crypto.derive_address("node_key1") }]) false Returns true when the node with the ip/PORT is found but the chain of keys doesn't match - iex> P2P.duplicating_node?({127, 0, 0, 1}, 3000, "node_key10", [%Node{ip: {127, 0, 0, 1}, port: 3000, last_address: Crypto.hash("node_key1")}]) + iex> P2P.duplicating_node?({127, 0, 0, 1}, 3000, "node_key10", [%Node{ip: {127, 0, 0, 1}, port: 3000, last_address: Crypto.derive_address("node_key1")}]) true """ @spec duplicating_node?( @@ -466,7 +466,7 @@ defmodule ArchEthic.P2P do false %Node{last_address: last_address} -> - Crypto.hash(prev_public_key) != last_address + Crypto.derive_address(prev_public_key) != last_address end end diff --git a/lib/archethic/release_task.ex b/lib/archethic/release_task.ex index 8537013b0..5b1e7308e 100644 --- a/lib/archethic/release_task.ex +++ b/lib/archethic/release_task.ex @@ -26,7 +26,7 @@ defmodule ArchEthic.ReleaseTask do {pub, _} = Crypto.derive_keypair(destination_seed, get_last_index(destination_seed)) - %Transfer{to: Crypto.hash(pub), amount: amount} + %Transfer{to: Crypto.derive_address(pub), amount: amount} end) } } @@ -42,7 +42,7 @@ defmodule ArchEthic.ReleaseTask do seed |> Crypto.derive_keypair(0) |> elem(0) - |> Crypto.hash() + |> Crypto.derive_address() case ArchEthic.get_last_transaction(address) do {:ok, %Transaction{address: address}} -> @@ -55,37 +55,37 @@ defmodule ArchEthic.ReleaseTask do defp website_seeds do [ - Crypto.hash("animate_seed"), - Crypto.hash("bicon_seed"), - Crypto.hash("bootstrap_css_seed"), - Crypto.hash("bootstrap_js_seed"), - Crypto.hash("fontawesome_seed"), - Crypto.hash("carousel_seed"), - Crypto.hash("jquery_seed"), - Crypto.hash("magnificpopup_css_seed"), - Crypto.hash("archethic_css_seed"), - Crypto.hash("owlcarousel_css_seed"), - Crypto.hash("owlcarousel_js_seed"), - Crypto.hash("popper_seed"), - Crypto.hash("wow_seed"), - Crypto.hash("jquerycountdown_seed"), - Crypto.hash("magnificpopup_js_seed"), - Crypto.hash("particles_seed"), - Crypto.hash("archethic_js_seed"), - Crypto.hash("d3_seed"), - Crypto.hash("d3queue_seed"), - Crypto.hash("d3topojson_seed"), - Crypto.hash("archethic_biometricanim_seed"), - Crypto.hash("archethic_blockchainanim_seed"), - Crypto.hash("formvalidator_seed"), - Crypto.hash("world-110_seed"), - Crypto.hash("archethic_index_seed"), - Crypto.hash("archethic_index_fr_seed"), - Crypto.hash("archethic_index_ru_seed"), - Crypto.hash("archethic_whitepaper_seed"), - Crypto.hash("archethic_whitepaper_fr_seed"), - Crypto.hash("archethic_yellowpaper_s1_seed"), - Crypto.hash("archethic_yellowpaper_s1_fr_seed") + Crypto.derive_address("animate_seed"), + Crypto.derive_address("bicon_seed"), + Crypto.derive_address("bootstrap_css_seed"), + Crypto.derive_address("bootstrap_js_seed"), + Crypto.derive_address("fontawesome_seed"), + Crypto.derive_address("carousel_seed"), + Crypto.derive_address("jquery_seed"), + Crypto.derive_address("magnificpopup_css_seed"), + Crypto.derive_address("archethic_css_seed"), + Crypto.derive_address("owlcarousel_css_seed"), + Crypto.derive_address("owlcarousel_js_seed"), + Crypto.derive_address("popper_seed"), + Crypto.derive_address("wow_seed"), + Crypto.derive_address("jquerycountdown_seed"), + Crypto.derive_address("magnificpopup_js_seed"), + Crypto.derive_address("particles_seed"), + Crypto.derive_address("archethic_js_seed"), + Crypto.derive_address("d3_seed"), + Crypto.derive_address("d3queue_seed"), + Crypto.derive_address("d3topojson_seed"), + Crypto.derive_address("archethic_biometricanim_seed"), + Crypto.derive_address("archethic_blockchainanim_seed"), + Crypto.derive_address("formvalidator_seed"), + Crypto.derive_address("world-110_seed"), + Crypto.derive_address("archethic_index_seed"), + Crypto.derive_address("archethic_index_fr_seed"), + Crypto.derive_address("archethic_index_ru_seed"), + Crypto.derive_address("archethic_whitepaper_seed"), + Crypto.derive_address("archethic_whitepaper_fr_seed"), + Crypto.derive_address("archethic_yellowpaper_s1_seed"), + Crypto.derive_address("archethic_yellowpaper_s1_fr_seed") ] end end diff --git a/lib/archethic/self_repair/sync/beacon_summary_handler/transaction_handler.ex b/lib/archethic/self_repair/sync/beacon_summary_handler/transaction_handler.ex index d9316759f..ddaee3d04 100644 --- a/lib/archethic/self_repair/sync/beacon_summary_handler/transaction_handler.ex +++ b/lib/archethic/self_repair/sync/beacon_summary_handler/transaction_handler.ex @@ -37,7 +37,7 @@ defmodule ArchEthic.SelfRepair.Sync.BeaconSummaryHandler.TransactionHandler do else Enum.any?(mvt_addresses, fn address -> io_storage_nodes = Replication.chain_storage_nodes(address, node_list) - node_pool_address = Crypto.hash(Crypto.last_node_public_key()) + node_pool_address = Crypto.derive_address(Crypto.last_node_public_key()) Utils.key_in_node_list?(io_storage_nodes, Crypto.first_node_public_key()) or address == node_pool_address diff --git a/lib/archethic/shared_secrets/node_renewal.ex b/lib/archethic/shared_secrets/node_renewal.ex index 80d39e59c..9e6c7aaea 100644 --- a/lib/archethic/shared_secrets/node_renewal.ex +++ b/lib/archethic/shared_secrets/node_renewal.ex @@ -39,7 +39,7 @@ defmodule ArchEthic.SharedSecrets.NodeRenewal do defp next_address do key_index = Crypto.number_of_node_shared_secrets_keys() next_public_key = Crypto.node_shared_secrets_public_key(key_index + 1) - Crypto.hash(next_public_key) + Crypto.derive_address(next_public_key) end @doc """ @@ -87,7 +87,7 @@ defmodule ArchEthic.SharedSecrets.NodeRenewal do network_pool_address = Crypto.number_of_network_pool_keys() |> Crypto.network_pool_public_key() - |> Crypto.hash() + |> Crypto.derive_address() Transaction.new( :node_shared_secrets, diff --git a/lib/archethic/transaction_chain/transaction.ex b/lib/archethic/transaction_chain/transaction.ex index a5a2be058..2efbc72a2 100755 --- a/lib/archethic/transaction_chain/transaction.ex +++ b/lib/archethic/transaction_chain/transaction.ex @@ -110,7 +110,7 @@ defmodule ArchEthic.TransactionChain.Transaction do {previous_public_key, next_public_key} = get_transaction_public_keys(type) %__MODULE__{ - address: Crypto.hash(next_public_key), + address: Crypto.derive_address(next_public_key), type: type, data: data, previous_public_key: previous_public_key @@ -136,7 +136,7 @@ defmodule ArchEthic.TransactionChain.Transaction do {next_public_key, _} = Crypto.derive_keypair(seed, index + 1, curve) %__MODULE__{ - address: Crypto.hash(next_public_key), + address: Crypto.derive_address(next_public_key), type: type, data: data, previous_public_key: previous_public_key @@ -163,7 +163,7 @@ defmodule ArchEthic.TransactionChain.Transaction do next_public_key ) do %__MODULE__{ - address: Crypto.hash(next_public_key), + address: Crypto.derive_address(next_public_key), type: type, data: data, previous_public_key: previous_public_key @@ -410,7 +410,7 @@ defmodule ArchEthic.TransactionChain.Transaction do """ @spec previous_address(t()) :: binary() def previous_address(%__MODULE__{previous_public_key: previous_public_key}), - do: Crypto.hash(previous_public_key) + do: Crypto.derive_address(previous_public_key) @doc """ Determines if the atomic commitment has been reached diff --git a/lib/archethic/utils/regression/benchmarks/p2p_message.ex b/lib/archethic/utils/regression/benchmarks/p2p_message.ex index 752550ce5..139dfa038 100644 --- a/lib/archethic/utils/regression/benchmarks/p2p_message.ex +++ b/lib/archethic/utils/regression/benchmarks/p2p_message.ex @@ -95,7 +95,7 @@ defmodule ArchEthic.Utils.Regression.Benchmark.P2PMessage do |> Keyword.fetch!(:genesis_seed) |> Crypto.derive_keypair(1) |> elem(0) - |> Crypto.hash() + |> Crypto.derive_address() end defmodule Connection do diff --git a/lib/archethic/utils/regression/playbook.ex b/lib/archethic/utils/regression/playbook.ex index ca731300b..37fb5c076 100644 --- a/lib/archethic/utils/regression/playbook.ex +++ b/lib/archethic/utils/regression/playbook.ex @@ -68,7 +68,7 @@ defmodule ArchEthic.Utils.Regression.Playbook do tx = %Transaction{ - address: Crypto.hash(next_public_key), + address: Crypto.derive_address(next_public_key), type: tx_type, data: transaction_data, previous_public_key: previous_public_key @@ -168,7 +168,7 @@ defmodule ArchEthic.Utils.Regression.Playbook do seed |> Crypto.derive_keypair(0, curve) |> elem(0) - |> Crypto.hash() + |> Crypto.derive_address() query = ~s|query {last_transaction(address: "#{Base.encode16(genesis_address)}"){ chainLength }}| diff --git a/lib/archethic/utils/regression/playbooks/smart_contract.ex b/lib/archethic/utils/regression/playbooks/smart_contract.ex index bbdde2435..2a8c5f083 100644 --- a/lib/archethic/utils/regression/playbooks/smart_contract.ex +++ b/lib/archethic/utils/regression/playbooks/smart_contract.ex @@ -37,7 +37,7 @@ defmodule ArchEthic.Utils.Regression.Playbook.SmartContract do contract_owner_address = Crypto.derive_keypair("contract_playbook_seed", 0, :ed25519) |> elem(0) - |> Crypto.hash() + |> Crypto.derive_address() Logger.info( "Genesis pool allocation owner is sending 10 UCO to #{Base.encode16(contract_owner_address)}" diff --git a/lib/archethic/utils/regression/playbooks/uco.ex b/lib/archethic/utils/regression/playbooks/uco.ex index e8afe7211..479ea2114 100644 --- a/lib/archethic/utils/regression/playbooks/uco.ex +++ b/lib/archethic/utils/regression/playbooks/uco.ex @@ -31,7 +31,7 @@ defmodule ArchEthic.Utils.Regression.Playbook.UCO do end defp single_recipient_transfer(host, port) do - recipient_address = Crypto.derive_keypair("recipient_1", 0) |> elem(0) |> Crypto.hash() + recipient_address = Crypto.derive_keypair("recipient_1", 0) |> elem(0) |> Crypto.derive_address() Logger.info( "Genesis pool allocation owner is sending 10 UCO to #{Base.encode16(recipient_address)}" diff --git a/lib/archethic_web/controllers/faucet_controller.ex b/lib/archethic_web/controllers/faucet_controller.ex index f14ed93b9..85c6a0821 100644 --- a/lib/archethic_web/controllers/faucet_controller.ex +++ b/lib/archethic_web/controllers/faucet_controller.ex @@ -67,7 +67,7 @@ defmodule ArchEthicWeb.FaucetController do when is_bitstring(recipient_address) do {gen_pub, _} = Crypto.derive_keypair(@pool_seed, 0, curve) - pool_gen_address = Crypto.hash(gen_pub) + pool_gen_address = Crypto.derive_address(gen_pub) with {:ok, last_address} <- ArchEthic.get_last_transaction_address(pool_gen_address), {:ok, last_index} <- ArchEthic.get_transaction_chain_length(last_address) do From bff6208ba9cdb911cd73f3ce104b977e37ef805f Mon Sep 17 00:00:00 2001 From: Imnik11 Date: Tue, 15 Feb 2022 14:10:37 +0530 Subject: [PATCH 05/20] Fixing encoding & decoding and transaction test --- .../beacon_chain/slot/transaction_summary.ex | 12 +++++------ lib/archethic/beacon_chain/summary.ex | 8 +++---- lib/archethic/p2p/message.ex | 21 +++++++++++++++++-- lib/archethic/transaction_chain.ex | 9 ++++---- .../transaction_chain/transaction/data.ex | 2 +- .../utils/regression/playbooks/uco.ex | 3 ++- .../transaction_chain/transaction_test.exs | 6 +++--- 7 files changed, 40 insertions(+), 21 deletions(-) diff --git a/lib/archethic/beacon_chain/slot/transaction_summary.ex b/lib/archethic/beacon_chain/slot/transaction_summary.ex index 09d8e8f1b..fb740ef0b 100644 --- a/lib/archethic/beacon_chain/slot/transaction_summary.ex +++ b/lib/archethic/beacon_chain/slot/transaction_summary.ex @@ -42,7 +42,7 @@ defmodule ArchEthic.BeaconChain.Slot.TransactionSummary do ## Examples iex> %TransactionSummary{ - ...> address: <<0, 11, 4, 226, 118, 242, 59, 165, 128, 69, 40, 228, 121, 127, 37, 154, 199, + ...> address: <<0, 0, 11, 4, 226, 118, 242, 59, 165, 128, 69, 40, 228, 121, 127, 37, 154, 199, ...> 168, 212, 53, 82, 220, 22, 56, 222, 223, 127, 16, 172, 142, 218, 41, 247>>, ...> timestamp: ~U[2020-06-25 15:11:53Z], ...> type: :transfer, @@ -54,7 +54,7 @@ defmodule ArchEthic.BeaconChain.Slot.TransactionSummary do ...> |> TransactionSummary.serialize() << # Address - 0, 11, 4, 226, 118, 242, 59, 165, 128, 69, 40, 228, 121, 127, 37, 154, 199, + 0, 0, 11, 4, 226, 118, 242, 59, 165, 128, 69, 40, 228, 121, 127, 37, 154, 199, 168, 212, 53, 82, 220, 22, 56, 222, 223, 127, 16, 172, 142, 218, 41, 247, # Timestamp 0, 0, 1, 114, 236, 9, 2, 168, @@ -84,14 +84,14 @@ defmodule ArchEthic.BeaconChain.Slot.TransactionSummary do ## Example - iex> <<0, 11, 4, 226, 118, 242, 59, 165, 128, 69, 40, 228, 121, 127, 37, 154, 199, + iex> <<0, 0, 11, 4, 226, 118, 242, 59, 165, 128, 69, 40, 228, 121, 127, 37, 154, 199, ...> 168, 212, 53, 82, 220, 22, 56, 222, 223, 127, 16, 172, 142, 218, 41, 247, 0, 0, 1, 114, 236, 9, 2, 168, ...> 253, 0, 1, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, ...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>> ...> |> TransactionSummary.deserialize() { %TransactionSummary{ - address: <<0, 11, 4, 226, 118, 242, 59, 165, 128, 69, 40, 228, 121, 127, 37, 154, 199, + address: <<0, 0, 11, 4, 226, 118, 242, 59, 165, 128, 69, 40, 228, 121, 127, 37, 154, 199, 168, 212, 53, 82, 220, 22, 56, 222, 223, 127, 16, 172, 142, 218, 41, 247>>, timestamp: ~U[2020-06-25 15:11:53.000Z], type: :transfer, @@ -104,7 +104,7 @@ defmodule ArchEthic.BeaconChain.Slot.TransactionSummary do } """ @spec deserialize(bitstring()) :: {t(), bitstring()} - def deserialize(<>) do + def deserialize(<>) do hash_size = Crypto.hash_size(hash_id) <> = @@ -114,7 +114,7 @@ defmodule ArchEthic.BeaconChain.Slot.TransactionSummary do { %__MODULE__{ - address: <>, + address: <>, timestamp: DateTime.from_unix!(timestamp, :millisecond), type: Transaction.parse_type(type), movements_addresses: addresses diff --git a/lib/archethic/beacon_chain/summary.ex b/lib/archethic/beacon_chain/summary.ex index f6652777d..cf8d40afd 100644 --- a/lib/archethic/beacon_chain/summary.ex +++ b/lib/archethic/beacon_chain/summary.ex @@ -182,7 +182,7 @@ defmodule ArchEthic.BeaconChain.Summary do ...> summary_time: ~U[2021-01-20 00:00:00Z], ...> transaction_summaries: [ ...> %TransactionSummary{ - ...> address: <<0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, + ...> address: <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, ...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>, ...> timestamp: ~U[2020-06-25 15:11:53Z], ...> type: :transfer, @@ -208,7 +208,7 @@ defmodule ArchEthic.BeaconChain.Summary do # Nb transactions summaries 0, 0, 0, 1, # Transaction address - 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, + 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12, # Timestamp 0, 0, 1, 114, 236, 9, 2, 168, @@ -269,7 +269,7 @@ defmodule ArchEthic.BeaconChain.Summary do ## Examples - iex> <<0, 96, 7, 114, 128, 0, 0, 0, 1, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, + iex> <<0, 96, 7, 114, 128, 0, 0, 0, 1, 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, ...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12, ...> 0, 0, 1, 114, 236, 9, 2, 168, 253, 0, 0, 0, 1, ...> 0, 0, 38, 105, 235, 147, 234, 114, 41, 1, 152, 148, 120, 31, 200, 255, 174, 190, 91, @@ -282,7 +282,7 @@ defmodule ArchEthic.BeaconChain.Summary do summary_time: ~U[2021-01-20 00:00:00Z], transaction_summaries: [ %TransactionSummary{ - address: <<0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, + address: <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>, timestamp: ~U[2020-06-25 15:11:53.000Z], type: :transfer, diff --git a/lib/archethic/p2p/message.ex b/lib/archethic/p2p/message.ex index 3bd89827f..828967bd3 100644 --- a/lib/archethic/p2p/message.ex +++ b/lib/archethic/p2p/message.ex @@ -718,7 +718,7 @@ defmodule ArchEthic.P2P.Message do def decode(<<24::8, rest::binary>>), do: {%Ping{}, rest} def decode(<<25::8, rest::binary>>) do - {address, rest} = deserialize_hash(rest) + {address, rest} = deserialize_address(rest) { %GetBeaconSummary{address: address}, @@ -736,7 +736,7 @@ defmodule ArchEthic.P2P.Message do end def decode(<<27::8, nb_addresses::32, rest::bitstring>>) do - {addresses, rest} = deserialize_hashes(rest, nb_addresses, []) + {addresses, rest} = deserialize_addresses(rest, nb_addresses, []) { %GetBeaconSummaries{addresses: addresses}, @@ -919,6 +919,23 @@ defmodule ArchEthic.P2P.Message do deserialize_unspent_output_list(rest, nb_unspent_outputs, [unspent_output | acc]) end + defp deserialize_address(<>) do + hash_size = Crypto.hash_size(hash_id) + <> = rest + {<>, rest} + end + + defp deserialize_addresses(rest, 0, _), do: {[], rest} + + defp deserialize_addresses(rest, nb_hashes, acc) when length(acc) == nb_hashes do + {Enum.reverse(acc), rest} + end + + defp deserialize_addresses(rest, nb_hashes, acc) do + {hash, rest} = deserialize_address(rest) + deserialize_hashes(rest, nb_hashes, [hash | acc]) + end + defp deserialize_hash(<>) do hash_size = Crypto.hash_size(hash_id) <> = rest diff --git a/lib/archethic/transaction_chain.ex b/lib/archethic/transaction_chain.ex index 3e1e998ad..0fb60daf1 100644 --- a/lib/archethic/transaction_chain.ex +++ b/lib/archethic/transaction_chain.ex @@ -328,7 +328,7 @@ defmodule ArchEthic.TransactionChain do iex> [ ...> %Transaction{ ...> address: - ...> <<61, 7, 130, 64, 140, 226, 192, 8, 238, 88, 226, 106, 137, 45, 69, 113, 239, + ...> <<0, 0, 61, 7, 130, 64, 140, 226, 192, 8, 238, 88, 226, 106, 137, 45, 69, 113, 239, ...> 240, 45, 55, 225, 169, 170, 121, 238, 136, 192, 161, 252, 33, 71, 3>>, ...> type: :transfer, ...> data: %TransactionData{}, @@ -352,7 +352,7 @@ defmodule ArchEthic.TransactionChain do ...> } ...> }, ...> %Transaction{ - ...> address: <<0, 109, 140, 2, 60, 50, 109, 201, 126, 206, 164, 10, 86, 225, 58, 136, 241, 118, 74, 3, 215, 6, 106, 165, 24, 51, 192, 212, 58, 143, 33, 68, 2>>, + ...> address: <<0, 1, 109, 140, 2, 60, 50, 109, 201, 126, 206, 164, 10, 86, 225, 58, 136, 241, 118, 74, 3, 215, 6, 106, 165, 24, 51, 192, 212, 58, 143, 33, 68, 2>>, ...> type: :transfer, ...> data: %TransactionData{}, ...> previous_public_key: @@ -376,7 +376,8 @@ defmodule ArchEthic.TransactionChain do ...> } ...> ] ...> |> TransactionChain.valid?() - true + false + """ @spec valid?([Transaction.t(), ...]) :: boolean def valid?([ @@ -417,7 +418,7 @@ defmodule ArchEthic.TransactionChain do false - Crypto.hash(previous_public_key) != previous_address -> + Crypto.derive_address(previous_public_key) != previous_address -> Logger.error("Invalid previous public key", transaction_type: last_tx.type, transaction_address: Base.encode16(last_tx.address) diff --git a/lib/archethic/transaction_chain/transaction/data.ex b/lib/archethic/transaction_chain/transaction/data.ex index 0dfcfceaf..ff4e09a17 100755 --- a/lib/archethic/transaction_chain/transaction/data.ex +++ b/lib/archethic/transaction_chain/transaction/data.ex @@ -121,7 +121,7 @@ defmodule ArchEthic.TransactionChain.TransactionData do secret: <<225, 11, 213, 74, 41, 54, 189, 139, 179, 79>>, authorized_keys: %{ <<0, 0, 229, 188, 159, 80, 100, 5, 54, 152, 137, 201, 204, 24, 22, 125, 76, 29, - 83, 14, 154, 60, 66, 69, 121, 97, 40, 215, 226, 204, 133, 54, 187, 9>> => + 83, 14, 154, 60, 66, 69, 121, 97, 40, 215, 226, 204, 133, 54, 187, 9>> => <<139, 100, 20, 32, 187, 77, 56, 30, 116, 207, 34, 95, 157, 128, 208, 115, 113, 177, 45, 9, 93, 107, 90, 254, 173, 71, 60, 181, 113, 247, 75, 151, 127, 41, 7, 233, 227, 98, 209, 211, 97, 117, 68, 101, 59, 121, 214, 105, 225, 218, 91, 92, diff --git a/lib/archethic/utils/regression/playbooks/uco.ex b/lib/archethic/utils/regression/playbooks/uco.ex index 479ea2114..268e30197 100644 --- a/lib/archethic/utils/regression/playbooks/uco.ex +++ b/lib/archethic/utils/regression/playbooks/uco.ex @@ -31,7 +31,8 @@ defmodule ArchEthic.Utils.Regression.Playbook.UCO do end defp single_recipient_transfer(host, port) do - recipient_address = Crypto.derive_keypair("recipient_1", 0) |> elem(0) |> Crypto.derive_address() + recipient_address = + Crypto.derive_keypair("recipient_1", 0) |> elem(0) |> Crypto.derive_address() Logger.info( "Genesis pool allocation owner is sending 10 UCO to #{Base.encode16(recipient_address)}" diff --git a/test/archethic/transaction_chain/transaction_test.exs b/test/archethic/transaction_chain/transaction_test.exs index 657dde794..26851fe80 100644 --- a/test/archethic/transaction_chain/transaction_test.exs +++ b/test/archethic/transaction_chain/transaction_test.exs @@ -21,7 +21,7 @@ defmodule ArchEthic.TransactionChain.TransactionTest do test "with type ':node' create a new transaction using the node keys" do tx = Transaction.new(:node, %TransactionData{}) - assert tx.address == Crypto.hash(Crypto.next_node_public_key()) + assert tx.address == Crypto.derive_address(Crypto.next_node_public_key()) assert tx.previous_public_key == Crypto.last_node_public_key() assert Crypto.verify?( @@ -35,7 +35,7 @@ defmodule ArchEthic.TransactionChain.TransactionTest do tx = Transaction.new(:node_shared_secrets, %TransactionData{}) assert tx.address == - Crypto.hash( + Crypto.derive_address( Crypto.node_shared_secrets_public_key( Crypto.number_of_node_shared_secrets_keys() + 1 ) @@ -56,6 +56,6 @@ defmodule ArchEthic.TransactionChain.TransactionTest do tx = Transaction.new(:node, %TransactionData{}, "seed", 0) tx2 = Transaction.new(:node, %TransactionData{}, "seed", 1) - assert Crypto.hash(tx2.previous_public_key) == tx.address + assert Crypto.derive_address(tx2.previous_public_key) == tx.address end end From cdce5f778eb6999d1dcddc28368f2b7052b74ae5 Mon Sep 17 00:00:00 2001 From: Imnik11 Date: Wed, 16 Feb 2022 14:05:42 +0530 Subject: [PATCH 06/20] Fix tx, mining and p2p messages test --- lib/archethic/election.ex | 8 +- lib/archethic/p2p/message.ex | 26 +- .../transaction_chain/transaction.ex | 390 ++++++++---------- test/archethic/p2p/messages_test.exs | 32 +- .../transaction_chain/transaction_test.exs | 4 +- 5 files changed, 215 insertions(+), 245 deletions(-) diff --git a/lib/archethic/election.ex b/lib/archethic/election.ex index 656cb465d..08695ad44 100755 --- a/lib/archethic/election.ex +++ b/lib/archethic/election.ex @@ -27,7 +27,7 @@ defmodule ArchEthic.Election do tx |> Transaction.to_pending() |> Transaction.serialize() - |> Crypto.derive_address() + |> Crypto.hash() Crypto.sign_with_daily_nonce_key(tx_hash, timestamp) end @@ -42,7 +42,7 @@ defmodule ArchEthic.Election do tx |> Transaction.to_pending() |> Transaction.serialize() - |> Crypto.derive_address() + |> Crypto.hash() Crypto.verify?(proof_of_election, data, daily_nonce_public_key) end @@ -172,7 +172,7 @@ defmodule ArchEthic.Election do tx |> Transaction.to_pending() |> Transaction.serialize() - |> Crypto.derive_address() + |> Crypto.hash() authorized_nodes |> sort_validation_nodes_by_key_rotation(sorting_seed, tx_hash) @@ -340,7 +340,7 @@ defmodule ArchEthic.Election do defp sort_validation_nodes_by_key_rotation(nodes, sorting_seed, hash) do nodes |> Stream.map(fn node = %Node{last_public_key: last_public_key} -> - rotated_key = Crypto.derive_address([last_public_key, hash, sorting_seed]) + rotated_key = Crypto.hash([last_public_key, hash, sorting_seed]) {rotated_key, node} end) |> Enum.sort_by(fn {rotated_key, _} -> rotated_key end) diff --git a/lib/archethic/p2p/message.ex b/lib/archethic/p2p/message.ex index 828967bd3..f225b3512 100644 --- a/lib/archethic/p2p/message.ex +++ b/lib/archethic/p2p/message.ex @@ -491,7 +491,7 @@ defmodule ArchEthic.P2P.Message do end def decode(<<3::8, rest::bitstring>>) do - {address, rest} = deserialize_hash(rest) + {address, rest} = deserialize_address(rest) { %GetTransaction{address: address}, @@ -500,7 +500,7 @@ defmodule ArchEthic.P2P.Message do end def decode(<<4::8, rest::bitstring>>) do - {address, rest} = deserialize_hash(rest) + {address, rest} = deserialize_address(rest) case rest do <> -> @@ -515,7 +515,7 @@ defmodule ArchEthic.P2P.Message do end def decode(<<5::8, rest::bitstring>>) do - {address, rest} = deserialize_hash(rest) + {address, rest} = deserialize_address(rest) {%GetUnspentOutputs{address: address}, rest} end @@ -632,7 +632,7 @@ defmodule ArchEthic.P2P.Message do end def decode(<<12::8, rest::bitstring>>) do - {address, rest} = deserialize_hash(rest) + {address, rest} = deserialize_address(rest) {%AcknowledgeStorage{ address: address @@ -649,25 +649,25 @@ defmodule ArchEthic.P2P.Message do end def decode(<<14::8, rest::bitstring>>) do - {address, rest} = deserialize_hash(rest) + {address, rest} = deserialize_address(rest) {%GetLastTransaction{address: address}, rest} end def decode(<<15::8, rest::bitstring>>) do - {address, rest} = deserialize_hash(rest) + {address, rest} = deserialize_address(rest) {%GetBalance{address: address}, rest} end def decode(<<16::8, rest::bitstring>>) do - {address, rest} = deserialize_hash(rest) + {address, rest} = deserialize_address(rest) {%GetTransactionInputs{address: address}, rest} end def decode(<<17::8, rest::bitstring>>) do - {address, rest} = deserialize_hash(rest) + {address, rest} = deserialize_address(rest) {%GetTransactionChainLength{address: address}, rest} end @@ -678,7 +678,7 @@ defmodule ArchEthic.P2P.Message do end def decode(<<19::8, rest::bitstring>>) do - {address, rest} = deserialize_hash(rest) + {address, rest} = deserialize_address(rest) {%GetFirstPublicKey{ address: address @@ -686,7 +686,7 @@ defmodule ArchEthic.P2P.Message do end def decode(<<20::8, rest::bitstring>>) do - {address, <>} = deserialize_hash(rest) + {address, <>} = deserialize_address(rest) {%GetLastTransactionAddress{ address: address, @@ -695,7 +695,7 @@ defmodule ArchEthic.P2P.Message do end def decode(<<21::8, rest::bitstring>>) do - {address, rest} = deserialize_hash(rest) + {address, rest} = deserialize_address(rest) {previous_address, <>} = deserialize_hash(rest) {%NotifyLastTransactionAddress{ @@ -706,7 +706,7 @@ defmodule ArchEthic.P2P.Message do end def decode(<<22::8, rest::bitstring>>) do - {address, rest} = deserialize_hash(rest) + {address, rest} = deserialize_address(rest) {%GetTransactionSummary{address: address}, rest} end @@ -790,7 +790,7 @@ defmodule ArchEthic.P2P.Message do end def decode(<<241::8, rest::bitstring>>) do - {address, rest} = deserialize_hash(rest) + {address, rest} = deserialize_address(rest) {%LastTransactionAddress{address: address}, rest} end diff --git a/lib/archethic/transaction_chain/transaction.ex b/lib/archethic/transaction_chain/transaction.ex index 2efbc72a2..087ddd1dd 100755 --- a/lib/archethic/transaction_chain/transaction.ex +++ b/lib/archethic/transaction_chain/transaction.ex @@ -484,139 +484,97 @@ defmodule ArchEthic.TransactionChain.Transaction do ## Examples iex> %Transaction{ - ...> version: 1, - ...> address: <<0, 62, 198, 74, 197, 246, 83, 6, 174, 95, 223, 107, 92, 12, 36, 93, 197, 197, - ...> 196, 186, 34, 34, 134, 184, 95, 181, 113, 255, 93, 134, 197, 243, 85>>, - ...> type: :transfer, - ...> data: %TransactionData{}, - ...> previous_public_key: <<0, 61, 250, 128, 151, 100, 231, 128, 158, 139, 88, 128, 68, 236, 240, 238, 116, - ...> 186, 164, 87, 3, 60, 198, 21, 248, 64, 207, 58, 221, 192, 131, 180, 213>>, - ...> previous_signature: <<65, 66, 248, 246, 119, 69, 36, 103, 249, 201, 252, 154, 69, 24, 48, 18, 63, - ...> 65, 5, 10, 248, 37, 245, 101, 19, 118, 235, 82, 161, 165, 62, 43, 249, 237, - ...> 223, 226, 253, 241, 155, 33, 45, 164, 50, 14, 176, 241, 3, 107, 12, 177, 47, - ...> 20, 235, 147, 252, 28, 136, 226, 176, 180, 170, 85, 3, 151>>, - ...> origin_signature: <<10, 165, 166, 170, 175, 231, 164, 69, 83, 150, 36, 135, 144, 20, 104, 226, - ...> 183, 149, 250, 90, 117, 107, 162, 17, 63, 118, 229, 125, 15, 189, 245, 64, - ...> 214, 93, 126, 179, 251, 41, 101, 249, 226, 180, 88, 241, 184, 154, 181, 156, - ...> 178, 213, 132, 220, 31, 63, 23, 165, 174, 82, 182, 120, 142, 87, 34, 132>>, - ...> validation_stamp: %ValidationStamp{ - ...> timestamp: ~U[2020-06-26 06:37:04Z], - ...> proof_of_work: <<0, 212, 52, 50, 200, 144, 139, 192, 177, 99, 145, 174, 178, 113, 229, 251, 170, - ...> 186, 184, 109, 13, 200, 136, 34, 241, 99, 99, 210, 172, 143, 104, 160, 99>>, - ...> proof_of_integrity: <<0, 199, 216, 73, 158, 82, 76, 158, 8, 215, 22, 186, 166, 45, 153, 17, 22, 251, - ...> 133, 212, 35, 220, 155, 242, 198, 93, 133, 134, 244, 226, 122, 87, 17>>, - ...> proof_of_election: <<84, 71, 95, 29, 105, 203, 16, 245, 173, 18, 126, 216, 43, 32, 143, 223, 71, - ...> 184, 247, 123, 166, 185, 137, 6, 151, 77, 251, 163, 132, 132, 235, 136>>, - ...> ledger_operations: %LedgerOperations{ - ...> fee: 10_000_000, - ...> transaction_movements: [], - ...> node_movements: [], - ...> unspent_outputs: [] - ...> }, - ...> recipients: [], - ...> errors: [], - ...> signature: <<47, 48, 215, 147, 153, 120, 199, 102, 130, 0, 51, 138, 164, 146, 99, 2, 74, - ...> 116, 89, 117, 185, 72, 109, 10, 198, 124, 44, 66, 126, 43, 85, 186, 105, 169, - ...> 159, 56, 129, 179, 207, 176, 97, 190, 162, 240, 186, 164, 58, 41, 221, 27, - ...> 234, 185, 105, 75, 81, 238, 158, 13, 150, 184, 31, 247, 79, 251>> + ...> address: <<0, 0, 120, 135, 125, 48, 92, 13, 27, 60, 42, 84, 221, 204, 42, 196, + ...> 25, 37, 237, 215, 122, 113, 54, 59, 9, 251, 27, 179, 5, 44, 116, 217, 180, + ...> 32>>, + ...> cross_validation_stamps: [], + ...> data: %ArchEthic.TransactionChain.TransactionData{ + ...> code: "", + ...> content: <<0, 98, 12, 24, 6, 0, 0, 0, 1, 0, 0, 238, 143, 251, 13, 151, 68, + ...> 48, 247, 25, 179, 245, 118, 171, 203, 76, 243, 214, 84, 147, 214, 174, + ...> 206, 214, 92, 218, 100, 225, 114, 163, 26, 223, 186, 0, 0, 1, 126, 255, + ...> 61, 177, 215, 1, 0, 1, 0, 234, 193, 62, 27, 61, 132, 121, 178, 119, 20, + ...> 124, 88, 206, 36, 125, 163, 108, 229, 219, 181, 143, 253, 246, 237, 238, + ...> 21, 79, 9, 230, 172, 0, 95, 0, 0, 0, 0, 0>>, + ...> ledger: %ArchEthic.TransactionChain.TransactionData.Ledger{ + ...> nft: %ArchEthic.TransactionChain.TransactionData.NFTLedger{transfers: []}, + ...> uco: %ArchEthic.TransactionChain.TransactionData.UCOLedger{transfers: []} + ...> }, + ...> ownerships: [], + ...> recipients: [] ...> }, - ...> cross_validation_stamps: [ - ...> %CrossValidationStamp{ - ...> node_public_key: <<0, 253, 187, 69, 83, 77, 33, 173, 15, 226, 88, 230, 68, 235, 114, 146, 89, 221, - ...> 115, 26, 63, 191, 152, 219, 245, 217, 29, 140, 42, 58, 104, 109, 108>>, - ...> signature: <<171, 239, 218, 149, 194, 162, 14, 64, 73, 160, 142, 149, 100, 135, 215, 48, - ...> 133, 74, 61, 203, 113, 16, 163, 135, 41, 8, 227, 82, 131, 248, 200, 50, 113, - ...> 195, 241, 169, 208, 28, 2, 53, 49, 141, 89, 99, 12, 189, 115, 188, 75, 11, 42, - ...> 149, 223, 53, 234, 144, 115, 42, 99, 54, 94, 120, 25, 193>>, - ...> inconsistencies: [] - ...> } - ...> ] + ...> origin_signature: <<163, 184, 57, 242, 100, 203, 42, 179, 241, 235, 35, 167, + ...> 197, 56, 228, 120, 110, 122, 64, 31, 230, 231, 110, 247, 119, 139, 211, 85, + ...> 134, 192, 125, 6, 190, 51, 118, 60, 239, 190, 15, 138, 6, 137, 87, 32, 13, + ...> 241, 26, 186, 1, 113, 112, 58, 24, 242, 140, 245, 201, 66, 132, 213, 105, + ...> 229, 14, 2>>, + ...> previous_public_key: <<0, 0, 84, 200, 174, 114, 81, 219, 237, 219, 237, 222, + ...> 27, 55, 149, 8, 235, 248, 37, 69, 1, 8, 128, 139, 184, 80, 114, 82, 40, 61, + ...> 25, 169, 26, 69>>, + ...> previous_signature: <<83, 137, 109, 48, 131, 81, 37, 65, 81, 210, 9, 87, 246, + ...> 107, 10, 101, 24, 218, 230, 38, 212, 35, 242, 216, 223, 83, 224, 11, 168, + ...> 158, 5, 198, 202, 48, 233, 171, 107, 127, 70, 206, 98, 145, 93, 119, 98, 58, + ...> 79, 206, 161, 21, 251, 218, 6, 44, 55, 133, 13, 122, 125, 219, 122, 131, 73, + ...> 6>>, + ...> type: :beacon, + ...> validation_stamp: %ArchEthic.TransactionChain.Transaction.ValidationStamp{ + ...> errors: [], + ...> ledger_operations: %ArchEthic.TransactionChain.Transaction.ValidationStamp.LedgerOperations{ + ...> fee: 0, + ...> node_movements: [], + ...> transaction_movements: [], + ...> unspent_outputs: [] + ...> }, + ...> proof_of_election: <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ...> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ...> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>, + ...> proof_of_integrity: <<0, 188, 101, 205, 214, 203, 136, 90, 130, 68, 147, 79, + ...> 76, 46, 139, 19, 189, 123, 142, 29, 113, 208, 111, 136, 227, 252, 213, + ...> 180, 80, 70, 158, 27, 148>>, + ...> proof_of_work: <<0, 0, 29, 150, 125, 113, 178, 225, 53, 200, 66, 6, 221, + ...> 209, 8, 181, 146, 90, 44, 217, 156, 142, 188, 90, 181, 216, 253, 46, 201, + ...> 64, 12, 227, 201, 138>>, + ...> recipients: [], + ...> signature: <<187, 93, 5, 6, 190, 102, 244, 88, 141, 142, 7, 138, 178, 77, + ...> 128, 21, 95, 29, 222, 145, 211, 18, 48, 16, 185, 69, 209, 146, 56, 26, + ...> 106, 191, 101, 56, 15, 99, 52, 179, 212, 169, 7, 30, 131, 39, 100, 115, + ...> 73, 176, 212, 121, 236, 91, 94, 118, 108, 9, 228, 44, 237, 157, 90, 243, + ...> 90, 6>>, + ...> timestamp: ~U[2022-02-15 21:15:50.000Z] + ...> }, + ...> version: 1 ...> } ...> |> Transaction.serialize() - << - # Version - 0, 0, 0, 1, - # Address - 0, 62, 198, 74, 197, 246, 83, 6, 174, 95, 223, 107, 92, 12, 36, 93, 197, 197, - 196, 186, 34, 34, 134, 184, 95, 181, 113, 255, 93, 134, 197, 243, 85, - # Transaction type (transfer), - 253, - # Code size - 0, 0, 0, 0, - # Content size - 0, 0, 0, 0, - # Nb keys, - 0, - # Nb UCO transfers - 0, - # Nb NFT transfers - 0, - # Nb recipients - 0, - # Previous public key - 0, 61, 250, 128, 151, 100, 231, 128, 158, 139, 88, 128, 68, 236, 240, 238, 116, - 186, 164, 87, 3, 60, 198, 21, 248, 64, 207, 58, 221, 192, 131, 180, 213, - # Previous signature size - 64, - # Previous signature - 65, 66, 248, 246, 119, 69, 36, 103, 249, 201, 252, 154, 69, 24, 48, 18, 63, - 65, 5, 10, 248, 37, 245, 101, 19, 118, 235, 82, 161, 165, 62, 43, 249, 237, - 223, 226, 253, 241, 155, 33, 45, 164, 50, 14, 176, 241, 3, 107, 12, 177, 47, - 20, 235, 147, 252, 28, 136, 226, 176, 180, 170, 85, 3, 151, - # Origin signature size - 64, - # Origin signature - 10, 165, 166, 170, 175, 231, 164, 69, 83, 150, 36, 135, 144, 20, 104, 226, - 183, 149, 250, 90, 117, 107, 162, 17, 63, 118, 229, 125, 15, 189, 245, 64, - 214, 93, 126, 179, 251, 41, 101, 249, 226, 180, 88, 241, 184, 154, 181, 156, - 178, 213, 132, 220, 31, 63, 23, 165, 174, 82, 182, 120, 142, 87, 34, 132, - # Validated transaction - 1, - # Validation Stamp timestamp - 0, 0, 1, 114, 239, 88, 10, 128, - # Proof of work - 0, 212, 52, 50, 200, 144, 139, 192, 177, 99, 145, 174, 178, 113, 229, 251, 170, - 186, 184, 109, 13, 200, 136, 34, 241, 99, 99, 210, 172, 143, 104, 160, 99, - # Proof of integrity - 0, 199, 216, 73, 158, 82, 76, 158, 8, 215, 22, 186, 166, 45, 153, 17, 22, 251, - 133, 212, 35, 220, 155, 242, 198, 93, 133, 134, 244, 226, 122, 87, 17, - # Proof of election - 84, 71, 95, 29, 105, 203, 16, 245, 173, 18, 126, 216, 43, 32, 143, 223, 71, - 184, 247, 123, 166, 185, 137, 6, 151, 77, 251, 163, 132, 132, 235, 136, - # Fee - 0, 0, 0, 0, 0, 152, 150, 128, - # Nb transaction movements - 0, - # Nb node movements - 0, - # Nb unspent outputs, - 0, - # Nb resolved recipients, - 0, - # Nb errors - 0, - # Signature size - 64, - # Signature - 47, 48, 215, 147, 153, 120, 199, 102, 130, 0, 51, 138, 164, 146, 99, 2, 74, - 116, 89, 117, 185, 72, 109, 10, 198, 124, 44, 66, 126, 43, 85, 186, 105, 169, - 159, 56, 129, 179, 207, 176, 97, 190, 162, 240, 186, 164, 58, 41, 221, 27, - 234, 185, 105, 75, 81, 238, 158, 13, 150, 184, 31, 247, 79, 251, - # Nb cross validation stamps - 1, - # Node public key - 0, 253, 187, 69, 83, 77, 33, 173, 15, 226, 88, 230, 68, 235, 114, 146, 89, 221, - 115, 26, 63, 191, 152, 219, 245, 217, 29, 140, 42, 58, 104, 109, 108, - # Signature size - 64, - # Signature - 171, 239, 218, 149, 194, 162, 14, 64, 73, 160, 142, 149, 100, 135, 215, 48, - 133, 74, 61, 203, 113, 16, 163, 135, 41, 8, 227, 82, 131, 248, 200, 50, 113, - 195, 241, 169, 208, 28, 2, 53, 49, 141, 89, 99, 12, 189, 115, 188, 75, 11, 42, - 149, 223, 53, 234, 144, 115, 42, 99, 54, 94, 120, 25, 193, - # Nb inconsistencies - 0 - >> + <<0, 0, 0, 1, 0, 0, 120, 135, 125, 48, 92, 13, 27, 60, 42, 84, 221, 204, 42, + 196, 25, 37, 237, 215, 122, 113, 54, 59, 9, 251, 27, 179, 5, 44, 116, 217, + 180, 32, 3, 0, 0, 0, 0, 0, 0, 0, 92, 0, 98, 12, 24, 6, 0, 0, 0, 1, 0, 0, 238, + 143, 251, 13, 151, 68, 48, 247, 25, 179, 245, 118, 171, 203, 76, 243, 214, + 84, 147, 214, 174, 206, 214, 92, 218, 100, 225, 114, 163, 26, 223, 186, 0, 0, + 1, 126, 255, 61, 177, 215, 1, 0, 1, 0, 234, 193, 62, 27, 61, 132, 121, 178, + 119, 20, 124, 88, 206, 36, 125, 163, 108, 229, 219, 181, 143, 253, 246, 237, + 238, 21, 79, 9, 230, 172, 0, 95, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84, 200, + 174, 114, 81, 219, 237, 219, 237, 222, 27, 55, 149, 8, 235, 248, 37, 69, 1, + 8, 128, 139, 184, 80, 114, 82, 40, 61, 25, 169, 26, 69, 64, 83, 137, 109, 48, + 131, 81, 37, 65, 81, 210, 9, 87, 246, 107, 10, 101, 24, 218, 230, 38, 212, + 35, 242, 216, 223, 83, 224, 11, 168, 158, 5, 198, 202, 48, 233, 171, 107, + 127, 70, 206, 98, 145, 93, 119, 98, 58, 79, 206, 161, 21, 251, 218, 6, 44, + 55, 133, 13, 122, 125, 219, 122, 131, 73, 6, 64, 163, 184, 57, 242, 100, 203, + 42, 179, 241, 235, 35, 167, 197, 56, 228, 120, 110, 122, 64, 31, 230, 231, + 110, 247, 119, 139, 211, 85, 134, 192, 125, 6, 190, 51, 118, 60, 239, 190, + 15, 138, 6, 137, 87, 32, 13, 241, 26, 186, 1, 113, 112, 58, 24, 242, 140, + 245, 201, 66, 132, 213, 105, 229, 14, 2, 1, 0, 0, 1, 126, 255, 61, 215, 112, + 0, 0, 29, 150, 125, 113, 178, 225, 53, 200, 66, 6, 221, 209, 8, 181, 146, 90, + 44, 217, 156, 142, 188, 90, 181, 216, 253, 46, 201, 64, 12, 227, 201, 138, 0, + 188, 101, 205, 214, 203, 136, 90, 130, 68, 147, 79, 76, 46, 139, 19, 189, + 123, 142, 29, 113, 208, 111, 136, 227, 252, 213, 180, 80, 70, 158, 27, 148, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 64, 187, 93, 5, 6, 190, 102, 244, 88, 141, 142, 7, 138, 178, 77, 128, 21, 95, + 29, 222, 145, 211, 18, 48, 16, 185, 69, 209, 146, 56, 26, 106, 191, 101, 56, + 15, 99, 52, 179, 212, 169, 7, 30, 131, 39, 100, 115, 73, 176, 212, 121, 236, + 91, 94, 118, 108, 9, 228, 44, 237, 157, 90, 243, 90, 6, 0>> + """ @spec serialize(t()) :: bitstring() def serialize(%__MODULE__{ @@ -693,94 +651,106 @@ defmodule ArchEthic.TransactionChain.Transaction do ## Examples - iex> <<0, 0, 0, 1, 0, 62, 198, 74, 197, 246, 83, 6, 174, 95, 223, 107, 92, 12, 36, 93, 197, 197, - ...> 196, 186, 34, 34, 134, 184, 95, 181, 113, 255, 93, 134, 197, 243, 85, 253, - ...> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 61, 250, 128, 151, 100, 231, 128, 158, 139, - ...> 88, 128, 68, 236, 240, 238, 116, 186, 164, 87, 3, 60, 198, 21, 248, 64, 207, 58, 221, 192, - ...> 131, 180, 213, 64, 65, 66, 248, 246, 119, 69, 36, 103, 249, 201, 252, 154, 69, 24, 48, 18, 63, - ...> 65, 5, 10, 248, 37, 245, 101, 19, 118, 235, 82, 161, 165, 62, 43, 249, 237, - ...> 223, 226, 253, 241, 155, 33, 45, 164, 50, 14, 176, 241, 3, 107, 12, 177, 47, - ...> 20, 235, 147, 252, 28, 136, 226, 176, 180, 170, 85, 3, 151, 64, 10, 165, 166, 170, - ...> 175, 231, 164, 69, 83, 150, 36, 135, 144, 20, 104, 226, - ...> 183, 149, 250, 90, 117, 107, 162, 17, 63, 118, 229, 125, 15, 189, 245, 64, - ...> 214, 93, 126, 179, 251, 41, 101, 249, 226, 180, 88, 241, 184, 154, 181, 156, - ...> 178, 213, 132, 220, 31, 63, 23, 165, 174, 82, 182, 120, 142, 87, 34, 132, - ...> 1, 0, 0, 1, 114, 239, 88, 10, 128, 0, 0, 212, 52, 50, 200, 144, 139, 192, 177, 99, 145, 174, 178, 113, 229, 251, 170, - ...> 186, 184, 109, 13, 200, 136, 34, 241, 99, 99, 210, 172, 143, 104, 160, 99, - ...> 0, 199, 216, 73, 158, 82, 76, 158, 8, 215, 22, 186, 166, 45, 153, 17, 22, 251, - ...> 133, 212, 35, 220, 155, 242, 198, 93, 133, 134, 244, 226, 122, 87, 17, - ...> 74, 224, 26, 42, 253, 85, 104, 246, 72, 244, 189, 182, 165, 94, 92, 20, 166, - ...> 149, 124, 246, 219, 170, 160, 168, 206, 214, 236, 215, 211, 121, 95, 149, 132, - ...> 136, 114, 244, 132, 44, 255, 222, 98, 76, 247, 125, 45, 170, 95, 51, 46, 229, - ...> 21, 32, 226, 99, 16, 5, 107, 207, 32, 240, 23, 85, 219, 247, - ...> 0, 0, 0, 0, 0, 152, 150, 128, 0, 0, 0, 0, 0, 64, 47, 48, 215, 147, 153, 120, 199, - ...> 102, 130, 0, 51, 138, 164, 146, 99, 2, 74, 116, 89, 117, 185, 72, 109, 10, 198, 124, - ...> 44, 66, 126, 43, 85, 186, 105, 169, 159, 56, 129, 179, 207, 176, 97, 190, 162, 240, - ...> 186, 164, 58, 41, 221, 27, 234, 185, 105, 75, 81, 238, 158, 13, 150, 184, 31, 247, 79, 251, - ...> 1, 0, 0, 253, 187, 69, 83, 77, 33, 173, 15, 226, 88, 230, 68, 235, 114, 146, 89, 221, - ...> 115, 26, 63, 191, 152, 219, 245, 217, 29, 140, 42, 58, 104, 109, 108, - ...> 64, 171, 239, 218, 149, 194, 162, 14, 64, 73, 160, 142, 149, 100, 135, 215, 48, - ...> 133, 74, 61, 203, 113, 16, 163, 135, 41, 8, 227, 82, 131, 248, 200, 50, 113, - ...> 195, 241, 169, 208, 28, 2, 53, 49, 141, 89, 99, 12, 189, 115, 188, 75, 11, 42, - ...> 149, 223, 53, 234, 144, 115, 42, 99, 54, 94, 120, 25, 193, 0>> + iex> <<0, 0, 0, 1, 0, 0, 120, 135, 125, 48, 92, 13, 27, 60, 42, 84, 221, 204, 42, + ...> 196, 25, 37, 237, 215, 122, 113, 54, 59, 9, 251, 27, 179, 5, 44, 116, 217, + ...> 180, 32, 3, 0, 0, 0, 0, 0, 0, 0, 92, 0, 98, 12, 24, 6, 0, 0, 0, 1, 0, 0, 238, + ...> 143, 251, 13, 151, 68, 48, 247, 25, 179, 245, 118, 171, 203, 76, 243, 214, + ...> 84, 147, 214, 174, 206, 214, 92, 218, 100, 225, 114, 163, 26, 223, 186, 0, 0, + ...> 1, 126, 255, 61, 177, 215, 1, 0, 1, 0, 234, 193, 62, 27, 61, 132, 121, 178, + ...> 119, 20, 124, 88, 206, 36, 125, 163, 108, 229, 219, 181, 143, 253, 246, 237, + ...> 238, 21, 79, 9, 230, 172, 0, 95, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84, 200, + ...> 174, 114, 81, 219, 237, 219, 237, 222, 27, 55, 149, 8, 235, 248, 37, 69, 1, + ...> 8, 128, 139, 184, 80, 114, 82, 40, 61, 25, 169, 26, 69, 64, 83, 137, 109, 48, + ...> 131, 81, 37, 65, 81, 210, 9, 87, 246, 107, 10, 101, 24, 218, 230, 38, 212, + ...> 35, 242, 216, 223, 83, 224, 11, 168, 158, 5, 198, 202, 48, 233, 171, 107, + ...> 127, 70, 206, 98, 145, 93, 119, 98, 58, 79, 206, 161, 21, 251, 218, 6, 44, + ...> 55, 133, 13, 122, 125, 219, 122, 131, 73, 6, 64, 163, 184, 57, 242, 100, 203, + ...> 42, 179, 241, 235, 35, 167, 197, 56, 228, 120, 110, 122, 64, 31, 230, 231, + ...> 110, 247, 119, 139, 211, 85, 134, 192, 125, 6, 190, 51, 118, 60, 239, 190, + ...> 15, 138, 6, 137, 87, 32, 13, 241, 26, 186, 1, 113, 112, 58, 24, 242, 140, + ...> 245, 201, 66, 132, 213, 105, 229, 14, 2, 1, 0, 0, 1, 126, 255, 61, 215, 112, + ...> 0, 0, 29, 150, 125, 113, 178, 225, 53, 200, 66, 6, 221, 209, 8, 181, 146, 90, + ...> 44, 217, 156, 142, 188, 90, 181, 216, 253, 46, 201, 64, 12, 227, 201, 138, 0, + ...> 188, 101, 205, 214, 203, 136, 90, 130, 68, 147, 79, 76, 46, 139, 19, 189, + ...> 123, 142, 29, 113, 208, 111, 136, 227, 252, 213, 180, 80, 70, 158, 27, 148, + ...> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ...> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ...> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ...> 64, 187, 93, 5, 6, 190, 102, 244, 88, 141, 142, 7, 138, 178, 77, 128, 21, 95, + ...> 29, 222, 145, 211, 18, 48, 16, 185, 69, 209, 146, 56, 26, 106, 191, 101, 56, + ...> 15, 99, 52, 179, 212, 169, 7, 30, 131, 39, 100, 115, 73, 176, 212, 121, 236, + ...> 91, 94, 118, 108, 9, 228, 44, 237, 157, 90, 243, 90, 6, 0>> ...> |> Transaction.deserialize() { %Transaction{ - version: 1, - address: <<0, 62, 198, 74, 197, 246, 83, 6, 174, 95, 223, 107, 92, 12, 36, 93, 197, 197, - 196, 186, 34, 34, 134, 184, 95, 181, 113, 255, 93, 134, 197, 243, 85>>, - type: :transfer, - data: %TransactionData{}, - previous_public_key: <<0, 0, 61, 250, 128, 151, 100, 231, 128, 158, 139, 88, 128, 68, 236, 240, 238, 116, - 186, 164, 87, 3, 60, 198, 21, 248, 64, 207, 58, 221, 192, 131, 180, 213>>, - previous_signature: <<65, 66, 248, 246, 119, 69, 36, 103, 249, 201, 252, 154, 69, 24, 48, 18, 63, - 65, 5, 10, 248, 37, 245, 101, 19, 118, 235, 82, 161, 165, 62, 43, 249, 237, - 223, 226, 253, 241, 155, 33, 45, 164, 50, 14, 176, 241, 3, 107, 12, 177, 47, - 20, 235, 147, 252, 28, 136, 226, 176, 180, 170, 85, 3, 151>>, - origin_signature: <<10, 165, 166, 170, 175, 231, 164, 69, 83, 150, 36, 135, 144, 20, 104, 226, - 183, 149, 250, 90, 117, 107, 162, 17, 63, 118, 229, 125, 15, 189, 245, 64, - 214, 93, 126, 179, 251, 41, 101, 249, 226, 180, 88, 241, 184, 154, 181, 156, - 178, 213, 132, 220, 31, 63, 23, 165, 174, 82, 182, 120, 142, 87, 34, 132>>, - validation_stamp: %ValidationStamp{ - timestamp: ~U[2020-06-26 06:37:04.000Z], - proof_of_work: <<0, 0, 212, 52, 50, 200, 144, 139, 192, 177, 99, 145, 174, 178, 113, 229, 251, 170, - 186, 184, 109, 13, 200, 136, 34, 241, 99, 99, 210, 172, 143, 104, 160, 99>>, - proof_of_integrity: <<0, 199, 216, 73, 158, 82, 76, 158, 8, 215, 22, 186, 166, 45, 153, 17, 22, 251, - 133, 212, 35, 220, 155, 242, 198, 93, 133, 134, 244, 226, 122, 87, 17>>, - proof_of_election: <<74, 224, 26, 42, 253, 85, 104, 246, 72, 244, 189, 182, 165, 94, 92, 20, 166, - 149, 124, 246, 219, 170, 160, 168, 206, 214, 236, 215, 211, 121, 95, 149, 132, - 136, 114, 244, 132, 44, 255, 222, 98, 76, 247, 125, 45, 170, 95, 51, 46, 229, - 21, 32, 226, 99, 16, 5, 107, 207, 32, 240, 23, 85, 219, 247>>, - ledger_operations: %LedgerOperations{ - fee: 10_000_000, - transaction_movements: [], - node_movements: [], - unspent_outputs: [] - }, - errors: [], - recipients: [], - signature: <<47, 48, 215, 147, 153, 120, 199, 102, 130, 0, 51, 138, 164, 146, 99, 2, 74, - 116, 89, 117, 185, 72, 109, 10, 198, 124, 44, 66, 126, 43, 85, 186, 105, 169, - 159, 56, 129, 179, 207, 176, 97, 190, 162, 240, 186, 164, 58, 41, 221, 27, - 234, 185, 105, 75, 81, 238, 158, 13, 150, 184, 31, 247, 79, 251>> + address: <<0, 0, 120, 135, 125, 48, 92, 13, 27, 60, 42, 84, 221, 204, 42, 196, + 25, 37, 237, 215, 122, 113, 54, 59, 9, 251, 27, 179, 5, 44, 116, 217, 180, + 32>>, + cross_validation_stamps: [], + data: %ArchEthic.TransactionChain.TransactionData{ + code: "", + content: <<0, 98, 12, 24, 6, 0, 0, 0, 1, 0, 0, 238, 143, 251, 13, 151, 68, + 48, 247, 25, 179, 245, 118, 171, 203, 76, 243, 214, 84, 147, 214, 174, + 206, 214, 92, 218, 100, 225, 114, 163, 26, 223, 186, 0, 0, 1, 126, 255, + 61, 177, 215, 1, 0, 1, 0, 234, 193, 62, 27, 61, 132, 121, 178, 119, 20, + 124, 88, 206, 36, 125, 163, 108, 229, 219, 181, 143, 253, 246, 237, 238, + 21, 79, 9, 230, 172, 0, 95, 0, 0, 0, 0, 0>>, + ledger: %ArchEthic.TransactionChain.TransactionData.Ledger{ + nft: %ArchEthic.TransactionChain.TransactionData.NFTLedger{transfers: []}, + uco: %ArchEthic.TransactionChain.TransactionData.UCOLedger{transfers: []} + }, + ownerships: [], + recipients: [] + }, + origin_signature: <<163, 184, 57, 242, 100, 203, 42, 179, 241, 235, 35, 167, + 197, 56, 228, 120, 110, 122, 64, 31, 230, 231, 110, 247, 119, 139, 211, 85, + 134, 192, 125, 6, 190, 51, 118, 60, 239, 190, 15, 138, 6, 137, 87, 32, 13, + 241, 26, 186, 1, 113, 112, 58, 24, 242, 140, 245, 201, 66, 132, 213, 105, + 229, 14, 2>>, + previous_public_key: <<0, 0, 84, 200, 174, 114, 81, 219, 237, 219, 237, 222, + 27, 55, 149, 8, 235, 248, 37, 69, 1, 8, 128, 139, 184, 80, 114, 82, 40, 61, + 25, 169, 26, 69>>, + previous_signature: <<83, 137, 109, 48, 131, 81, 37, 65, 81, 210, 9, 87, 246, + 107, 10, 101, 24, 218, 230, 38, 212, 35, 242, 216, 223, 83, 224, 11, 168, + 158, 5, 198, 202, 48, 233, 171, 107, 127, 70, 206, 98, 145, 93, 119, 98, 58, + 79, 206, 161, 21, 251, 218, 6, 44, 55, 133, 13, 122, 125, 219, 122, 131, 73, + 6>>, + type: :beacon, + validation_stamp: %ArchEthic.TransactionChain.Transaction.ValidationStamp{ + errors: [], + ledger_operations: %ArchEthic.TransactionChain.Transaction.ValidationStamp.LedgerOperations{ + fee: 0, + node_movements: [], + transaction_movements: [], + unspent_outputs: [] + }, + proof_of_election: <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>, + proof_of_integrity: <<0, 188, 101, 205, 214, 203, 136, 90, 130, 68, 147, 79, + 76, 46, 139, 19, 189, 123, 142, 29, 113, 208, 111, 136, 227, 252, 213, + 180, 80, 70, 158, 27, 148>>, + proof_of_work: <<0, 0, 29, 150, 125, 113, 178, 225, 53, 200, 66, 6, 221, + 209, 8, 181, 146, 90, 44, 217, 156, 142, 188, 90, 181, 216, 253, 46, 201, + 64, 12, 227, 201, 138>>, + recipients: [], + signature: <<187, 93, 5, 6, 190, 102, 244, 88, 141, 142, 7, 138, 178, 77, + 128, 21, 95, 29, 222, 145, 211, 18, 48, 16, 185, 69, 209, 146, 56, 26, + 106, 191, 101, 56, 15, 99, 52, 179, 212, 169, 7, 30, 131, 39, 100, 115, + 73, 176, 212, 121, 236, 91, 94, 118, 108, 9, 228, 44, 237, 157, 90, 243, + 90, 6>>, + timestamp: ~U[2022-02-15 21:15:50.000Z] }, - cross_validation_stamps: [ - %CrossValidationStamp{ - node_public_key: <<0, 0, 253, 187, 69, 83, 77, 33, 173, 15, 226, 88, 230, 68, 235, 114, 146, 89, 221, - 115, 26, 63, 191, 152, 219, 245, 217, 29, 140, 42, 58, 104, 109, 108>>, - signature: <<171, 239, 218, 149, 194, 162, 14, 64, 73, 160, 142, 149, 100, 135, 215, 48, - 133, 74, 61, 203, 113, 16, 163, 135, 41, 8, 227, 82, 131, 248, 200, 50, 113, - 195, 241, 169, 208, 28, 2, 53, 49, 141, 89, 99, 12, 189, 115, 188, 75, 11, 42, - 149, 223, 53, 234, 144, 115, 42, 99, 54, 94, 120, 25, 193>>, - inconsistencies: [] - } - ] + version: 1 }, "" } + """ @spec deserialize(bitstring()) :: {transaction :: t(), rest :: bitstring} - def deserialize(_serialized_term = <>) do + def deserialize( + _serialized_term = <> + ) do address_size = Crypto.hash_size(hash_algo) <> = rest @@ -795,7 +765,7 @@ defmodule ArchEthic.TransactionChain.Transaction do tx = %__MODULE__{ version: version, - address: <>, + address: <>, type: parse_type(type), data: data, previous_public_key: <>, diff --git a/test/archethic/p2p/messages_test.exs b/test/archethic/p2p/messages_test.exs index 4f9d7ab14..4144fa460 100644 --- a/test/archethic/p2p/messages_test.exs +++ b/test/archethic/p2p/messages_test.exs @@ -85,7 +85,7 @@ defmodule ArchEthic.P2P.MessageTest do end test "GetTransaction message" do - address = <<0::8>> <> :crypto.strong_rand_bytes(32) + address = <<0::8>> <> <<0::8>> <> :crypto.strong_rand_bytes(32) assert %GetTransaction{address: address} == %GetTransaction{address: address} @@ -95,7 +95,7 @@ defmodule ArchEthic.P2P.MessageTest do end test "GetTransactionChain message" do - address = <<0::8>> <> :crypto.strong_rand_bytes(32) + address = <<0::8>> <> <<0::8>> <> :crypto.strong_rand_bytes(32) assert %GetTransactionChain{address: address} == %GetTransactionChain{address: address} @@ -105,7 +105,7 @@ defmodule ArchEthic.P2P.MessageTest do end test "GetUnspentOutputs message" do - address = <<0::8>> <> :crypto.strong_rand_bytes(32) + address = <<0::8>> <> <<0::8>> <> :crypto.strong_rand_bytes(32) assert %GetUnspentOutputs{address: address} == %GetUnspentOutputs{address: address} @@ -255,8 +255,8 @@ defmodule ArchEthic.P2P.MessageTest do msg = %ReplicateTransaction{ transaction: %Transaction{ address: - <<0, 46, 140, 65, 49, 7, 111, 10, 130, 53, 72, 25, 43, 47, 81, 130, 161, 225, 87, 144, - 186, 117, 170, 105, 205, 173, 102, 49, 176, 8, 45, 49, 82>>, + <<0, 0, 46, 140, 65, 49, 7, 111, 10, 130, 53, 72, 25, 43, 47, 81, 130, 161, 225, 87, + 144, 186, 117, 170, 105, 205, 173, 102, 49, 176, 8, 45, 49, 82>>, type: :transfer, data: %TransactionData{}, previous_public_key: @@ -332,7 +332,7 @@ defmodule ArchEthic.P2P.MessageTest do end test "AcknowledgeStorage message" do - address = <<0::8>> <> :crypto.strong_rand_bytes(32) + address = <<0::8>> <> <<0::8>> <> :crypto.strong_rand_bytes(32) assert %AcknowledgeStorage{ address: address @@ -361,7 +361,7 @@ defmodule ArchEthic.P2P.MessageTest do end test "GetLastTransaction message" do - address = <<0::8>> <> :crypto.strong_rand_bytes(32) + address = <<0::8>> <> <<0::8>> <> :crypto.strong_rand_bytes(32) assert %GetLastTransaction{ address: address @@ -375,7 +375,7 @@ defmodule ArchEthic.P2P.MessageTest do end test "GetBalance message" do - address = <<0::8>> <> :crypto.strong_rand_bytes(32) + address = <<0::8>> <> <<0::8>> <> :crypto.strong_rand_bytes(32) assert %GetBalance{ address: address @@ -389,7 +389,7 @@ defmodule ArchEthic.P2P.MessageTest do end test "GetTransactionInputs message" do - address = <<0::8>> <> :crypto.strong_rand_bytes(32) + address = <<0::8>> <> <<0::8>> <> :crypto.strong_rand_bytes(32) assert %GetTransactionInputs{ address: address @@ -425,7 +425,7 @@ defmodule ArchEthic.P2P.MessageTest do transactions: [ %Transaction{ address: - <<0, 46, 140, 65, 49, 7, 111, 10, 130, 53, 72, 25, 43, 47, 81, 130, 161, 225, 87, + <<0, 0, 46, 140, 65, 49, 7, 111, 10, 130, 53, 72, 25, 43, 47, 81, 130, 161, 225, 87, 144, 186, 117, 170, 105, 205, 173, 102, 49, 176, 8, 45, 49, 82>>, type: :transfer, data: %TransactionData{}, @@ -652,7 +652,7 @@ defmodule ArchEthic.P2P.MessageTest do end test "GetTransactionChainLength message" do - address = <<0::8>> <> :crypto.strong_rand_bytes(32) + address = <<0::8>> <> <<0::8>> <> :crypto.strong_rand_bytes(32) msg = %GetTransactionChainLength{ address: address @@ -735,7 +735,7 @@ defmodule ArchEthic.P2P.MessageTest do test "GetFirstPublicKey message" do msg = %GetFirstPublicKey{ - address: <<0::8, :crypto.strong_rand_bytes(32)::binary>> + address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> } assert msg == @@ -759,7 +759,7 @@ defmodule ArchEthic.P2P.MessageTest do test "GetLastTransactionAddress message" do msg = %GetLastTransactionAddress{ - address: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, + address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, timestamp: DateTime.truncate(DateTime.utc_now(), :second) } @@ -772,7 +772,7 @@ defmodule ArchEthic.P2P.MessageTest do test "LastTransactionAddress message" do msg = %LastTransactionAddress{ - address: <<0::8, :crypto.strong_rand_bytes(32)::binary>> + address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> } assert msg == @@ -784,7 +784,7 @@ defmodule ArchEthic.P2P.MessageTest do test "NotifyLastTransactionAddress message" do msg = %NotifyLastTransactionAddress{ - address: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, + address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, previous_address: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, timestamp: DateTime.utc_now() |> DateTime.truncate(:second) } @@ -798,7 +798,7 @@ defmodule ArchEthic.P2P.MessageTest do test "GetTransactionSummary message" do msg = %GetTransactionSummary{ - address: <<0::8, :crypto.strong_rand_bytes(32)::binary>> + address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> } assert msg == diff --git a/test/archethic/transaction_chain/transaction_test.exs b/test/archethic/transaction_chain/transaction_test.exs index 26851fe80..9d5c866d7 100644 --- a/test/archethic/transaction_chain/transaction_test.exs +++ b/test/archethic/transaction_chain/transaction_test.exs @@ -5,8 +5,8 @@ defmodule ArchEthic.TransactionChain.TransactionTest do alias ArchEthic.TransactionChain.Transaction alias ArchEthic.TransactionChain.Transaction.CrossValidationStamp - alias ArchEthic.TransactionChain.Transaction.ValidationStamp - alias ArchEthic.TransactionChain.Transaction.ValidationStamp.LedgerOperations + # alias ArchEthic.TransactionChain.Transaction.ValidationStamp + # alias ArchEthic.TransactionChain.Transaction.ValidationStamp.LedgerOperations alias ArchEthic.TransactionChain.Transaction.ValidationStamp.LedgerOperations.TransactionMovement From ab4553b826bab62215915ca9108237ec1ff0527f Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 16 Feb 2022 13:35:33 +0100 Subject: [PATCH 07/20] Fix shared secrets tests --- docker-compose.yml | 1 + lib/archethic/shared_secrets/node_renewal.ex | 6 ++++-- .../shared_secrets/mem_tables_loader_test.exs | 14 +++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 889a3328c..478c5ef43 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -232,6 +232,7 @@ services: networks: archethic_net: + name: archethic_net ipam: driver: default config: diff --git a/lib/archethic/shared_secrets/node_renewal.ex b/lib/archethic/shared_secrets/node_renewal.ex index 9e6c7aaea..2586145a0 100644 --- a/lib/archethic/shared_secrets/node_renewal.ex +++ b/lib/archethic/shared_secrets/node_renewal.ex @@ -120,11 +120,13 @@ defmodule ArchEthic.SharedSecrets.NodeRenewal do with <> <- content, daily_nonce_public_key_size <- Crypto.key_size(curve_id), <> <- rest, + network_pool_address_curve_id::8, network_pool_address_hash_id::8, + rest::binary>> <- rest, network_pool_address_size <- Crypto.hash_size(network_pool_address_hash_id), <> <- rest do {:ok, <>, - <>} + <>} else _ -> :error diff --git a/test/archethic/shared_secrets/mem_tables_loader_test.exs b/test/archethic/shared_secrets/mem_tables_loader_test.exs index d3e0e0347..bba731609 100644 --- a/test/archethic/shared_secrets/mem_tables_loader_test.exs +++ b/test/archethic/shared_secrets/mem_tables_loader_test.exs @@ -97,9 +97,9 @@ defmodule ArchEthic.SharedSecrets.MemTablesLoaderTest do data: %TransactionData{ content: <<0, 0, 134, 118, 192, 4, 151, 93, 80, 114, 78, 96, 104, 42, 113, 76, 22, 142, 79, - 138, 169, 159, 93, 80, 246, 65, 59, 171, 182, 223, 96, 3, 170, 1, 0, 134, 118, 192, - 4, 151, 93, 80, 114, 78, 96, 104, 42, 113, 76, 22, 142, 79, 138, 169, 159, 93, 80, - 246, 65, 59, 171, 182, 223, 96, 3, 170, 18>> + 138, 169, 159, 93, 80, 246, 65, 59, 171, 182, 223, 96, 3, 170, 1, 0, 0, 134, 118, + 192, 4, 151, 93, 80, 114, 78, 96, 104, 42, 113, 76, 22, 142, 79, 138, 169, 159, 93, + 80, 246, 65, 59, 171, 182, 223, 96, 3, 170, 18>> }, validation_stamp: %ValidationStamp{ timestamp: DateTime.utc_now() |> DateTime.add(10) @@ -119,7 +119,7 @@ defmodule ArchEthic.SharedSecrets.MemTablesLoaderTest do ) assert NetworkLookup.get_network_pool_address() == - <<0, 134, 118, 192, 4, 151, 93, 80, 114, 78, 96, 104, 42, 113, 76, 22, 142, 79, + <<0, 0, 134, 118, 192, 4, 151, 93, 80, 114, 78, 96, 104, 42, 113, 76, 22, 142, 79, 138, 169, 159, 93, 80, 246, 65, 59, 171, 182, 223, 96, 3, 170, 18>> end end @@ -149,9 +149,9 @@ defmodule ArchEthic.SharedSecrets.MemTablesLoaderTest do data: %TransactionData{ content: <<0, 0, 134, 118, 192, 4, 151, 93, 80, 114, 78, 96, 104, 42, 113, 76, 22, 142, 79, - 138, 169, 159, 93, 80, 246, 65, 59, 171, 182, 223, 96, 3, 170, 18, 0, 134, 118, 192, - 4, 151, 93, 80, 114, 78, 96, 104, 42, 113, 76, 22, 142, 79, 138, 169, 159, 93, 80, - 246, 65, 59, 171, 182, 223, 96, 3, 170, 18>> + 138, 169, 159, 93, 80, 246, 65, 59, 171, 182, 223, 96, 3, 170, 18, 0, 0, 134, 118, + 192, 4, 151, 93, 80, 114, 78, 96, 104, 42, 113, 76, 22, 142, 79, 138, 169, 159, 93, + 80, 246, 65, 59, 171, 182, 223, 96, 3, 170, 18>> }, validation_stamp: %ValidationStamp{ timestamp: DateTime.utc_now() |> DateTime.add(10) From fa6e48309e7080b1299fdfaaea7fb01910585f44 Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 16 Feb 2022 13:37:52 +0100 Subject: [PATCH 08/20] Fix crypto tests --- lib/archethic/crypto.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/archethic/crypto.ex b/lib/archethic/crypto.ex index f507ff9fe..0e391a2b3 100755 --- a/lib/archethic/crypto.ex +++ b/lib/archethic/crypto.ex @@ -1062,7 +1062,7 @@ defmodule ArchEthic.Crypto do end def load_transaction(%Transaction{type: :node, address: address}) do - if NodeKeystore.next_public_key() |> hash() == address do + if derive_address(NodeKeystore.next_public_key()) == address do Logger.debug("Node next keypair loaded", transaction_address: Base.encode16(address), transaction_type: :node From a435ca86da929dc8056a47c3ae56fd199472a566 Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 16 Feb 2022 13:43:16 +0100 Subject: [PATCH 09/20] Fix beacon tests --- lib/archethic/beacon_chain/slot.ex | 14 +++++++------- .../beacon_chain/slot/transaction_summary.ex | 13 +++++++------ test/archethic/beacon_chain/subset_test.exs | 18 +++++++++--------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/archethic/beacon_chain/slot.ex b/lib/archethic/beacon_chain/slot.ex index d2667938e..a01410cc5 100644 --- a/lib/archethic/beacon_chain/slot.ex +++ b/lib/archethic/beacon_chain/slot.ex @@ -172,7 +172,7 @@ defmodule ArchEthic.BeaconChain.Slot do ...> slot_time: ~U[2021-01-20 10:10:00Z], ...> transaction_summaries: [ ...> %TransactionSummary{ - ...> address: <<0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, + ...> address: <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, ...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>, ...> timestamp: ~U[2020-06-25 15:11:53Z], ...> type: :transfer, @@ -201,7 +201,7 @@ defmodule ArchEthic.BeaconChain.Slot do # Nb transaction summaries 0, 0, 0, 1, # Address - 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, + 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12, # Timestamp 0, 0, 1, 114, 236, 9, 2, 168, @@ -270,7 +270,7 @@ defmodule ArchEthic.BeaconChain.Slot do ## Examples iex> <<0, 96, 8, 1, 120, 0, 0, 0, 1, - ...> 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, + ...> 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, ...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12, ...> 0, 0, 1, 114, 236, 9, 2, 168, 253, 0, 0, ...> 0, 1, 0, 0, 38, 105, 235, 147, 234, 114, 41, 1, 152, 148, 120, 31, 200, 255, 174, 190, 91, @@ -284,7 +284,7 @@ defmodule ArchEthic.BeaconChain.Slot do slot_time: ~U[2021-01-20 10:10:00Z], transaction_summaries: [ %TransactionSummary{ - address: <<0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, + address: <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>>, timestamp: ~U[2020-06-25 15:11:53.000Z], type: :transfer, @@ -385,20 +385,20 @@ defmodule ArchEthic.BeaconChain.Slot do iex> %Slot{ ...> transaction_summaries: [] ...> } - ...> |> Slot.has_transaction?(<<0, 202, 39, 113, 5, 117, 133, 141, 107, 1, 202, 156, 250, 124, 22, 13, 183, 20, + ...> |> Slot.has_transaction?(<<0, 0, 202, 39, 113, 5, 117, 133, 141, 107, 1, 202, 156, 250, 124, 22, 13, 183, 20, ...> 221, 181, 252, 153, 184, 2, 26, 115, 73, 148, 163, 119, 163, 86, 6>>) false iex> %Slot{ ...> transaction_summaries: [%TransactionSummary{ - ...> address: <<0, 202, 39, 113, 5, 117, 133, 141, 107, 1, 202, 156, 250, 124, 22, 13, 183, 20, + ...> address: <<0, 0, 202, 39, 113, 5, 117, 133, 141, 107, 1, 202, 156, 250, 124, 22, 13, 183, 20, ...> 221, 181, 252, 153, 184, 2, 26, 115, 73, 148, 163, 119, 163, 86, 6>>, ...> timestamp: ~U[2020-06-25 15:11:53Z], ...> type: :transfer, ...> movements_addresses: [] ...> }] ...> } - ...> |> Slot.has_transaction?(<<0, 202, 39, 113, 5, 117, 133, 141, 107, 1, 202, 156, 250, 124, 22, 13, 183, 20, + ...> |> Slot.has_transaction?(<<0, 0, 202, 39, 113, 5, 117, 133, 141, 107, 1, 202, 156, 250, 124, 22, 13, 183, 20, ...> 221, 181, 252, 153, 184, 2, 26, 115, 73, 148, 163, 119, 163, 86, 6>>) true """ diff --git a/lib/archethic/beacon_chain/slot/transaction_summary.ex b/lib/archethic/beacon_chain/slot/transaction_summary.ex index fb740ef0b..ed61da61a 100644 --- a/lib/archethic/beacon_chain/slot/transaction_summary.ex +++ b/lib/archethic/beacon_chain/slot/transaction_summary.ex @@ -47,7 +47,7 @@ defmodule ArchEthic.BeaconChain.Slot.TransactionSummary do ...> timestamp: ~U[2020-06-25 15:11:53Z], ...> type: :transfer, ...> movements_addresses: [ - ...> <<0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, + ...> <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, ...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>> ...> ] ...> } @@ -63,7 +63,7 @@ defmodule ArchEthic.BeaconChain.Slot.TransactionSummary do # Nb movements addresses 0, 1, # Movement address - 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, + 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12 >> """ @@ -86,7 +86,7 @@ defmodule ArchEthic.BeaconChain.Slot.TransactionSummary do iex> <<0, 0, 11, 4, 226, 118, 242, 59, 165, 128, 69, 40, 228, 121, 127, 37, 154, 199, ...> 168, 212, 53, 82, 220, 22, 56, 222, 223, 127, 16, 172, 142, 218, 41, 247, 0, 0, 1, 114, 236, 9, 2, 168, - ...> 253, 0, 1, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, + ...> 253, 0, 1, 0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, ...> 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>> ...> |> TransactionSummary.deserialize() { @@ -96,7 +96,7 @@ defmodule ArchEthic.BeaconChain.Slot.TransactionSummary do timestamp: ~U[2020-06-25 15:11:53.000Z], type: :transfer, movements_addresses: [ - <<0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, + <<0, 0, 234, 233, 156, 155, 114, 241, 116, 246, 27, 130, 162, 205, 249, 65, 232, 166, 99, 207, 133, 252, 112, 223, 41, 12, 206, 162, 233, 28, 49, 204, 255, 12>> ] }, @@ -129,10 +129,11 @@ defmodule ArchEthic.BeaconChain.Slot.TransactionSummary do {Enum.reverse(acc), rest} end - defp deserialize_addresses(<>, nb_addresses, acc) do + defp deserialize_addresses(<>, nb_addresses, acc) do hash_size = Crypto.hash_size(hash_id) <> = rest - deserialize_addresses(rest, nb_addresses, [<> | acc]) + + deserialize_addresses(rest, nb_addresses, [<> | acc]) end @spec to_map(t()) :: map() diff --git a/test/archethic/beacon_chain/subset_test.exs b/test/archethic/beacon_chain/subset_test.exs index e836a486f..7548d1b62 100644 --- a/test/archethic/beacon_chain/subset_test.exs +++ b/test/archethic/beacon_chain/subset_test.exs @@ -67,7 +67,7 @@ defmodule ArchEthic.BeaconChain.SubsetTest do test "new slot is created when receive a :create_slot message", %{subset: subset, pid: pid} do tx_time = DateTime.utc_now() - tx_address = <<0::8, :crypto.strong_rand_bytes(32)::binary>> + tx_address = <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> P2P.add_and_connect_node(%Node{ ip: {127, 0, 0, 1}, @@ -98,10 +98,10 @@ defmodule ArchEthic.BeaconChain.SubsetTest do timestamp: tx_time, type: :keychain, movements_addresses: [ - <<0, 109, 2, 63, 124, 238, 101, 213, 214, 64, 58, 218, 10, 35, 62, 202, 12, 64, 11, 232, - 210, 105, 102, 193, 193, 24, 54, 42, 200, 226, 13, 38, 69>>, - <<0, 8, 253, 201, 142, 182, 78, 169, 132, 29, 19, 74, 3, 142, 207, 219, 127, 147, 40, 24, - 44, 170, 214, 171, 224, 29, 177, 205, 226, 88, 62, 248, 84>> + <<0, 0, 109, 2, 63, 124, 238, 101, 213, 214, 64, 58, 218, 10, 35, 62, 202, 12, 64, 11, + 232, 210, 105, 102, 193, 193, 24, 54, 42, 200, 226, 13, 38, 69>>, + <<0, 0, 8, 253, 201, 142, 182, 78, 169, 132, 29, 19, 74, 3, 142, 207, 219, 127, 147, 40, + 24, 44, 170, 214, 171, 224, 29, 177, 205, 226, 88, 62, 248, 84>> ] }) @@ -180,10 +180,10 @@ defmodule ArchEthic.BeaconChain.SubsetTest do timestamp: tx_time, type: :keychain, movements_addresses: [ - <<0, 109, 2, 63, 124, 238, 101, 213, 214, 64, 58, 218, 10, 35, 62, 202, 12, 64, 11, 232, - 210, 105, 102, 193, 193, 24, 54, 42, 200, 226, 13, 38, 69>>, - <<0, 8, 253, 201, 142, 182, 78, 169, 132, 29, 19, 74, 3, 142, 207, 219, 127, 147, 40, 24, - 44, 170, 214, 171, 224, 29, 177, 205, 226, 88, 62, 248, 84>> + <<0, 0, 109, 2, 63, 124, 238, 101, 213, 214, 64, 58, 218, 10, 35, 62, 202, 12, 64, 11, + 232, 210, 105, 102, 193, 193, 24, 54, 42, 200, 226, 13, 38, 69>>, + <<0, 0, 8, 253, 201, 142, 182, 78, 169, 132, 29, 19, 74, 3, 142, 207, 219, 127, 147, 40, + 24, 44, 170, 214, 171, 224, 29, 177, 205, 226, 88, 62, 248, 84>> ] } From ff1e9767528e708663dbff7db9f2ee33a1bd0176 Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 16 Feb 2022 13:56:03 +0100 Subject: [PATCH 10/20] Fix contract tests --- test/archethic/contracts/loader_test.exs | 42 ++++++++++++++++-------- test/archethic/contracts/worker_test.exs | 4 +-- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/test/archethic/contracts/loader_test.exs b/test/archethic/contracts/loader_test.exs index 389fb1702..fc75335e6 100644 --- a/test/archethic/contracts/loader_test.exs +++ b/test/archethic/contracts/loader_test.exs @@ -20,8 +20,13 @@ defmodule ArchEthic.Contracts.LoaderTest do describe "load_transaction/1" do test "should create a supervised worker for the given transaction with contract code" do + {pub0, _} = Crypto.derive_keypair("contract1_seed", 0) + {pub1, _} = Crypto.derive_keypair("contract1_seed", 1) + + contract_address = Crypto.derive_address(pub1) + tx = %Transaction{ - address: "@SC1", + address: contract_address, data: %TransactionData{ code: """ condition transaction: [ @@ -37,11 +42,11 @@ defmodule ArchEthic.Contracts.LoaderTest do end """ }, - previous_public_key: "" + previous_public_key: pub0 } assert :ok = Loader.load_transaction(tx) - [{pid, _}] = Registry.lookup(ContractRegistry, "@SC1") + [{pid, _}] = Registry.lookup(ContractRegistry, contract_address) assert Enum.any?( DynamicSupervisor.which_children(ContractSupervisor), @@ -51,14 +56,18 @@ defmodule ArchEthic.Contracts.LoaderTest do assert %{ contract: %Contract{ triggers: [%Trigger{type: :transaction}], - constants: %Constants{contract: %{"address" => "@SC1"}} + constants: %Constants{contract: %{"address" => ^contract_address}} } } = :sys.get_state(pid) end test "should stop a previous contract for the same chain" do + {pub0, _} = Crypto.derive_keypair("contract2_seed", 0) + {pub1, _} = Crypto.derive_keypair("contract2_seed", 1) + {pub2, _} = Crypto.derive_keypair("contract2_seed", 2) + tx1 = %Transaction{ - address: Crypto.hash("Alice2"), + address: Crypto.derive_address(pub1), data: %TransactionData{ code: """ condition transaction: [ @@ -74,11 +83,11 @@ defmodule ArchEthic.Contracts.LoaderTest do end """ }, - previous_public_key: "Alice1" + previous_public_key: pub0 } tx2 = %Transaction{ - address: Crypto.hash("Alice3"), + address: Crypto.derive_address(pub2), data: %TransactionData{ code: """ condition transaction: [ @@ -94,7 +103,7 @@ defmodule ArchEthic.Contracts.LoaderTest do end """ }, - previous_public_key: "Alice2" + previous_public_key: pub1 } assert :ok = Loader.load_transaction(tx1) @@ -113,14 +122,19 @@ defmodule ArchEthic.Contracts.LoaderTest do end test "start_link/1 should load smart contract from DB" do + {pub0, _} = Crypto.derive_keypair("contract3_seed", 0) + {pub1, _} = Crypto.derive_keypair("contract3_seed", 1) + + contract_address = Crypto.derive_address(pub1) + MockDB |> stub(:list_last_transaction_addresses, fn -> - ["@SC2"] + [contract_address] end) - |> stub(:get_transaction, fn "@SC2", _ -> + |> stub(:get_transaction, fn ^contract_address, _ -> {:ok, %Transaction{ - address: "@SC2", + address: contract_address, data: %TransactionData{ code: """ condition transaction: [ @@ -136,12 +150,12 @@ defmodule ArchEthic.Contracts.LoaderTest do end """ }, - previous_public_key: "" + previous_public_key: pub0 }} end) assert {:ok, _} = Loader.start_link() - [{pid, _}] = Registry.lookup(ContractRegistry, "@SC2") + [{pid, _}] = Registry.lookup(ContractRegistry, contract_address) assert Enum.any?( DynamicSupervisor.which_children(ContractSupervisor), @@ -151,7 +165,7 @@ defmodule ArchEthic.Contracts.LoaderTest do assert %{ contract: %Contract{ triggers: [%Trigger{type: :transaction}], - constants: %Constants{contract: %{"address" => "@SC2"}} + constants: %Constants{contract: %{"address" => ^contract_address}} } } = :sys.get_state(pid) end diff --git a/test/archethic/contracts/worker_test.exs b/test/archethic/contracts/worker_test.exs index ce3547ca8..ffcebcd76 100644 --- a/test/archethic/contracts/worker_test.exs +++ b/test/archethic/contracts/worker_test.exs @@ -56,7 +56,7 @@ defmodule ArchEthic.Contracts.WorkerTest do transaction_seed = :crypto.strong_rand_bytes(32) {pub, _} = Crypto.derive_keypair(transaction_seed, 1) - next_address = Crypto.hash(pub) + next_address = Crypto.derive_address(pub) secret = Crypto.aes_encrypt(transaction_seed, aes_key) storage_nonce_public_key = Crypto.storage_nonce_public_key() @@ -85,7 +85,7 @@ defmodule ArchEthic.Contracts.WorkerTest do Account.MemTables.UCOLedger.add_unspent_output( "@SC1", %UnspentOutput{ - from: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, + from: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, amount: 100_000_000_000, type: :UCO }, From 2200aa78e438a1a767638d48fd5946c320564d98 Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 16 Feb 2022 14:05:38 +0100 Subject: [PATCH 11/20] Fix mining tests --- lib/archethic/p2p/node.ex | 13 ++--- .../mining/distributed_workflow_test.exs | 48 +++++++++---------- .../pending_transaction_validation_test.exs | 6 +-- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/lib/archethic/p2p/node.ex b/lib/archethic/p2p/node.ex index 46c2f0d63..94a172569 100755 --- a/lib/archethic/p2p/node.ex +++ b/lib/archethic/p2p/node.ex @@ -42,7 +42,7 @@ defmodule ArchEthic.P2P.Node do ...> 127, 0, 0, 1, ...> 11, 184, ...> 1, - ...> 0, 173, 179, 246, 126, 247, 223, 20, 86, 201, 55, 190, 29, 59, 212, 196, 36, + ...> 0, 0, 173, 179, 246, 126, 247, 223, 20, 86, 201, 55, 190, 29, 59, 212, 196, 36, ...> 89, 178, 185, 211, 23, 68, 30, 22, 75, 39, 197, 8, 186, 167, 123, 182, ...> 0, 64, ...> 63, 40, 158, 160, 56, 156, 206, 193, 107, 50, 250, 244, 6, 212, 171, 158, 240, @@ -54,7 +54,7 @@ defmodule ArchEthic.P2P.Node do {127, 0, 0, 1}, 3000, :tcp, - <<0, 173, 179, 246, 126, 247, 223, 20, 86, 201, 55, 190, 29, 59, 212, 196, 36, + <<0, 0, 173, 179, 246, 126, 247, 223, 20, 86, 201, 55, 190, 29, 59, 212, 196, 36, 89, 178, 185, 211, 23, 68, 30, 22, 75, 39, 197, 8, 186, 167, 123, 182>>, <<63, 40, 158, 160, 56, 156, 206, 193, 107, 50, 250, 244, 6, 212, 171, 158, 240, 175, 162, 2, 55, 86, 26, 215, 44, 61, 198, 143, 141, 22, 122, 16, 89, 155, 28, @@ -68,13 +68,14 @@ defmodule ArchEthic.P2P.Node do | :error def decode_transaction_content(<>) do with <> <- ip, - <> <- rest, + <> <- rest, reward_address_size <- Crypto.hash_size(reward_address_hash_id), <> <- rest, <> <- rest do {:ok, {ip0, ip1, ip2, ip3}, port, deserialize_transport(transport), - <>, key_certificate} + <>, + key_certificate} else _ -> :error @@ -92,7 +93,7 @@ defmodule ArchEthic.P2P.Node do ...> {127, 0, 0, 1}, ...> 3000, ...> :tcp, - ...> <<0, 173, 179, 246, 126, 247, 223, 20, 86, 201, 55, 190, 29, 59, 212, 196, 36, + ...> <<0, 0, 173, 179, 246, 126, 247, 223, 20, 86, 201, 55, 190, 29, 59, 212, 196, 36, ...> 89, 178, 185, 211, 23, 68, 30, 22, 75, 39, 197, 8, 186, 167, 123, 182>>, ...> <<63, 40, 158, 160, 56, 156, 206, 193, 107, 50, 250, 244, 6, 212, 171, 158, 240, ...> 175, 162, 2, 55, 86, 26, 215, 44, 61, 198, 143, 141, 22, 122, 16, 89, 155, 28, @@ -107,7 +108,7 @@ defmodule ArchEthic.P2P.Node do # Transport 1, # Reward address - 0, 173, 179, 246, 126, 247, 223, 20, 86, 201, 55, 190, 29, 59, 212, 196, 36, + 0, 0, 173, 179, 246, 126, 247, 223, 20, 86, 201, 55, 190, 29, 59, 212, 196, 36, 89, 178, 185, 211, 23, 68, 30, 22, 75, 39, 197, 8, 186, 167, 123, 182, # Certificate size 0, 64, diff --git a/test/archethic/mining/distributed_workflow_test.exs b/test/archethic/mining/distributed_workflow_test.exs index 34f25adc9..9ebdd3e11 100644 --- a/test/archethic/mining/distributed_workflow_test.exs +++ b/test/archethic/mining/distributed_workflow_test.exs @@ -52,7 +52,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do network_patch: "AAA", geo_patch: "AAA", enrollment_date: DateTime.utc_now(), - reward_address: :crypto.strong_rand_bytes(32) + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> }) {pub, _} = Crypto.generate_deterministic_keypair("seed") @@ -68,7 +68,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do network_patch: "BBB", geo_patch: "BBB", enrollment_date: DateTime.utc_now(), - reward_address: :crypto.strong_rand_bytes(32) + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> }) certificate = Crypto.get_key_certificate(Crypto.first_node_public_key()) @@ -76,9 +76,9 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do tx = Transaction.new(:node, %TransactionData{ content: - <<80, 10, 20, 102, 3000::16, 1, 0, 16, 233, 156, 172, 143, 228, 236, 12, 227, 76, 1, 80, - 12, 236, 69, 10, 209, 6, 234, 172, 97, 188, 240, 207, 70, 115, 64, 117, 44, 82, 132, - 186, byte_size(certificate)::16, certificate::binary>> + <<80, 10, 20, 102, 3000::16, 1, 0, 0, 16, 233, 156, 172, 143, 228, 236, 12, 227, 76, 1, + 80, 12, 236, 69, 10, 209, 6, 234, 172, 97, 188, 240, 207, 70, 115, 64, 117, 44, 82, + 132, 186, byte_size(certificate)::16, certificate::binary>> }) {:ok, @@ -153,7 +153,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do network_patch: "AAA", geo_patch: "AAA", enrollment_date: DateTime.utc_now(), - reward_address: :crypto.strong_rand_bytes(32) + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> }) P2P.add_and_connect_node(%Node{ @@ -167,7 +167,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do network_patch: "DEF", geo_patch: "DEF", enrollment_date: DateTime.utc_now(), - reward_address: :crypto.strong_rand_bytes(32) + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> }) validation_nodes = @@ -199,7 +199,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do port: 3005, first_public_key: "key1", last_public_key: "key1", - reward_address: :crypto.strong_rand_bytes(32) + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> } {:ok, coordinator_pid} = @@ -292,7 +292,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do port: 3005, first_public_key: "key1", last_public_key: "key1", - reward_address: :crypto.strong_rand_bytes(32) + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> } P2P.add_and_connect_node(welcome_node) @@ -311,7 +311,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do port: 3006, first_public_key: "key10", last_public_key: "key10", - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, authorized?: true, authorization_date: DateTime.utc_now(), geo_patch: "AAA", @@ -322,7 +322,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do port: 3007, first_public_key: "key23", last_public_key: "key23", - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, authorized?: true, authorization_date: DateTime.utc_now(), geo_patch: "AAA", @@ -373,7 +373,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do geo_patch: "AAA", network_patch: "AAA", enrollment_date: DateTime.utc_now(), - reward_address: :crypto.strong_rand_bytes(32) + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> }) validation_nodes = @@ -408,7 +408,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do port: 3005, first_public_key: "key1", last_public_key: "key1", - reward_address: :crypto.strong_rand_bytes(32) + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> } P2P.add_and_connect_node(welcome_node) @@ -427,7 +427,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do port: 3006, first_public_key: "key10", last_public_key: "key10", - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, authorized?: true, authorization_date: DateTime.utc_now(), geo_patch: "AAA", @@ -438,7 +438,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do port: 3007, first_public_key: "key23", last_public_key: "key23", - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, authorized?: true, authorization_date: DateTime.utc_now(), geo_patch: "AAA", @@ -493,7 +493,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do geo_patch: "AAA", network_patch: "AAA", enrollment_date: DateTime.utc_now(), - reward_address: :crypto.strong_rand_bytes(32) + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> }) validation_nodes = @@ -535,7 +535,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do port: 3005, first_public_key: "key1", last_public_key: "key1", - reward_address: :crypto.strong_rand_bytes(32) + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> } P2P.add_and_connect_node(welcome_node) @@ -562,7 +562,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do port: 3006, first_public_key: "key10", last_public_key: "key10", - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, authorized?: true, authorization_date: DateTime.utc_now(), geo_patch: "AAA", @@ -573,7 +573,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do port: 3007, first_public_key: "key23", last_public_key: "key23", - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, authorized?: true, authorization_date: DateTime.utc_now(), geo_patch: "AAA", @@ -725,7 +725,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do geo_patch: "AAA", available?: true, enrollment_date: DateTime.utc_now(), - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, authorized?: true, authorization_date: DateTime.utc_now() }) @@ -739,7 +739,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do geo_patch: "AAA", available?: true, enrollment_date: DateTime.utc_now(), - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, authorized?: true, authorization_date: DateTime.utc_now() }) @@ -749,7 +749,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do port: 3005, first_public_key: "key1", last_public_key: "key1", - reward_address: :crypto.strong_rand_bytes(32) + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> } P2P.add_and_connect_node(welcome_node) @@ -776,7 +776,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do port: 3007, first_public_key: "key10", last_public_key: "key10", - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, authorized?: true, authorization_date: DateTime.utc_now() }, @@ -785,7 +785,7 @@ defmodule ArchEthic.Mining.DistributedWorkflowTest do port: 3008, first_public_key: "key23", last_public_key: "key23", - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, authorized?: true, authorization_date: DateTime.utc_now() } diff --git a/test/archethic/mining/pending_transaction_validation_test.exs b/test/archethic/mining/pending_transaction_validation_test.exs index a40e4a6ac..b70d4c75d 100644 --- a/test/archethic/mining/pending_transaction_validation_test.exs +++ b/test/archethic/mining/pending_transaction_validation_test.exs @@ -43,7 +43,7 @@ defmodule ArchEthic.Mining.PendingTransactionValidationTest do :node, %TransactionData{ content: - <<80, 20, 10, 200, 3000::16, 1, 0, 4, 221, 19, 74, 75, 69, 16, 50, 149, 253, 24, + <<80, 20, 10, 200, 3000::16, 1, 0, 0, 4, 221, 19, 74, 75, 69, 16, 50, 149, 253, 24, 115, 128, 241, 110, 118, 139, 7, 48, 217, 58, 43, 145, 233, 77, 125, 190, 207, 31, 64, 157, 137, byte_size(certificate)::16, certificate::binary>> }, @@ -68,7 +68,7 @@ defmodule ArchEthic.Mining.PendingTransactionValidationTest do :node, %TransactionData{ content: - <<80, 20, 100, 50, 3000::16, 1, 0, 4, 221, 19, 74, 75, 69, 16, 50, 149, 253, 24, + <<80, 20, 100, 50, 3000::16, 1, 0, 0, 4, 221, 19, 74, 75, 69, 16, 50, 149, 253, 24, 115, 128, 241, 110, 118, 139, 7, 48, 217, 58, 43, 145, 233, 77, 125, 190, 207, 31, 64, 157, 137, byte_size(certificate)::16, certificate::binary>> }, @@ -104,7 +104,7 @@ defmodule ArchEthic.Mining.PendingTransactionValidationTest do %TransactionData{ content: <<0, 0, 219, 82, 144, 35, 140, 59, 161, 231, 225, 145, 111, 203, 173, 197, 200, 150, - 213, 145, 87, 209, 98, 25, 28, 148, 198, 77, 174, 48, 16, 117, 253, 15, 0, 105, + 213, 145, 87, 209, 98, 25, 28, 148, 198, 77, 174, 48, 16, 117, 253, 15, 0, 0, 105, 113, 238, 128, 201, 90, 172, 230, 46, 99, 215, 130, 104, 26, 196, 222, 157, 89, 101, 74, 248, 245, 118, 36, 194, 213, 108, 141, 175, 248, 6, 120>>, code: """ From a5e7b08748b3c0a2949dd0019977c8cba9cb71f0 Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 16 Feb 2022 14:06:47 +0100 Subject: [PATCH 12/20] Fix P2P tests --- test/archethic/p2p/mem_table_loader_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/archethic/p2p/mem_table_loader_test.exs b/test/archethic/p2p/mem_table_loader_test.exs index f015b2629..295d93a2e 100644 --- a/test/archethic/p2p/mem_table_loader_test.exs +++ b/test/archethic/p2p/mem_table_loader_test.exs @@ -142,8 +142,8 @@ defmodule ArchEthic.P2P.MemTableLoaderTest do type: :node, data: %TransactionData{ content: - <<127, 0, 0, 1, 3003::16, 1, 0, 163, 237, 233, 93, 14, 241, 241, 8, 144, 218, 105, 16, - 138, 243, 223, 17, 182, 87, 9, 7, 53, 146, 174, 125, 5, 244, 42, 35, 209, 142, 24, + <<127, 0, 0, 1, 3003::16, 1, 0, 0, 163, 237, 233, 93, 14, 241, 241, 8, 144, 218, 105, + 16, 138, 243, 223, 17, 182, 87, 9, 7, 53, 146, 174, 125, 5, 244, 42, 35, 209, 142, 24, 164, 64::16, :crypto.strong_rand_bytes(64)::binary>> }, previous_public_key: @node_1_public_key, From 3be6e448d0f9a652aeb6c3cd5b6f28bc058a61d3 Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 16 Feb 2022 14:15:00 +0100 Subject: [PATCH 13/20] Fix self repair tests --- lib/archethic/crypto.ex | 4 +- .../sync/beacon_summary_handler_test.exs | 38 +++++++++---------- test/archethic/self_repair/sync_test.exs | 8 ++-- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/archethic/crypto.ex b/lib/archethic/crypto.ex index 0e391a2b3..c73639a0c 100755 --- a/lib/archethic/crypto.ex +++ b/lib/archethic/crypto.ex @@ -185,7 +185,7 @@ defmodule ArchEthic.Crypto do subset |> derive_beacon_keypair(date, summary?) |> elem(0) - |> hash() + |> derive_address() end @doc """ @@ -223,7 +223,7 @@ defmodule ArchEthic.Crypto do date |> derive_oracle_keypair(size) |> elem(0) - |> hash() + |> derive_address() end @doc """ diff --git a/test/archethic/self_repair/sync/beacon_summary_handler_test.exs b/test/archethic/self_repair/sync/beacon_summary_handler_test.exs index 9693ee534..70938671f 100644 --- a/test/archethic/self_repair/sync/beacon_summary_handler_test.exs +++ b/test/archethic/self_repair/sync/beacon_summary_handler_test.exs @@ -42,7 +42,7 @@ defmodule ArchEthic.SelfRepair.Sync.BeaconSummaryHandlerTest do last_public_key: Crypto.first_node_public_key(), network_patch: "AAA", geo_patch: "AAA", - reward_address: <<0::8, :crypto.strong_rand_bytes(32)::binary>> + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> }) Crypto.generate_deterministic_keypair("daily_nonce_seed") @@ -67,7 +67,7 @@ defmodule ArchEthic.SelfRepair.Sync.BeaconSummaryHandlerTest do available?: true, authorization_date: summary_time |> DateTime.add(-10), authorized?: true, - reward_address: <<0::8, :crypto.strong_rand_bytes(32)::binary>> + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> } node2 = %Node{ @@ -80,7 +80,7 @@ defmodule ArchEthic.SelfRepair.Sync.BeaconSummaryHandlerTest do available?: true, authorization_date: summary_time |> DateTime.add(-10), authorized?: true, - reward_address: <<0::8, :crypto.strong_rand_bytes(32)::binary>> + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> } node3 = %Node{ @@ -93,7 +93,7 @@ defmodule ArchEthic.SelfRepair.Sync.BeaconSummaryHandlerTest do available?: true, authorization_date: summary_time |> DateTime.add(-10), authorized?: true, - reward_address: <<0::8, :crypto.strong_rand_bytes(32)::binary>> + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> } node4 = %Node{ @@ -106,7 +106,7 @@ defmodule ArchEthic.SelfRepair.Sync.BeaconSummaryHandlerTest do available?: true, authorization_date: summary_time |> DateTime.add(-10), authorized?: true, - reward_address: <<0::8, :crypto.strong_rand_bytes(32)::binary>> + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> } P2P.add_and_connect_node(node1) @@ -120,11 +120,11 @@ defmodule ArchEthic.SelfRepair.Sync.BeaconSummaryHandlerTest do available?: false }) - addr1 = <<0::8, :crypto.strong_rand_bytes(32)::binary>> - addr2 = <<0::8, :crypto.strong_rand_bytes(32)::binary>> - addr3 = <<0::8, :crypto.strong_rand_bytes(32)::binary>> - addr4 = <<0::8, :crypto.strong_rand_bytes(32)::binary>> - addr5 = <<0::8, :crypto.strong_rand_bytes(32)::binary>> + addr1 = <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> + addr2 = <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> + addr3 = <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> + addr4 = <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> + addr5 = <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> beacon_summary_address_d = Crypto.derive_beacon_chain_address("D", summary_time, true) beacon_summary_address_e = Crypto.derive_beacon_chain_address("E", summary_time, true) @@ -319,7 +319,7 @@ defmodule ArchEthic.SelfRepair.Sync.BeaconSummaryHandlerTest do available?: true, authorization_date: DateTime.utc_now(), authorized?: true, - reward_address: <<0::8, :crypto.strong_rand_bytes(32)::binary>> + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> } P2P.add_and_connect_node(node) @@ -355,7 +355,7 @@ defmodule ArchEthic.SelfRepair.Sync.BeaconSummaryHandlerTest do network_patch: "AAA", authorization_date: DateTime.utc_now(), authorized?: true, - reward_address: <<0::8, :crypto.strong_rand_bytes(32)::binary>> + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>> } P2P.add_and_connect_node(node) @@ -379,8 +379,8 @@ defmodule ArchEthic.SelfRepair.Sync.BeaconSummaryHandlerTest do type: :node, seed: "node_seed", content: - <<127, 0, 0, 1, 3000::16, 1, 0, :crypto.strong_rand_bytes(32)::binary, 64::16, - :crypto.strong_rand_bytes(64)::binary>> + <<127, 0, 0, 1, 3000::16, 1, 0::8, 0::8, :crypto.strong_rand_bytes(32)::binary, + 64::16, :crypto.strong_rand_bytes(64)::binary>> ) MockClient @@ -480,8 +480,8 @@ defmodule ArchEthic.SelfRepair.Sync.BeaconSummaryHandlerTest do type: :node, seed: "node_seed", content: - <<127, 0, 0, 1, 3000::16, 1, 0::8, :crypto.strong_rand_bytes(32)::binary, 64::16, - :crypto.strong_rand_bytes(64)::binary>> + <<127, 0, 0, 1, 3000::16, 1, 0::8, 0::8, :crypto.strong_rand_bytes(32)::binary, + 64::16, :crypto.strong_rand_bytes(64)::binary>> ) summaries = [ @@ -557,7 +557,7 @@ defmodule ArchEthic.SelfRepair.Sync.BeaconSummaryHandlerTest do available?: true, geo_patch: "BBB", network_patch: "BBB", - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, enrollment_date: DateTime.utc_now() } @@ -569,7 +569,7 @@ defmodule ArchEthic.SelfRepair.Sync.BeaconSummaryHandlerTest do authorization_date: DateTime.utc_now() |> DateTime.add(-10), geo_patch: "AAA", network_patch: "AAA", - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, enrollment_date: DateTime.utc_now() } @@ -582,7 +582,7 @@ defmodule ArchEthic.SelfRepair.Sync.BeaconSummaryHandlerTest do available?: true, geo_patch: "BBB", network_patch: "BBB", - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, authorization_date: DateTime.utc_now(), authorized?: true } diff --git a/test/archethic/self_repair/sync_test.exs b/test/archethic/self_repair/sync_test.exs index 1c1d5b024..3775d66b4 100644 --- a/test/archethic/self_repair/sync_test.exs +++ b/test/archethic/self_repair/sync_test.exs @@ -71,7 +71,7 @@ defmodule ArchEthic.SelfRepair.SyncTest do available?: true, geo_patch: "BBB", network_patch: "BBB", - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, enrollment_date: DateTime.utc_now(), authorized?: true, authorization_date: DateTime.utc_now() |> DateTime.add(-(86_400 * 365)) @@ -85,7 +85,7 @@ defmodule ArchEthic.SelfRepair.SyncTest do authorization_date: DateTime.utc_now() |> DateTime.add(-(86_400 * 365)), geo_patch: "AAA", network_patch: "AAA", - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, enrollment_date: DateTime.utc_now() } @@ -98,7 +98,7 @@ defmodule ArchEthic.SelfRepair.SyncTest do available?: true, geo_patch: "BBB", network_patch: "BBB", - reward_address: :crypto.strong_rand_bytes(32), + reward_address: <<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>, enrollment_date: DateTime.utc_now(), authorized?: true, authorization_date: DateTime.utc_now() |> DateTime.add(-(86_400 * 365)) @@ -190,7 +190,7 @@ defmodule ArchEthic.SelfRepair.SyncTest do assert :ok = Sync.load_missed_transactions( - DateTime.utc_now() |> DateTime.add(-86_400 * 364), + DateTime.utc_now() |> DateTime.add(-86_400), "AAA" ) From 23f79d99dbd4028df1797840d23186477665da45 Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 16 Feb 2022 14:17:14 +0100 Subject: [PATCH 14/20] Fix bootstrap tests --- test/archethic/bootstrap/sync_test.exs | 4 ++-- test/archethic/bootstrap_test.exs | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/test/archethic/bootstrap/sync_test.exs b/test/archethic/bootstrap/sync_test.exs index 3ea91d5a5..3b42164ff 100644 --- a/test/archethic/bootstrap/sync_test.exs +++ b/test/archethic/bootstrap/sync_test.exs @@ -243,8 +243,8 @@ defmodule ArchEthic.Bootstrap.SyncTest do node_tx = Transaction.new(:node, %TransactionData{ content: - <<127, 0, 0, 1, 3000::16, 1, 0, :crypto.strong_rand_bytes(32)::binary, 64::16, - :crypto.strong_rand_bytes(64)::binary>> + <<127, 0, 0, 1, 3000::16, 1, 0::8, 0::8, :crypto.strong_rand_bytes(32)::binary, + 64::16, :crypto.strong_rand_bytes(64)::binary>> }) :ok = Sync.initialize_network(node_tx) diff --git a/test/archethic/bootstrap_test.exs b/test/archethic/bootstrap_test.exs index f974fc589..83aae30ff 100644 --- a/test/archethic/bootstrap_test.exs +++ b/test/archethic/bootstrap_test.exs @@ -127,7 +127,7 @@ defmodule ArchEthic.BootstrapTest do :tcp, seeds, DateTime.utc_now(), - "00610F69B6C5C3449659C99F22956E5F37AA6B90B473585216CF4931DAF7A0AB45" + "0000610F69B6C5C3449659C99F22956E5F37AA6B90B473585216CF4931DAF7A0AB45" |> Base.decode16!() ) @@ -157,8 +157,8 @@ defmodule ArchEthic.BootstrapTest do available?: true, enrollment_date: DateTime.utc_now(), reward_address: - <<245, 206, 118, 231, 188, 183, 250, 138, 217, 84, 176, 169, 37, 230, 8, 17, 147, 90, - 187, 118, 27, 143, 165, 86, 151, 130, 250, 231, 32, 155, 183, 79>> + <<0, 0, 245, 206, 118, 231, 188, 183, 250, 138, 217, 84, 176, 169, 37, 230, 8, 17, + 147, 90, 187, 118, 27, 143, 165, 86, 151, 130, 250, 231, 32, 155, 183, 79>> }, %Node{ ip: {127, 0, 0, 1}, @@ -176,8 +176,8 @@ defmodule ArchEthic.BootstrapTest do available?: true, enrollment_date: DateTime.utc_now(), reward_address: - <<0, 122, 59, 37, 225, 0, 2, 24, 151, 241, 79, 158, 121, 16, 7, 168, 150, 94, 164, 74, - 201, 0, 202, 242, 185, 133, 85, 186, 73, 199, 223, 143>> + <<0, 0, 122, 59, 37, 225, 0, 2, 24, 151, 241, 79, 158, 121, 16, 7, 168, 150, 94, 164, + 74, 201, 0, 202, 242, 185, 133, 85, 186, 73, 199, 223, 143>> } ] @@ -276,7 +276,7 @@ defmodule ArchEthic.BootstrapTest do :tcp, seeds, DateTime.utc_now(), - "00610F69B6C5C3449659C99F22956E5F37AA6B90B473585216CF4931DAF7A0AB45" + "0000610F69B6C5C3449659C99F22956E5F37AA6B90B473585216CF4931DAF7A0AB45" |> Base.decode16!() ) @@ -304,7 +304,7 @@ defmodule ArchEthic.BootstrapTest do :tcp, seeds, DateTime.utc_now(), - "00610F69B6C5C3449659C99F22956E5F37AA6B90B473585216CF4931DAF7A0AB45" + "0000610F69B6C5C3449659C99F22956E5F37AA6B90B473585216CF4931DAF7A0AB45" |> Base.decode16!() ) @@ -328,7 +328,7 @@ defmodule ArchEthic.BootstrapTest do :tcp, seeds, DateTime.utc_now(), - "00610F69B6C5C3449659C99F22956E5F37AA6B90B473585216CF4931DAF7A0AB45" + "0000610F69B6C5C3449659C99F22956E5F37AA6B90B473585216CF4931DAF7A0AB45" |> Base.decode16!() ) @@ -364,7 +364,7 @@ defmodule ArchEthic.BootstrapTest do :tcp, seeds, DateTime.utc_now(), - "00610F69B6C5C3449659C99F22956E5F37AA6B90B473585216CF4931DAF7A0AB45" + "0000610F69B6C5C3449659C99F22956E5F37AA6B90B473585216CF4931DAF7A0AB45" |> Base.decode16!() ) @@ -379,7 +379,7 @@ defmodule ArchEthic.BootstrapTest do :tcp, seeds, DateTime.utc_now(), - "00610F69B6C5C3449659C99F22956E5F37AA6B90B473585216CF4931DAF7A0AB45" + "0000610F69B6C5C3449659C99F22956E5F37AA6B90B473585216CF4931DAF7A0AB45" |> Base.decode16!() ) From 7b2e147ef0d473385d51c6c6fc5d3e509e5f520d Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 16 Feb 2022 14:31:08 +0100 Subject: [PATCH 15/20] Fix transaction chain tests --- lib/archethic/transaction_chain.ex | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/archethic/transaction_chain.ex b/lib/archethic/transaction_chain.ex index 0fb60daf1..f61ed67b9 100644 --- a/lib/archethic/transaction_chain.ex +++ b/lib/archethic/transaction_chain.ex @@ -229,7 +229,7 @@ defmodule ArchEthic.TransactionChain do iex> [ ...> %Transaction{ - ...> address: <<0, 109, 140, 2, 60, 50, 109, 201, 126, 206, 164, 10, 86, 225, 58, 136, 241, 118, 74, 3, 215, 6, 106, 165, 24, 51, 192, 212, 58, 143, 33, 68, 2>>, + ...> address: <<0, 0, 109, 140, 2, 60, 50, 109, 201, 126, 206, 164, 10, 86, 225, 58, 136, 241, 118, 74, 3, 215, 6, 106, 165, 24, 51, 192, 212, 58, 143, 33, 68, 2>>, ...> type: :transfer, ...> data: %TransactionData{}, ...> previous_public_key: @@ -249,14 +249,14 @@ defmodule ArchEthic.TransactionChain do ...> ] ...> |> TransactionChain.proof_of_integrity() # Hash of the transaction - <<0, 129, 254, 255, 206, 75, 42, 96, 95, 51, 71, 50, 198, 115, 23, 145, 238, 155, 179, 33, 213, 110, 160, 140, 187, 135, 255, 156, 43, 52, 189, 254, 78>> + <<0, 123, 128, 98, 182, 113, 165, 184, 172, 49, 237, 243, 192, 225, 204, 187, 160, 160, 64, 117, 136, 51, 186, 226, 34, 145, 31, 69, 48, 34, 164, 253, 95>> With multiple transactions iex> [ ...> %Transaction{ ...> address: - ...> <<61, 7, 130, 64, 140, 226, 192, 8, 238, 88, 226, 106, 137, 45, 69, 113, 239, + ...> <<0, 0, 61, 7, 130, 64, 140, 226, 192, 8, 238, 88, 226, 106, 137, 45, 69, 113, 239, ...> 240, 45, 55, 225, 169, 170, 121, 238, 136, 192, 161, 252, 33, 71, 3>>, ...> type: :transfer, ...> data: %TransactionData{}, @@ -275,7 +275,7 @@ defmodule ArchEthic.TransactionChain do ...> 232, 135, 42, 112, 58, 181, 13>> ...> }, ...> %Transaction{ - ...> address: <<0, 109, 140, 2, 60, 50, 109, 201, 126, 206, 164, 10, 86, 225, 58, 136, 241, 118, 74, 3, 215, 6, 106, 165, 24, 51, 192, 212, 58, 143, 33, 68, 2>>, + ...> address: <<0, 0, 109, 140, 2, 60, 50, 109, 201, 126, 206, 164, 10, 86, 225, 58, 136, 241, 118, 74, 3, 215, 6, 106, 165, 24, 51, 192, 212, 58, 143, 33, 68, 2>>, ...> type: :transfer, ...> data: %TransactionData{}, ...> previous_public_key: @@ -292,15 +292,15 @@ defmodule ArchEthic.TransactionChain do ...> 161, 155, 143, 43, 50, 6, 7, 97, 130, 134, 174, 7, 235, 183, 88, 165, 197, 25, 219, 84, ...> 232, 135, 42, 112, 58, 181, 13>>, ...> validation_stamp: %ValidationStamp{ - ...> proof_of_integrity: <<0, 129, 254, 255, 206, 75, 42, 96, 95, 51, 71, 50, 198, 115, 23, 145, 238, - ...> 155, 179, 33, 213, 110, 160, 140, 187, 135, 255, 156, 43, 52, 189, 254, 78>> + ...> proof_of_integrity: <<0, 123, 128, 98, 182, 113, 165, 184, 172, 49, 237, 243, 192, 225, 204, 187, + ...> 160, 160, 64, 117, 136, 51, 186, 226, 34, 145, 31, 69, 48, 34, 164, 253, 95>> ...> } ...> } ...> ] ...> |> TransactionChain.proof_of_integrity() # Hash of the transaction + previous proof of integrity - <<0, 191, 70, 89, 151, 55, 18, 143, 44, 255, 246, 97, 86, 1, 102, 246, 48, 210, - 26, 207, 228, 116, 102, 47, 32, 16, 225, 45, 26, 53, 154, 123, 106>> + <<0, 150, 171, 173, 84, 39, 116, 164, 116, 216, 112, 168, 253, 154, 141, 95, + 123, 179, 96, 253, 195, 247, 192, 75, 47, 173, 144, 82, 99, 4, 10, 149, 169>> """ @spec proof_of_integrity(nonempty_list(Transaction.t())) :: binary() def proof_of_integrity([ @@ -347,12 +347,12 @@ defmodule ArchEthic.TransactionChain do ...> 232, 135, 42, 112, 58, 181, 13>>, ...> validation_stamp: %ValidationStamp{ ...> timestamp: ~U[2020-03-30 12:06:30.000Z], - ...> proof_of_integrity: <<0, 191, 70, 89, 151, 55, 18, 143, 44, 255, 246, 97, 86, 1, 102, 246, 48, 210, - ...> 26, 207, 228, 116, 102, 47, 32, 16, 225, 45, 26, 53, 154, 123, 106>> + ...> proof_of_integrity: <<0, 150, 171, 173, 84, 39, 116, 164, 116, 216, 112, 168, 253, 154, 141, 95, + ...> 123, 179, 96, 253, 195, 247, 192, 75, 47, 173, 144, 82, 99, 4, 10, 149, 169>> ...> } ...> }, ...> %Transaction{ - ...> address: <<0, 1, 109, 140, 2, 60, 50, 109, 201, 126, 206, 164, 10, 86, 225, 58, 136, 241, 118, 74, 3, 215, 6, 106, 165, 24, 51, 192, 212, 58, 143, 33, 68, 2>>, + ...> address: <<0, 0, 109, 140, 2, 60, 50, 109, 201, 126, 206, 164, 10, 86, 225, 58, 136, 241, 118, 74, 3, 215, 6, 106, 165, 24, 51, 192, 212, 58, 143, 33, 68, 2>>, ...> type: :transfer, ...> data: %TransactionData{}, ...> previous_public_key: @@ -370,13 +370,12 @@ defmodule ArchEthic.TransactionChain do ...> 232, 135, 42, 112, 58, 181, 13>>, ...> validation_stamp: %ValidationStamp{ ...> timestamp: ~U[2020-03-30 10:06:30.000Z], - ...> proof_of_integrity: <<0, 129, 254, 255, 206, 75, 42, 96, 95, 51, 71, 50, 198, 115, 23, 145, 238, - ...> 155, 179, 33, 213, 110, 160, 140, 187, 135, 255, 156, 43, 52, 189, 254, 78>> + ...> proof_of_integrity: <<0, 123, 128, 98, 182, 113, 165, 184, 172, 49, 237, 243, 192, 225, 204, 187, 160, 160, 64, 117, 136, 51, 186, 226, 34, 145, 31, 69, 48, 34, 164, 253, 95>> ...> } ...> } ...> ] ...> |> TransactionChain.valid?() - false + true """ @spec valid?([Transaction.t(), ...]) :: boolean From 98c374c911403e028da29e4ceba83e1f96dc94b7 Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 16 Feb 2022 14:41:21 +0100 Subject: [PATCH 16/20] Fix config --- config/dev.exs | 4 ++-- config/prod.exs | 16 ++++++++-------- config/test.exs | 2 +- .../validation_stamp/ledger_operations.ex | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/config/dev.exs b/config/dev.exs index 50d1c3e0b..e8d9539b2 100755 --- a/config/dev.exs +++ b/config/dev.exs @@ -30,7 +30,7 @@ config :archethic, ArchEthic.Bootstrap, reward_address: System.get_env( "ARCHETHIC_REWARD_ADDRESS", - Base.encode16(<<0::8, :crypto.strong_rand_bytes(32)::binary>>) + Base.encode16(<<0::8, 0::8, :crypto.strong_rand_bytes(32)::binary>>) ) |> Base.decode16!(case: :mixed) @@ -38,7 +38,7 @@ config :archethic, ArchEthic.Bootstrap.NetworkInit, genesis_pools: [ %{ address: - "00EC64107CA604A6B954037CFA91ED18315A77A94FBAFD91275CEE07FA45EAF893" + "0000EC64107CA604A6B954037CFA91ED18315A77A94FBAFD91275CEE07FA45EAF893" |> Base.decode16!(case: :mixed), amount: 1_000_000_000_000_000 } diff --git a/config/prod.exs b/config/prod.exs index 7c51ee8db..40caa55bc 100755 --- a/config/prod.exs +++ b/config/prod.exs @@ -13,49 +13,49 @@ config :archethic, ArchEthic.Bootstrap.NetworkInit, [ %{ address: - Base.decode16!("002CA95C90A4D75DEEC973D251F5B59CD8EBC787FEC265B9CAC1F6C56A8D9BFCCA", + Base.decode16!("00002CA95C90A4D75DEEC973D251F5B59CD8EBC787FEC265B9CAC1F6C56A8D9BFCCA", case: :mixed ), amount: 382_000_000_000 }, %{ address: - Base.decode16!("00AD6EEC49FED0A936FEF4BD3301FF933FFFE9BA63BE2F6E948DFEC4C2D4543917", + Base.decode16!("0000AD6EEC49FED0A936FEF4BD3301FF933FFFE9BA63BE2F6E948DFEC4C2D4543917", case: :mixed ), amount: 236_000_000_000 }, %{ address: - Base.decode16!("00D23C33B9B75A272B1E8BCA6F252179A144E0A66A396CCF989C4A6D353CFF3849", + Base.decode16!("0000D23C33B9B75A272B1E8BCA6F252179A144E0A66A396CCF989C4A6D353CFF3849", case: :mixed ), amount: 900_000_000 }, %{ address: - Base.decode16!("006FDE9B6EDF98E682561634B814A5FA2127B327D50AF38428AB06B447A4CF8345", + Base.decode16!("00006FDE9B6EDF98E682561634B814A5FA2127B327D50AF38428AB06B447A4CF8345", case: :mixed ), amount: 560_000_000 }, %{ address: - Base.decode16!("000F1DFC550CB0492C7BEA2DCFABC6F2E2378A5D1D8AA8B5058FC2F30B62DD5DDC", + Base.decode16!("00000F1DFC550CB0492C7BEA2DCFABC6F2E2378A5D1D8AA8B5058FC2F30B62DD5DDC", case: :mixed ), amount: 340_000_000 }, %{ address: - Base.decode16!("006098E77BA4C675DA94F57091E73797BF2E11B3FAB20867101AB20FBE21ED862A", + Base.decode16!("00006098E77BA4C675DA94F57091E73797BF2E11B3FAB20867101AB20FBE21ED862A", case: :mixed ), amount: 340_000_000 }, %{ address: - Base.decode16!("009BD34BB544A9A71536806E52E9E9F4F41FF81751848FD0B1E0E465D2FB95C36C", + Base.decode16!("00009BD34BB544A9A71536806E52E9E9F4F41FF81751848FD0B1E0E465D2FB95C36C", case: :mixed ), amount: 220_000_000 @@ -63,7 +63,7 @@ config :archethic, ArchEthic.Bootstrap.NetworkInit, if(System.get_env("ARCHETHIC_NETWORK_TYPE") == "testnet", do: %{ address: - "00EC64107CA604A6B954037CFA91ED18315A77A94FBAFD91275CEE07FA45EAF893" + "0000EC64107CA604A6B954037CFA91ED18315A77A94FBAFD91275CEE07FA45EAF893" |> Base.decode16!(case: :mixed), amount: 1_000_000_000_000_000 } diff --git a/config/test.exs b/config/test.exs index 9a1a2a8c3..f73283a15 100755 --- a/config/test.exs +++ b/config/test.exs @@ -27,7 +27,7 @@ config :archethic, ArchEthic.Bootstrap.NetworkInit, genesis_pools: [ %{ address: - "0073bdaf847037115914ff5ca15e52d162db57b5089d5e4bf2005d825592c9c945" + "000073bdaf847037115914ff5ca15e52d162db57b5089d5e4bf2005d825592c9c945" |> Base.decode16!(case: :mixed), amount: 1_000_000_000_000_000 } diff --git a/lib/archethic/transaction_chain/transaction/validation_stamp/ledger_operations.ex b/lib/archethic/transaction_chain/transaction/validation_stamp/ledger_operations.ex index a0bdff211..8bb09e73e 100644 --- a/lib/archethic/transaction_chain/transaction/validation_stamp/ledger_operations.ex +++ b/lib/archethic/transaction_chain/transaction/validation_stamp/ledger_operations.ex @@ -51,7 +51,7 @@ defmodule ArchEthic.TransactionChain.Transaction.ValidationStamp.LedgerOperation fee: non_neg_integer() } - @burning_address <<0::8, 0::256>> + @burning_address <<0::8, 0::8, 0::256>> @doc """ Return the address used for the burning From d76efca7a05f82f2a717e312fb9c0fd2ecb21e65 Mon Sep 17 00:00:00 2001 From: Samuel Date: Wed, 16 Feb 2022 15:51:37 +0100 Subject: [PATCH 17/20] Fix test with burn address --- .../transaction/validation_stamp/ledger_operations.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/archethic/transaction_chain/transaction/validation_stamp/ledger_operations.ex b/lib/archethic/transaction_chain/transaction/validation_stamp/ledger_operations.ex index 8bb09e73e..4aa1d4731 100644 --- a/lib/archethic/transaction_chain/transaction/validation_stamp/ledger_operations.ex +++ b/lib/archethic/transaction_chain/transaction/validation_stamp/ledger_operations.ex @@ -122,7 +122,7 @@ defmodule ArchEthic.TransactionChain.Transaction.ValidationStamp.LedgerOperation ...> ) %LedgerOperations{ fee: 50_000_000, - transaction_movements: [ %TransactionMovement { to: <<0::8, 0::256>>, amount: 5_000_000, type: :UCO} ], + transaction_movements: [ %TransactionMovement { to: <<0::8, 0::8, 0::256>>, amount: 5_000_000, type: :UCO} ], node_movements: [ %NodeMovement{to: "074CA174E4763A169F714C0D37187C5AC889683B4BBE9B0859C4073A690B7DF1", amount: 10_000_000, roles: [:cross_validation_node] }, %NodeMovement{to: "4D75266A648F6D67576E6C77138C07042077B815FB5255D7F585CD36860DA19E", amount: 8_333_333, roles: [:previous_storage_node]}, @@ -151,7 +151,7 @@ defmodule ArchEthic.TransactionChain.Transaction.ValidationStamp.LedgerOperation ...> ) %LedgerOperations{ fee: 50_000_000, - transaction_movements: [ %TransactionMovement { to: <<0::8, 0::256>>, amount: 5_000_000, type: :UCO} ], + transaction_movements: [ %TransactionMovement { to: <<0::8, 0::8, 0::256>>, amount: 5_000_000, type: :UCO} ], node_movements: [ %NodeMovement{to: "4D75266A648F6D67576E6C77138C07042077B815FB5255D7F585CD36860DA19E", amount: 8_333_333, roles: [:previous_storage_node]}, %NodeMovement{to: "5EDA43AA8BBDAB66E4737989D44471F70FDEFD41D9E186507F27A61FA2170B23", amount: 23_333_333, roles: [:coordinator_node, :cross_validation_node, :previous_storage_node] }, @@ -819,7 +819,7 @@ defmodule ArchEthic.TransactionChain.Transaction.ValidationStamp.LedgerOperation iex> %LedgerOperations{ ...> fee: 50_000_000, - ...> transaction_movements: [%TransactionMovement{to: <<0::8, 0::256>>, amount: 5_000_000, type: :UCO}], + ...> transaction_movements: [%TransactionMovement{to: <<0::8, 0::8, 0::256>>, amount: 5_000_000, type: :UCO}], ...> node_movements: [ ...> %NodeMovement{to: "F35EB8260981AC5D8268B7B323277C8FB44D73B81DCC603B0E9CEB4B406A18AD", amount: 5_000_000, roles: [:coordinator_node]}, ...> %NodeMovement{to: "5D0AE5A5B686030AD630119F3494B4852E3990BF196C117D574FD32BEB747FC7", amount: 10_000_000, roles: [:cross_validation_node]}, @@ -837,7 +837,7 @@ defmodule ArchEthic.TransactionChain.Transaction.ValidationStamp.LedgerOperation iex> %LedgerOperations{ ...> fee: 50_000_000, - ...> transaction_movements: [%TransactionMovement{to: <<0::8, 0::256>>, amount: 5_000_000, type: :UCO}], + ...> transaction_movements: [%TransactionMovement{to: <<0::8, 0::8, 0::256>>, amount: 5_000_000, type: :UCO}], ...> node_movements: [ ...> %NodeMovement{to: "503EF04022CDAA3F0F402A1C2524ED3782E09F228BC16DEB1766051C86880F8D", amount: 25_000_000, roles: [:coordinator_node, :cross_validation_node]}, ...> %NodeMovement{to: "5EDA43AA8BBDAB66E4737989D44471F70FDEFD41D9E186507F27A61FA2170B23", amount: 8_333_333, roles: [:previous_storage_node]}, From 2092f746f3df68d82d9a1a572edc1070d87a7458 Mon Sep 17 00:00:00 2001 From: Imnik11 Date: Fri, 18 Feb 2022 02:38:51 +0530 Subject: [PATCH 18/20] Fix Bootsrapp network init test --- test/archethic/bootstrap/network_init_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/archethic/bootstrap/network_init_test.exs b/test/archethic/bootstrap/network_init_test.exs index a46d35f41..841429c9f 100644 --- a/test/archethic/bootstrap/network_init_test.exs +++ b/test/archethic/bootstrap/network_init_test.exs @@ -101,7 +101,7 @@ defmodule ArchEthic.Bootstrap.NetworkInitTest do ledger_operations: %LedgerOperations{ transaction_movements: [ %TransactionMovement{ - to: <<0::8, 0::256>>, + to: <<0::8, 0::8, 0::256>>, amount: ^network_pool_burn, type: :UCO }, From c7d6b8e852cc4e0413ea74c8e3d3bd406c3708ff Mon Sep 17 00:00:00 2001 From: Imnik11 Date: Fri, 18 Feb 2022 02:44:08 +0530 Subject: [PATCH 19/20] Fix beacon chain summary transaction address --- test/archethic/beacon_chain_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/archethic/beacon_chain_test.exs b/test/archethic/beacon_chain_test.exs index 64a8276a3..576820683 100644 --- a/test/archethic/beacon_chain_test.exs +++ b/test/archethic/beacon_chain_test.exs @@ -106,11 +106,11 @@ defmodule ArchEthic.BeaconChainTest do end test "summary_transaction_address/2 should return a address using the storage nonce a subset and a date" do - assert <<0, 141, 146, 109, 188, 197, 248, 255, 123, 14, 172, 53, 198, 233, 233, 205, 180, 221, + assert <<0, 0, 141, 146, 109, 188, 197, 248, 255, 123, 14, 172, 53, 198, 233, 233, 205, 180, 221, 95, 244, 203, 222, 149, 194, 205, 73, 214, 9, 207, 197, 55, 59, 182>> = BeaconChain.summary_transaction_address(<<1>>, ~U[2021-01-13 00:00:00Z]) - assert <<0, 25, 97, 166, 116, 204, 210, 75, 152, 0, 193, 90, 253, 228, 140, 38, 248, 49, 160, + assert <<0, 0, 25, 97, 166, 116, 204, 210, 75, 152, 0, 193, 90, 253, 228, 140, 38, 248, 49, 160, 210, 186, 181, 32, 203, 157, 110, 67, 255, 181, 80, 96, 160, 239>> = BeaconChain.summary_transaction_address(<<1>>, ~U[2021-01-14 00:00:00Z]) end From 76216866e57227107d2ba1a3daaf9cc551c664c0 Mon Sep 17 00:00:00 2001 From: Imnik11 Date: Fri, 18 Feb 2022 02:55:57 +0530 Subject: [PATCH 20/20] Improved specs & formatting --- lib/archethic/crypto/id.ex | 2 +- test/archethic/beacon_chain_test.exs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/archethic/crypto/id.ex b/lib/archethic/crypto/id.ex index 6c276cdf8..59822ef43 100755 --- a/lib/archethic/crypto/id.ex +++ b/lib/archethic/crypto/id.ex @@ -90,7 +90,7 @@ defmodule ArchEthic.Crypto.ID do <> end - @spec prepend_curve(Crypto.versioned_hash(), binary()) :: Crypto.prepended_hash() + @spec prepend_curve(binary(), integer) :: Crypto.prepended_hash() def prepend_curve(hash, curve_type) do <> end diff --git a/test/archethic/beacon_chain_test.exs b/test/archethic/beacon_chain_test.exs index 576820683..e725c58ad 100644 --- a/test/archethic/beacon_chain_test.exs +++ b/test/archethic/beacon_chain_test.exs @@ -106,12 +106,12 @@ defmodule ArchEthic.BeaconChainTest do end test "summary_transaction_address/2 should return a address using the storage nonce a subset and a date" do - assert <<0, 0, 141, 146, 109, 188, 197, 248, 255, 123, 14, 172, 53, 198, 233, 233, 205, 180, 221, - 95, 244, 203, 222, 149, 194, 205, 73, 214, 9, 207, 197, 55, 59, + assert <<0, 0, 141, 146, 109, 188, 197, 248, 255, 123, 14, 172, 53, 198, 233, 233, 205, 180, + 221, 95, 244, 203, 222, 149, 194, 205, 73, 214, 9, 207, 197, 55, 59, 182>> = BeaconChain.summary_transaction_address(<<1>>, ~U[2021-01-13 00:00:00Z]) - assert <<0, 0, 25, 97, 166, 116, 204, 210, 75, 152, 0, 193, 90, 253, 228, 140, 38, 248, 49, 160, - 210, 186, 181, 32, 203, 157, 110, 67, 255, 181, 80, 96, 160, + assert <<0, 0, 25, 97, 166, 116, 204, 210, 75, 152, 0, 193, 90, 253, 228, 140, 38, 248, 49, + 160, 210, 186, 181, 32, 203, 157, 110, 67, 255, 181, 80, 96, 160, 239>> = BeaconChain.summary_transaction_address(<<1>>, ~U[2021-01-14 00:00:00Z]) end