Commit Graph

3413 Commits

Author SHA1 Message Date
parazyd
2e4b8c8167 rpc: Remove forgotten debug prints 2023-10-16 11:14:21 +02:00
parazyd
6be651c408 rpc: Support JsonRequest params as maps.
Internally we convert them to an array of len 1.
2023-10-16 10:55:59 +02:00
aggstam
1d2212ae10 validator/consensus: generate proper slots on fork creation/rebuilding 2023-10-14 15:14:03 +03:00
aggstam
4043e09330 validator/consensus: handle same ranking forks 2023-10-14 14:23:05 +03:00
aggstam
893ea4a52f validator/pow: store block difficulty info in sled 2023-10-13 19:40:18 +03:00
aggstam
594946044e validator/pow: TODOs cleanup 2023-10-13 16:48:13 +03:00
aggstam
8cff15a9b8 validator: handle proposals based on their version 2023-10-11 21:41:08 +03:00
aggstam
1cdad996d3 validator/consensus: cache fork rank for better performance 2023-10-06 18:29:12 +03:00
aggstam
0331a02f53 validator/consensus: use blocks previous previous VRF for ranking 2023-10-06 18:15:17 +03:00
aggstam
c847febc51 validator/consensus: fork/block ranking implemented 2023-10-06 17:38:44 +03:00
aggstam
15adf6f9cb contract/money/pow_reward: vrf proof added 2023-10-05 18:36:25 +03:00
aggstam
d61cf39649 chore: naming cleanup 2023-10-05 16:21:04 +03:00
y
0e9a9d5bc5 [WIP] Modify parser to support array syntax
Add support for square brackets to the parser to prepare to support
arrays.
Add a test .zk file with intended syntax for arrays. This can be used as
input to the zkas binary to check for errors while developing this
feature.
2023-10-04 10:20:23 -04:00
y
aba4d3b0f7 zkas: add square brackets to lexer (for arrays) 2023-10-04 10:20:23 -04:00
aggstam
6ad2a19bac validator: validate blocks based on their version 2023-10-03 21:45:28 +03:00
aggstam
95434701f4 blockchain/Block: block version to derive from cuttof slot, not hardcoded value 2023-10-03 16:38:30 +03:00
aggstam
f7f8214988 contract/money/pow_reward: minor renaming 2023-10-03 16:31:02 +03:00
aggstam
030cbb48c9 validator/verification: validate producer signature using transaction public key 2023-10-03 16:25:29 +03:00
aggstam
b26106ffe7 validator/pow: stoppable mining 2023-09-28 16:50:18 +03:00
aggstam
214a4f458d darkfid2: (very) raw miner task added 2023-09-21 18:40:15 +03:00
aggstam
10fbf5d963 validator: pow module added for mining 2023-09-20 23:32:33 +03:00
aggstam
989d049452 blockchain/Block: proper hash usage 2023-09-19 16:54:35 +03:00
aggstam
e5081d55ce blockchain/Block: refactored in preparation for mining integration 2023-09-19 00:11:20 +03:00
aggstam
6bcdfd3f87 blockchain/Block: magic be gone 2023-09-18 20:13:58 +03:00
y
6c1002a1ba timekeeper: improve wording about fields set to 0 2023-09-18 15:46:05 +00:00
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