Commit Graph

3388 Commits

Author SHA1 Message Date
y
63a6856ccd timekeeper: restore 0 check for slot 2023-09-18 15:46:05 +00:00
y
f67fc3df29 Add checks on TimeKeeperSafe methods 2023-09-18 15:46:05 +00:00
y
f85cd257a0 fix mistake in TimeKeeperSafe::current 2023-09-18 15:46:05 +00:00
y
6308a7e123 fix comments 2023-09-18 15:46:05 +00:00
y
5d62a10855 Add TimeKeeperSafe struct
Instead of checking if one of the TimeKeeper fields is 0 on every
operation (which adds overhead and protects only in the case of an
incoherent instantiation of the struct), add a new struct TimeKeeperSafe
that panics when created with bad values.

It is still possible that a developer can make a mistake and manually
initialize a TimeKeeper with bad values or else set its fields to bad
values. For now, we will accept this risk as it is not present in the
codebase.
2023-09-18 15:46:05 +00:00
y
c7814711e0 fmt 2023-09-18 15:46:05 +00:00
y
2f45588f57 util: fix division-by-zero panics
Added simple checks for division by zero in arithmetic operations in
util/time.rs
Added a unit test to check that a TimeKeeper with values of 0 in its
fields can call its methods without panicking.
2023-09-18 15:46:05 +00:00
y
0a61ec37fb zkas: fix panic occurring in nested function calls
This issue was discovered by fuzzing.

Change the `unimplemented()!` panic macro to error handling that informs
the user that using Literals and Functions in nested function calls is
not yet supported. This should be a slightly more friendly developer
experience. Changing this from a panic to an error allows us to continue
with further fuzzing.
2023-09-18 11:04:20 +00:00
y
3b52ed4e27 zkas: formatting, typos, clippy 2023-09-18 11:04:20 +00:00
y
8a333100ef zkas: fix panic in Analyzer
This issue was discovered with fuzzing.

Panic 1: It was possible to assign a variable to a function/opcode with
no return type. This caused a index-out-of-bounds panic when the
analyzer attempted to access the first element of an empty vector of
return types. The analyzer now presents an error when a .zk author
attempts to assign a variable to an opcode that has no return types.

Panic 2: There was an index-out-of-bounds panic when performing
verification on Literals that were passed to Opcodes that use Array
types as their arguments. This was fixed by pasting the validation code
from the Variable verfication section which handles Arrays properly.
(Refactoring should be done to reduce duplication here.)
2023-09-18 11:04:20 +00:00
y
827ddbb9a0 zkas: fix more panics in Parser
These issues were found via fuzzing

Panic 1: If the size of the vector of tokens passed to
`check_section_structure` is less than 2, the parser tells
the author that there are not enough valid tokens in the section.

Panic 2: Very large values of k will result in integer overflow when the
value is larger than the type's MAX_SIZE. This causes the existing k <=
16 check to succeed but it actually shouldn't. In debug/fuzzing
   contexts, Rust panics. In production, this will not occur.

Panic 3: If invalid/unimplemented characters appear in an argument to a function, the
parser panicked when it hit `unimplemented!()`. Now it tells the author
that this character cannot be used in an argument to a function.
2023-09-17 00:18:15 +00:00
y
d7816326fb zkas: fix panics in Parser
Add error handling for the parser logic. Both of these issues were found
via fuzzing.

Fix Panic 1: instead of panicking via unwrap() when analyzing the namespace,
the parser displays an error message informing the .zk file author
that they need to add a namespace.

Fix Panic 2: if the length of the `tokens` vector is 0, the parser
now displays an error saying so.
2023-09-16 23:14:31 +00:00
greptile
94d101a8ae zkas: Fix compiler panic when semicolons are missing (#220)
* zkas: Add error for missing semicolons

Fixed a parser bug where it would pass invalid statements to the
compiler which resulted in a panic.

Added error handling in the parser when a semicolon is missing. The
error message suggest to the dev to add a semicolon.

Also added more detail to the unreachable()! statement in the compiler
so that a darkfi dev can see what the erroneous StatementType was that
caused the panic.

Example errror cases:

```
<statement> <statement>;
```

and
```
<statement>
<statement>;
```

To test: remove a semicolon from example/simple.zk and run ./zkas
example/simple.zk

* add code comment to explain

---------

Co-authored-by: y <y>
2023-09-16 18:55:41 +00:00
aggstam
4d5e779e28 contract/money/tests/pow_reward: use proper producer tx validation 2023-09-15 01:27:37 +03:00
aggstam
01fac53e39 validator: properly test producer txs 2023-09-15 00:51:37 +03:00
aggstam
ade055d3db validator/validation,verification: perform validations based on block version 2023-09-15 00:51:37 +03:00
aggstam
45d6ffea71 validator/verification: proper producer tx handling 2023-09-15 00:51:37 +03:00
aggstam
0d0740d331 blockchain/Block: removed slots vector, and handle storing based on block version.
With these changes, BlockInfo now represents a wrapper over Block, as it becomes constant/final in terms of structure. All extra data based on block versions go to BlockInfo, and their storage is handled accordingly.
2023-09-15 00:51:37 +03:00
aggstam
eca2c7e175 blockchain/Block: moved producer tx at last position of blocks' txs vec 2023-09-15 00:51:37 +03:00
aggstam
dba13ebef6 blockchain/Block: removed producer structure 2023-09-15 00:51:37 +03:00
aggstam
b8e612138d validator/blockchain: consolidate all blockchain structures validation at src/validator/validation.rs 2023-09-14 14:39:20 +03:00
aggstam
8d7a2bde7c validator: preperation cleanup for PoW blocks integration 2023-09-13 19:22:56 +03:00
aggstam
4700e85e4b contract/money: decoupled GenesisMintV1 and PoWRewardV1 from TokenMintV1 2023-09-13 16:20:05 +03:00
aggstam
91e2b0b916 contract/consensus: decoupled GenesisStakeV1 from StakeV1 2023-09-13 15:46:17 +03:00
aggstam
bcbc636318 contract/money: new PoWReward call added 2023-09-12 17:48:04 +03:00
parazyd
6661faf8c4 event-graph: DAG sync implementation. 2023-09-11 12:40:58 +02:00
parazyd
6b49fa6560 net/message: Allow packet payloads to be empty.
We should be able to send commands without a payload.
2023-09-11 12:40:06 +02:00
y
bb20e05f0c event_graph2: Add unit tests for Event::validate 2023-09-10 08:54:35 +00:00
y
fb780d73be event_graph2: add basic checks on math
Force panic rather than perform operations that overflow i64
Add explicit check for division by zero
2023-09-10 08:53:44 +00:00
Dastan-glitch
12df4958f5 event_graph: fill blanks in tests 2023-09-08 18:33:01 +03:00
parazyd
7861949a64 event-graph: DAG sync concept 2023-09-08 16:41:46 +02:00
parazyd
f6699efea9 event-graph: Flush sled on prune task stop. 2023-09-08 15:59:04 +02:00
narodnik
f3c604acc1 system/condvar: add illustrative comments to explain how async/await works in rust 2023-09-08 13:58:56 +02:00
parazyd
57f0896fb2 event-graph: Improve parent fetching, and improve tests. 2023-09-08 13:55:47 +02:00
parazyd
8a40af693f event-graph: Clean up the tests a little bit, they need to be more serious. 2023-09-07 20:16:39 +02:00
parazyd
382604342e event-graph: Sprinkle some logs around the code. 2023-09-07 19:29:58 +02:00
parazyd
cf0776caf0 event-graph: Implement DAG pruning background task. 2023-09-07 14:53:43 +02:00
parazyd
c041aea075 event-graph: Add a StoppableTask for DAG pruning. 2023-09-07 14:53:43 +02:00
parazyd
a81f8f096d event-graph: Find and fill the unreferenced tips on EventGraph::new() 2023-09-07 14:53:43 +02:00
parazyd
b184cfb5b8 event-graph: Use u64 instead of the Timestamp wrapper. 2023-09-07 14:53:43 +02:00
parazyd
215855335f event-graph: Implement deterministic genesis event creation with variable rotation time. 2023-09-07 10:23:56 +02:00
parazyd
3a1b3c75be serial: Rework encode_payload_test 2023-09-06 17:48:53 +02:00
parazyd
7015af9d7c event-graph: Make DAG sorting more deterministic. 2023-09-06 15:22:13 +02:00
parazyd
5ac3af091c event-graph: Add TODO notes on implementing pruning and syncing. 2023-09-06 14:19:52 +02:00
parazyd
c00e29350b event-graph: Add placeholders for TipReq and TipRep messages 2023-09-06 14:19:52 +02:00
parazyd
e7fb3bd370 event-graph: Move Event to a separate module 2023-09-06 14:19:52 +02:00
parazyd
fab0ba66be event-graph: More proper new event validation. 2023-09-06 14:19:51 +02:00
parazyd
839f15721d event-graph: Alternative DAG WIP 2023-09-06 12:54:37 +02:00
parazyd
68a28200c8 serial: Implement generic fixed-size array encoding and decoding. 2023-09-06 12:54:37 +02:00
parazyd
b96a54bb4f net/p2p: Implement broadcast_to() when we want to broadcast to specific peers. 2023-09-05 14:27:18 +02:00