Hash Functions in Fluree
In Fluree, every block contains the hash of the previous block, the transaction data for that block, and the hash of the current block.
When you submit a transaction, your transaction is turned into a series of flakes. Flakes are assertions of facts at a given point in time, and flakes are the way that all information, including schema, ledger settings, and metadata is stored in Fluree.
Flakes
Flakes are composed of six parts: subject, predicate, object, time, operation (true or false), and metadata. Read more about flakes in the docs.
For example, the below flakes are the results of adding a new person to the ledger with the handle, "cRose". Only the first flake, [ 387028092977159, 1012, "cRose", -25, true, {} ]
pertains to the actual data I updated in my ledger.
Block Metadata
The rest of the flakes are block metadata. Any subject ids that are negative (i.e. -25 and -26 in the flakes below) are subjects in either the _block
or _tx
collections. These collections cannot be updated manually, and they contain all of a ledger's metadata. You can see that the time part of the first flake is -25, and this is the subject id of several of the metadata flakes.
[
[387028092977159, 1012, "cRose", -25, true, null],
[
-25,
100,
"8375ebebb724e16d41069550f3e3845bff2f9db0109c85bfce82347ca2ea8d73",
-25,
true,
null
],
[-25, 101, 105553116266496, -25, true, null],
[-25, 103, 1546625546568, -25, true, null],
[
-25,
106,
"{\"db\":\"dev/$network\",\"tx\":[{\"_id\":\"person\",\"handle\":\"cRose\"}],\"nonce\":1546625546568,\"auth\":\"TfHsKYf5cVcBeSTAmxgqymLZu4i7d8yXRcG\",\"expire\":1546625576568}",
-25,
true,
null
],
[
-25,
107,
"1b3045022100e1086f4399b46360f35955a057f254c1aec0c4868696de8c5c4d9b04ff8523ae0220328350a24075c3fa2ea1aaa32be88093378b9b7f7f5825040cbe58d303cf7b3a",
-25,
true,
null
],
[-25, 108, "{\"person$1\":387028092977159}", -25, true, null],
[
-26,
1,
"fc3aa46906bafed20f67b3f41edb2ad2bb1124577442c92652a2d69d8dbd3496",
-26,
true,
null
],
[
-26,
2,
"a1fb08361da823b0c4b17db5a3e912207e2dbdbe97890e0665b066b3941112be",
-26,
true,
null
],
[-26, 3, -26, -26, true, null],
[-26, 3, -25, -26, true, null],
[-26, 4, 105553116266496, -26, true, null],
[-26, 5, 1546625546581, -26, true, null],
[-26, 6, 13, -26, true, null],
[
-26,
7,
"1c304402202e93e0e42faa01e4d8c6404ce656f3e562fbc095644cd0a810b46c0112e0c8280220494083304a0c9164ca2b1ffcdb8cf9a07ad233f6d9090df9b55906483046dd2a",
-26,
true,
null
]
]
Two of the metadata flakes contain hashes.
[
-26,
2,
"a1fb08361da823b0c4b17db5a3e912207e2dbdbe97890e0665b066b3941112be",
-26,
true,
null
]
Subject id -26, in this ledger, refers to a subject in the _block
collection. _block
predicates include hash, prevHash, transactions, transactors, instant, number and sig. The predicate with the subject id 2, in this ledger, is _block/prevHash
, and "a1fb08361da823b0c4b17db5a3e912207e2dbdbe97890e0665b066b3941112be" is the hash of the previous block.
[
-26,
1,
"fc3aa46906bafed20f67b3f41edb2ad2bb1124577442c92652a2d69d8dbd3496",
-26,
true,
null
]
The predicate with the subject id 1, in this ledger, is _block/hash
, and "fc3aa46906bafed20f67b3f41edb2ad2bb1124577442c92652a2d69d8dbd3496" is the hash of the current block.
These hashes are derived by taking all of the other flakes above (excluding the block hash- itself- and block signatures) and running them through a hash function (SHA2-256).
Because each hash combines the data from a given block, as well as the previous block's hash, hashes are an easy way to spot if someone in a network is trying to tamper with data.