Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Prepend curve type in address #210

Merged
20 commits merged into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ 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)

config :archethic, ArchEthic.Bootstrap.NetworkInit,
genesis_pools: [
%{
address:
"00EC64107CA604A6B954037CFA91ED18315A77A94FBAFD91275CEE07FA45EAF893"
"0000EC64107CA604A6B954037CFA91ED18315A77A94FBAFD91275CEE07FA45EAF893"
|> Base.decode16!(case: :mixed),
amount: 1_000_000_000_000_000
}
Expand Down
16 changes: 8 additions & 8 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,57 @@ 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
},
if(System.get_env("ARCHETHIC_NETWORK_TYPE") == "testnet",
do: %{
address:
"00EC64107CA604A6B954037CFA91ED18315A77A94FBAFD91275CEE07FA45EAF893"
"0000EC64107CA604A6B954037CFA91ED18315A77A94FBAFD91275CEE07FA45EAF893"
|> Base.decode16!(case: :mixed),
amount: 1_000_000_000_000_000
}
Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ services:

networks:
archethic_net:
name: archethic_net
ipam:
driver: default
config:
Expand Down
2 changes: 1 addition & 1 deletion lib/archethic/account/mem_tables_loader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/archethic/beacon_chain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ defmodule ArchEthic.BeaconChain do
Crypto.hash([subset, <<DateTime.to_unix(date)::32>>])
)

Crypto.hash(pub)
Crypto.derive_address(pub)
end

@doc """
Expand Down
14 changes: 7 additions & 7 deletions lib/archethic/beacon_chain/slot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
"""
Expand Down
25 changes: 13 additions & 12 deletions lib/archethic/beacon_chain/slot/transaction_summary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ 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,
...> 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>>
...> ]
...> }
...> |> 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,
Expand All @@ -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
>>
"""
Expand All @@ -84,27 +84,27 @@ 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,
...> 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()
{
%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,
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>>
]
},
""
}
"""
@spec deserialize(bitstring()) :: {t(), bitstring()}
def deserialize(<<hash_id::8, rest::bitstring>>) do
def deserialize(<<curve_type::8, hash_id::8, rest::bitstring>>) do
hash_size = Crypto.hash_size(hash_id)

<<address::binary-size(hash_size), timestamp::64, type::8, nb_movements::16, rest::bitstring>> =
Expand All @@ -114,7 +114,7 @@ defmodule ArchEthic.BeaconChain.Slot.TransactionSummary do

{
%__MODULE__{
address: <<hash_id::8, address::binary>>,
address: <<curve_type::8, hash_id::8, address::binary>>,
timestamp: DateTime.from_unix!(timestamp, :millisecond),
type: Transaction.parse_type(type),
movements_addresses: addresses
Expand All @@ -129,10 +129,11 @@ defmodule ArchEthic.BeaconChain.Slot.TransactionSummary do
{Enum.reverse(acc), rest}
end

defp deserialize_addresses(<<hash_id::8, rest::bitstring>>, nb_addresses, acc) do
defp deserialize_addresses(<<curve_id::8, hash_id::8, rest::bitstring>>, nb_addresses, acc) do
hash_size = Crypto.hash_size(hash_id)
<<address::binary-size(hash_size), rest::bitstring>> = rest
deserialize_addresses(rest, nb_addresses, [<<hash_id::8, address::binary>> | acc])

deserialize_addresses(rest, nb_addresses, [<<curve_id::8, hash_id::8, address::binary>> | acc])
end

@spec to_map(t()) :: map()
Expand Down
8 changes: 4 additions & 4 deletions lib/archethic/beacon_chain/summary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions lib/archethic/bootstrap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -222,7 +222,7 @@ defmodule ArchEthic.Bootstrap do
get_genesis_seed()
|> Crypto.derive_keypair(1)
|> elem(0)
|> Crypto.hash()
|> Crypto.derive_address()
end

@doc """
Expand All @@ -233,7 +233,7 @@ defmodule ArchEthic.Bootstrap do
get_genesis_seed()
|> Crypto.derive_keypair(0)
|> elem(0)
|> Crypto.hash()
|> Crypto.derive_address()
end

@doc """
Expand Down
Loading