Commit Graph

4105 Commits

Author SHA1 Message Date
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
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
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
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
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
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
f8f446f916 money: change DARK_TOKEN_ID = hash_to_base("DarkFi:DRK_Native_Token") 2024-03-26 16:37:14 +01:00
skoupidi
fbeb88ad45 darkfid: cleaned up unused PoWReward fields, use (de)serialize_async 2024-03-26 15:43:42 +02:00
skoupidi
b6c7b5ff3c contract/money/model/token_id: restore deprecated functions(with minor cleanup) and added clarification TODOs 2024-03-26 15:06:53 +02:00
skoupidi
2956207cc5 chore: clippy 2024-03-26 15:02:21 +02:00
draoi
afde25dd1d store: don't store whitelist entries in greylist on stop()
Previously we had decided on forcing whitelist entries through the
refinery on each new run, by writing them to the greylist on stop.

However, this is a bad design for the following reasons:

1. It deletes the work performed by the refinery, which is valuable and
   should be preserved. The whitelist is expensive (i.e. 15s/ peer + bandwidth),
   whereas the greylist is cheap (costs nothing to create). Therefore it's
   important to retain the distinction even on stop().

2. It means that when we start a node, since we have no memory of white
   hosts, the node will always try to connect to peers from the greylist.
   Probably safe peers (white) are mixed with potentially hostile peers (grey),
   so the node will struggle to form connections and DAG sync will fail.

3. Whitelist peers will be downgraded to Greylist if we cannot connect to
    them in Outbound Session, so forcing them through the refinery is redundant.
2024-03-26 08:58:49 +01:00
zero
99d5e54883 test-harness: change wasm benchmark to use microsecs instead of millisecs 2024-03-24 15:51:34 +01:00
zero
48d23df367 create zkrender tool to plot circuit layouts 2024-03-24 10:23:43 +01:00
zero
74b7d2f7b8 py: Proof.create() return None when failing rather than use .unwrap() 2024-03-24 09:39:35 +01:00
skoupidi
8871f0898d validator: eat ze bugs 2024-03-23 19:50:40 +02:00
skoupidi
74ed38a7e6 blockchain/contract_store: added auxilliary fn get_all() to WasmStore and ContractStateStore 2024-03-23 14:08:42 +02:00
skoupidi
5cac7b404d sdk: chore clippy and typo 2024-03-23 14:07:55 +02:00
draoi
b5764d2c9f store: remove redundant Result<()> type on register_channel() 2024-03-23 10:26:25 +01:00
draoi
1d6f1175be net: fix bug that was causing duplicate connections to seed nodes
We establish some new rules:

1. Configured seed nodes should never enter the hostlist.
2. If by weird chance they enter the hostlist, they should never be connected to in outbound session.
3. Manual connections to configured seeds are also not allowed.
2024-03-23 09:59:00 +01:00
skoupidi
b70ade1922 validator: permanently store ranks as blockchain expands 2024-03-22 20:19:44 +02:00
zero
05ea80bd99 wasm tests: add option to generate a CSV of benchmarks 2024-03-22 11:06:42 +01:00
draoi
c2941c4726 error: more descriptive error handling for state transitions 2024-03-22 10:14:22 +01:00
draoi
0329e2b296 settings: delete deprecated quarantine setting 2024-03-22 10:14:22 +01:00
skoupidi
c15facda1c validator: fixed not saving PoW module updates to db 2024-03-21 20:54:40 +02:00
skoupidi
23d49cd158 validator: use sled-overlay add diff functionality to rebuild forks 2024-03-21 16:27:39 +02:00
skoupidi
269cffbd1c validator: purge unreferenced trees from sled when reseting forks 2024-03-21 15:37:25 +02:00
draoi
6ba22f7a85 manual_session: avoid risky op when all attempts to manual connect fail
Simply exit the manual session when we fail to connect
manual_attempt_limit times. Marking as suspend could panic if the host
has been received via the seedsync/ protocoladdr process and is currently
in an incompatiable state.
2024-03-21 11:43:49 +01:00
draoi
0c23ba0947 manual_session: fix bug which caused peers to get stuck in Connect state
We must remove a peer from the HostRegistry when we fail to connect to
it in ManualSession, otherwise we will never attempt to reconnect, since
the state transition of Connect-> Connect will fail.
2024-03-21 10:19:22 +01:00
draoi
5f55e877ae net: enable hostlist migration + bugfixes
Fixes several bugs:

1. Gold list upgrades were getting blocked since it required the
   following state change that was not permitted: Connected() -> Move
   We have fixed this by enabling this state change and making Move
   take an Option<ChannelPtr> so that we can immediately reset Gold
   upgrades to Connected(ChannelPtr) once the upgrade has successfully
   completed.

2. Previously we were not downgrading peers when they disconnect, this
   has now been fixed.

3. Previously move_host() was not properly atomic. While HostState
   protects single host from being misused (like being Refined and Moved
   at the same time), HostState does not protect the hostlists
   themselves from being written to, creating race conditions when hosts
   are being removed from hostlists, like so:

        thread1: assert!(get_index(host_a) == 0)
        thread2: assert!(get_index(host_b) == 1)
        thread1: remove(0)
        thread2: remove(1) -> panic!

    We resolve this by moving write locks higher up in the code so that
    the entire sequence of looking up an index and removing it is
    atomic.

4. Manual session had a bug in which we proceeded to establish a
   Connector with an address even if try_register() failed. This has
   been fixed. We now only try to connect to address that are valid,
   otherwise we wait outbound_connect_timeout and retry
   manual_attempt_limit tries.
2024-03-20 12:10:02 +01:00
parazyd
50f7220341 chore: Clippy lints 2024-03-20 09:21:40 +01:00
skoupidi
696bc213a0 validator: fixed stupid mistake 2024-03-19 18:02:05 +02:00
skoupidi
41c9bd28ba validator: updated sled-overlay version and use new diffs logic for finalization 2024-03-19 16:47:33 +02:00
skoupidi
aae713227f contract/test-harness/vks: updated hashes 2024-03-19 16:46:35 +02:00
zero
010ea6037d runtime/merkle: db_roots store key=blockhash, value=blockheight (before value=[]) 2024-03-19 10:48:22 +01:00
zero
cde5f7cea2 runtime/merkle: simplify the function. we do not need to store the intermediate roots for the tree since each update is atomic. Also the serialization length == 32 should be an assert rather than a conditional check. 2024-03-19 10:34:45 +01:00