AleoNet / snarkVM

A Virtual Machine for Zero-Knowledge Executions
https://snarkvm.org
Apache License 2.0
1.08k stars 1.5k forks source link

[Feature] Introduces a maximum transaction size. #2437

Closed d0cd closed 7 months ago

d0cd commented 7 months ago

This PR introduces MAX_TRANSACTION_SIZE which upper bounds the number of bytes in a transaction. This limit is imposed in check_transaction, however constructing larger transactions is still permitted.

As part of the design, this PR introduces a LimitedWriter which is a wrapper aroound Write. The motivation is to ensure that additional bytes (beyond the maximum) are not written. Without this, the implementation in check_transaction have to write potentially larger amounts of data, before being able to check that the limit is not exceeded.

Note that this implementation requires that MAX_TRANSACTION_SIZE is never decreased.

An alternate implementation was considered where MAX_TRANSACTION_SIZE was enforced in the (de)serializers. That design is prone to backwards compatibility issues. Note that this design is not free of backwards compatibility issues either; if MAX_TRANSACTION_SIZE is decreased, then older transactions can still be invalidated.