Chia-Network / clvm_rs

Rust implementation of clvm
Apache License 2.0
66 stars 57 forks source link

`serialized_length_from_bytes()` #355

Closed arvidn closed 10 months ago

arvidn commented 10 months ago

This PR adds an implementation of serialized_length_from_bytes() where any back-references are validated. Rename the existing function to indicate that the input is trusted (i.e. not fully validated).

In support of this, it also adds:

objective

The objective is to ensure that the buffer is a valid serialization if it passes this function. That way, an invalid CLVM program fails early, at parse-time, rather than time-of-use. Currently, the Program class in chia_rs (the counterpart to SerializedProgram) is parsed in a relaxed manner, and so might fail later, in run().

This can also tie into trusted- and untrusted parsing of Streamable. So trusted programs don't need to be validated to the same extent.

benchmarks:

     Running benches/deserialize.rs (target/release/deps/deserialize-2f84100aeab5fe87)
deserialize/serialized_length_from_bytes
                        time:   [150.42 µs 150.99 µs 151.54 µs]
deserialize/serialized_length_from_bytes_trusted
                        time:   [44.187 µs 44.339 µs 44.522 µs]
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) high mild
deserialize/node_from_bytes_backrefs
                        time:   [239.17 µs 240.30 µs 241.73 µs]
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) high mild
deserialize/node_from_bytes
                        time:   [222.05 µs 222.99 µs 223.73 µs]
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) low severe
coveralls-official[bot] commented 10 months ago

Pull Request Test Coverage Report for Build 7261386983


Changes Missing Coverage Covered Lines Changed/Added Lines %
src/serde/tools.rs 119 122 97.54%
<!-- Total: 119 122 97.54% -->
Files with Coverage Reduction New Missed Lines %
src/serde/tools.rs 4 97.18%
<!-- Total: 4 -->
Totals Coverage Status
Change from base Build 7261384226: 0.03%
Covered Lines: 5405
Relevant Lines: 5762

💛 - Coveralls