Commit Graph

8347 Commits

Author SHA1 Message Date
draoi
c794507458 store: fix logic error in is_connection_to_self() 2024-04-01 13:33:38 +02:00
draoi
1f1bfd3dce net: flatten move_hosts() so unregister call happens outside function
this leads to cleaner code since depending on the use case we still do
different things with the HostState following move_host(). However it
does mean that unregister() has to be called manually in some cases.
2024-04-01 13:33:38 +02:00
draoi
11c65a7705 store: cleanup move_host() to reduce code reuse
also makes store_or_update() and remove_if_exists() properly atomic.
2024-04-01 13:33:38 +02:00
draoi
69c6530a5d net: move downgrade to greylist into remove_sub_on_stop()
Previously there was a bug which happened v rarely in which:

> Outbound and Manual Session are waiting on a stop signal
> Outbound/ Manual receives a stop signal, de-registers channel (in move_host)
> Channel is selected by Slot 1 to be connected to, state is changed to Connect
> remove_sub_on_stop() receives a stop signal, de-registers channel
> Channel is selected by Slot 5 connected to, state is changed to Connect
> Slot 1 connects, state is changed to Connected
> Slot 5 connects -> panic!

To avoid this happening, we move unregister() out of move_host and perform the sequence:

recv stop signal -> move_host to greylist (if outbond/manual) -> unregister()

We do this inside the shared method remove_sub_on_stop to ensure the execution path always happens in the same way.
2024-04-01 13:33:38 +02:00
skoupidi
7d4151c230 sdk: fn get_tx(hash) added 2024-04-01 14:19:22 +03:00
skoupidi
0475a8e2d3 runtime/import/util: corrected some log targets 2024-04-01 13:25:29 +03:00
skoupidi
254af116f4 blockchain/*: minore code look cleanup 2024-04-01 13:14:56 +03:00
zero
9878fff12d runtime::{merkle, smt}: change value for roots_db from (blk_height:3, tx_idx:2, call_idx:2) to (tx_hash:32, call_idx:2) 2024-04-01 12:07:25 +02:00
zero
0967744635 runtime: add tx_hash to runtime params 2024-04-01 11:59:17 +02:00
zero
5c9e3bd4a1 tx: change tx.hash() -> Result<blake3::Hash> to tx.hash() -> TransactionHash, by calling .unwrap() on blake3 hasher. This should be safe (see code comment in tx/mod.rs:188 inside fn hash() ) 2024-04-01 11:59:17 +02:00
skoupidi
f9a58ca5ad runtime/import/util: minor optimizations retrieving block info stuff 2024-04-01 12:57:21 +03:00
zero
4f2f660d61 money/integration: add missing import for darkfi_sdk::blockchain::expected_reward 2024-04-01 10:59:04 +02:00
zero
affcde18d8 book/arch/dao: change (block_height, tx_idx) to simply tx_hash since mempool txs won't have this data. 2024-04-01 10:42:22 +02:00
zero
51d7f2996a dao::propose(): when a proposal is made, we snapshot the current coins root (old) AND nullifiers root (newly added) 2024-04-01 10:28:16 +02:00
zero
2919a595f1 runtime/merkle & smt: implements DB_roots format documented in the book arch/dao page. We store all merkle roots together with information about exactly when that root occurred. To store when the root occurred, we use an absolute location of (block_height, tx_idx, call_idx). Right now tx_idx and call_idx are hardcoded to 0 since the env doesn't yet have access to this info. 2024-04-01 09:23:07 +02:00
zero
bfcd383f3b doc: on disk states, use (block_height, tx_index) tuple instead of tx_hash since it's 1. more compact 2. the info we actually need 2024-03-31 11:23:05 +02:00
zero
f92fc9b096 sdk: add missing "0x" prefix to unit test strings 2024-03-30 09:32:53 +01:00
draoi
6504ceceb7 net: fix bug in outbound session that was restricting slot connections
Previously we were using the wrong variable in
fetch_addrs_with_preference, such that Greylist entries were always
returned when in fact we want to select from the Gold and White list
first.

We also clean up the code and simplify the associated net settings.
2024-03-30 09:06:42 +01:00
zero
37e642922b doc: add section specifying DB formats for sets 2024-03-30 07:51:28 +01:00
zero
ef71a31ffe sdk: fix broken unit test 2024-03-29 12:20:21 +01:00
draoi
1c5586cf6e store: fix bug in filter_addrs() that was causing peers with the same ports as us to get dropped 2024-03-29 11:18:05 +01:00
zero
031aac7f65 fee/swap: migrate nullifiers to SMT to match money::transfer() 2024-03-29 10:06:44 +01:00
zero
45f0e1ab5e bench: add sled benchmark 2024-03-29 09:42:56 +01:00
foo
1383e7bd47 doc: Remove reference to quarantine settings
They have been deleted and replaced with the greylist system
2024-03-28 20:12:06 -04:00
zero
2527dd0812 doc: add laptop nullifier vs SMT benchmarks 2024-03-28 13:47:39 +01:00
zero
5bfd718575 doc: add desktop nullifier/SMT benchmarks comparison 2024-03-28 12:05:56 +01:00
zero
edf36acc88 Cargo.toml: add bench=false to disable libtest benchmarker 2024-03-28 11:26:57 +01:00
zero
452a6740f2 Makefile: s/bench_zk-from-json/bench-zk-from-json/ and add bench* to PHONY 2024-03-28 10:39:42 +01:00
zero
dd5c4d747f Makefile/bench: add -f to rm so nonexistent files don't block target 2024-03-28 10:35:52 +01:00
zero
79b6276fc8 Makefile: add missing dependency 'contracts' to bench target and rm src/contract/test-harness/*.bin 2024-03-28 10:33:05 +01:00
zero
03ca4794eb bench: simplify and improve zk-from-json benchmark 2024-03-28 10:26:31 +01:00
zero
b2d29aaa0a sdk/python: add missing SparseMerklePath 2024-03-28 09:47:24 +01:00
zero
cb80b9a69f money/dao: regen zk witness json files, and comment out zk::export_witness() from money clients 2024-03-28 07:28:02 +01:00
zero
61661052ce sdk/util: rename Fp.to_str() to Fp.to_string(), and encode/deocde hex strings with 0x prefix. 2024-03-28 07:21:20 +01:00
parazyd
19b0325dd9 contract/test-harness: Update PKS and VKS cache hashes 2024-03-27 15:36:20 +01:00
parazyd
b0df9d5f38 chore: Clippy lints 2024-03-27 15:19:04 +01:00
therealyingtong
ce35921cab zk::vm: Refactor range checks to reuse table 2024-03-27 15:14:44 +01:00
draoi
10404a962e doc: fix various hosts documentation 2024-03-27 13:39:51 +01:00
zero
b1ba95b9e0 bench: correct paths and add missing EcNiPoint to import_witness_json() 2024-03-27 13:02:29 +01:00
zero
19016fb521 bench: add generic zk_from_json() which will benchmark most .zk files using witness.json files provided. 2024-03-27 11:30:05 +01:00
zero
4532b8d229 for most .zk proofs, provide a corresponding witness.json file which is usable with zkrunner, benchmarks and other utils (using import_witness_json()). 2024-03-27 11:30:04 +01:00
zero
a1c48a39c7 zk/debug: add import_witness_json() 2024-03-27 11:30:04 +01:00
zero
4c049778bb sdk/crypto: FieldElemAsStr trait which provides to/from_str() for Fp/Fq 2024-03-27 11:30:04 +01:00
draoi
4bad13e687 net: create darklist for unknown transports + share darklist (not greylist)
In monero, nodes broadcast addrs from their whitelist. Receiving nodes
save the information on their greylist.

This is to ensure that honest nodes only broadcast active (i.e. whitelist)
nodes to the network. Dishonest nodes can send garbage info through
the hostlist, and therefore all information received from other nodes
is considered hostile and placed in the greylist, until we independently
verify it is accessible via the refinery.

Previously, darkfi deviated from this design as follows:

* Since peers on the greylist that do not match our transports never
  enter the refinery, we assume that the greylist consists of
  unsupported transports.
* We broadcast the greylist in ProtocolAddr, in an attempt to
  ensure that all transports are propagated.

Rather than simply assuming the greylist contains unsupported
transports, it is better to assume the greylist is hostile (since it
comes from other nodes).

We create a `darklist` specifically for storing unknown/ unsupported
transports. When we receive information from other peer, unsupported
addrs are added to our `darklist`, which is then broadcast to other
peers in ProtocolAddr. This fulfils to requirement (of broadcasting all
transports) without also involving honest peers in the propagating of
hostile info.

Specifically:

* Hostile peers can still broadcast garbage info in their gold, white
  and dark lists.

* Since info from other nodes is potentially hostile, honest peers save
  this info on their greylist and do not broadcast it to other peers
  unless a) it passes the refinery b) we connect to in outbound session
  c) we do not support this transport.

* There is a potential attack in which an attacker could fill their
  darklist with garbage e.g. Nym addresses, and honest nodes that do not
  support Nym will continue sharing these addresses via the dark list.
  The hostile peers will continue to be shared until a Nym-supporting
  node receives them and they pass via the refinery.

* Note that this attack is less severe, since providing the nodes stay
  on the Dark list they are ignored by the refinery and outbound connect
  loop and do not eat up resources of the node. The only time it will
  potentially cause pressure on a node if is the e.g. Nym node receives
  a list of hostile fake Nym addresses and they enter its greylist,
  causing it to refine many garbage addresses and potentially slowing
  its ability to make outbound connections. The latter can be prevented
  by increasing the settings `anchor_connect_count` and
  `white_connection_percent` (meaning outbound connections will not
  select from the greylist, or select less).

* Since there exists a potential attack vector of garbage entries in the
  Dark list, we limit the Dark list size to 1000 peers.

* This also means that supporting all transports is the best setup for a
  since it increases the security of the network (wrt the dark list).
2024-03-27 10:44:28 +01:00
zero
afa1856236 tests/bench: delete bench_zk, add zk_arith (uses criterion crate) 2024-03-26 17:19:08 +01:00
zero
f8f446f916 money: change DARK_TOKEN_ID = hash_to_base("DarkFi:DRK_Native_Token") 2024-03-26 16:37:14 +01:00
skoupidi
3349ea5cd8 script/research/gg: Use async (de)serialisation and prefer base64 over base58 2024-03-26 16:11:17 +02:00
skoupidi
3fc0fb19ed minerd: use (de)serialize_async 2024-03-26 15:46:01 +02:00
skoupidi
fbeb88ad45 darkfid: cleaned up unused PoWReward fields, use (de)serialize_async 2024-03-26 15:43:42 +02:00
skoupidi
4b12c9de4f chore: clippy 2024-03-26 15:18:08 +02:00