Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v5.0.1] Add threshold for maxTreeDepth for serializers #798

Closed
wants to merge 4 commits into from

Conversation

jozanek
Copy link
Collaborator

@jozanek jozanek commented May 9, 2022

Partially closes #759, #781

@jozanek jozanek requested a review from aslesarenko May 9, 2022 18:50
@codecov
Copy link

codecov bot commented May 9, 2022

Codecov Report

Merging #798 (91853dd) into v5.0.1-RC (743123c) will decrease coverage by 0.09%.
The diff coverage is 87.50%.

❗ Current head 91853dd differs from pull request most recent head 595ef21. Consider uploading reports for the commit 595ef21 to get more accurate results

@@              Coverage Diff              @@
##           v5.0.1-RC     #798      +/-   ##
=============================================
- Coverage      71.89%   71.79%   -0.10%     
=============================================
  Files            248      248              
  Lines          18942    18829     -113     
  Branches         634      573      -61     
=============================================
- Hits           13618    13519      -99     
+ Misses          5324     5310      -14     
Impacted Files Coverage Δ
...ala/sigmastate/serialization/ValueSerializer.scala 68.69% <65.21%> (+0.41%) ⬆️
...cala/sigmastate/serialization/DataSerializer.scala 98.75% <97.36%> (+1.34%) ⬆️
sigmastate/src/main/scala/sigmastate/Values.scala 82.89% <100.00%> (+0.11%) ⬆️
...cala/sigmastate/serialization/TypeSerializer.scala 99.15% <100.00%> (+0.02%) ⬆️
.../main/scala/sigmastate/utils/SigmaByteWriter.scala 45.37% <100.00%> (+2.65%) ⬆️
.../src/main/scala/scalan/primitives/NumericOps.scala 73.91% <0.00%> (-4.35%) ⬇️
core/src/main/scala/scalan/DefRewriting.scala 72.94% <0.00%> (-1.18%) ⬇️
...ain/scala/special/collection/CollsOverArrays.scala 86.74% <0.00%> (-0.47%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 743123c...595ef21. Read the comment docs.

@@ -255,6 +288,12 @@ class DeserializationResilience extends SerializationSpecification
ValueSerializer.deserialize(reader(ValueSerializer.serialize(expr), maxTreeDepth = 3))
Copy link
Member

@aslesarenko aslesarenko May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure the thrown exception comes from TypeSerializer. I.e. that the test is actually testing anything.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in new version.

property("max recursive call depth is checked in writer.level for TypeSerializer") {
val expr = Tuple(Tuple(IntConstant(1)))
an[SerializeCallDepthExceeded] should be thrownBy
ValueSerializer.serialize(expr, writer(maxTreeDepth = 2))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issues as with the previous test I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, the TypeSerializer was completely missing handling for maxTreeDepth for both de/serializing, added to both method and updated tests.

}
w.level = depth
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jozanek please reintroduce changes so that most of the code remain the same and number of red and green lines is minimal. Otherwise I cannot estimate what was actually changed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github diff tool is quite puzzled, had to break formatting to show it properly. I can add it in additional commit after PR is reviewed.

tpe
}

private def getArgType(r: SigmaByteReader, primId: Int, depth: Int) =
if (primId == 0)
deserialize(r, depth + 1)
deserialize(r)
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rollback changes in deserializer, it part of the consensus, where as serializer is not.
This PR don't need to touch consensus code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@aslesarenko aslesarenko added this to the v5.x milestone Jun 1, 2022
@aslesarenko aslesarenko changed the title Add threshold for maxTreeDepth for serializers [v5.0.1] Add threshold for maxTreeDepth for serializers Jun 1, 2022
@aslesarenko aslesarenko changed the base branch from v5.0-add-jit-costing-for-tests to v5.0.1-RC June 1, 2022 11:28
@jozanek jozanek force-pushed the v5.x-control-max-tree-depth branch 3 times, most recently from 129fdb0 to 91853dd Compare June 7, 2022 19:41
@jozanek jozanek force-pushed the v5.x-control-max-tree-depth branch from 91853dd to 595ef21 Compare June 7, 2022 19:49
@aslesarenko aslesarenko marked this pull request as draft December 23, 2022 11:39
@aslesarenko aslesarenko changed the base branch from v5.0.1-RC to v5.0.4-RC January 4, 2023 16:15
@jozanek
Copy link
Collaborator Author

jozanek commented Feb 17, 2023

@aslesarenko can you review again please and possibly merge?

@aslesarenko aslesarenko changed the base branch from v5.0.4-RC to develop February 20, 2023 15:47
@aslesarenko
Copy link
Member

@jozanek, this is low prioriity and considering how much unmerged code is there in develop already I'm putting this PR on hold.

@aslesarenko
Copy link
Member

After giving more thought into this I think this feature will complicate maintenance.
Depth limits on serialisation should exactly match measurements on deserialisation.
Any difference may lead to subtle bugs in dApps using Sigma (Appkit, Fleet).
And adversary can create malicious bytes directly anyway, so the value of this checks is small.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement all TODO v5.x
2 participants