logoalt Hacker News

Show HN: Formally verified 3D CSG: Trust 93 lines spec, not 1000 lines AI code

102 pointsby permutetoday at 1:07 PM44 commentsview on HN

To my knowledge, this is the first formally verified implementation of a 3D constructive solid geometry (CSG) operation: mesh intersection, implemented in Lean 4 and verified against a concise specification that pins down the surface of the resulting mesh exactly and guarantees practical well-formedness conditions on the triangulation.

This project is also an experiment in avoiding having to trust AI-generated code. A human reviewer only needs to read 93 lines of formal specification and run the Lean checker to certify the correctness of the kernel, skipping the intricate 1000+ lines of AI-written implementation. To prove correctness, AI autonomously wrote over 60,000 lines of Lean proofs, which also never have to be inspected by a human. The Lean checker guarantees conformance to the specification at compile time, with zero trust placed in any LLM. This allows us to treat the implementation and proofs as a black box. I guided the agent through the milestones described in the readme to arrive at the result presented here.

Also take a look at the web demo https://schildep.github.io/verified-3d-mesh-intersection/, which runs the verified mesh intersection kernel compiled to WebAssembly in your browser.


Comments

permutetoday at 1:20 PM

Note that the claims are about the kernel that computes the mesh intersection, not the web demo: While the kernel is formally verified, the UI and glue code (that call the kernel) are not. I once hit a bug that looked like there were holes in the resulting mesh: I found that it was an overflow in the glue code (now fixed) that converts the exact rationals coordinates of the output mesh, for which we prove the specification, to floats before sending them to the GPU. All geometry is happening inside the kernel, for which we know the specification holds.

bob1029today at 1:42 PM

This is really neat. I think CSG is one of the more intuitive ways to build 3d environments (especially 'indoor' ones). No geometry is ever destroyed in a proper CSG workflow. A hierarchy of brushes makes it possible to very rapidly iterate parameters like how long a hallway is or the time it takes to get from one objective to another. Often, you only have to apply a transform to a single brush to affect something that would take a non-CSG workflow an entire afternoon to recover from.

The current story with CSG around commercial game engines is pretty awful. Unity has some 3rd party options that can work well but they're also glitchy and don't integrate well with the other parts of the ecosystem. For a while I thinking about building my own CSG implementation but the exact things this project solved were what was stopping me. The EditorWindow integration stuff is not as scary to me (although it is painful). The advanced geometry and set operations is what kept me from trying. It appears that dragon has been (at least partially) slain.

show 1 reply
brandonpelfreytoday at 2:32 PM

This seems like very cool work. I'm sorry if I missed it: I'm still not sure how we go from verified proof (Great!) to an implementation (by LLM or by Human) which you're sure actually conforms to the proof? How do we know that the implementation maps precisely to the description within the proof?

show 3 replies
agentultratoday at 1:44 PM

> A human reviewer only needs to read 93 lines of formal specification and run the Lean checker to certify the correctness of the kernel, skipping the intricate 1000+ lines of AI-written implementation. To prove correctness, AI autonomously wrote over 60,000 lines of Lean proofs, which also never have to be inspected by a human.

I am curious about the approach as I find claims like this hard to believe. There is a theory behind proof kernels that they must be small because they have to be trusted and verifiable by a human. Otherwise the whole system breaks.

How does one trust an LLM generated kernel is proving the right things?

show 2 replies
swiftcodertoday at 3:11 PM

Ok, that's very cool. I don't yet grasp exactly how this deals with numerical stability - the one true enemy of mesh-based CSG operations

show 3 replies
iFiretoday at 1:32 PM

How does it compare against https://github.com/elalish/manifold in performance and zero corruption?

I spent a lot of time making elalish/manifold work in Godot Engine and it is now a method in Blender too.

https://manifoldcad.org

If it helps, feel free to use the apache2 licensed unit tests that were generated in manifold development https://github.com/elalish/manifold/tree/master/test

show 2 replies
peetletoday at 3:36 PM

This is a really cool project. Love it. Why not extend to union, difference, and xor? Is that exercise left to the reader or is it not tractable? ;)

I'm also curious if you've consider fuzz testing this system to verify the results.

show 2 replies
_benttoday at 4:56 PM

Would you still be able to deal with coplanar faces if you were to expand this to floats?

show 1 reply
outoftheweedtoday at 6:39 PM

no lean background here so the proofs are over my head, but the framing makes sense to me. everything i've shipped that claude co-wrote, the thing that made me trust it was running it end to end, never reading it. having a checker do that part is a way better deal.

CyLithtoday at 1:49 PM

The issue I have with all these formally verified numerical algorithms is that, at the end of the day, I need this implemented using actual floating point. It's great that it's verified, but not for the case that is practically meaningful. Unless it's implemented using hardware accelerated floating point, most of these algorithms are not sufficiently performant to be practically useful.

show 3 replies
bartvktoday at 1:54 PM

Congrats with this achievement. Do you see it possible that this project can be integrated into, for example, FreeCAD?

show 3 replies
bogwogtoday at 2:48 PM

Honestly I think I'd have an easier time understanding 1000s of lines of slop than 93 lines of proofs lol.

Does anyone have any recommended learning resources for this type of thing? Skimming the repo, it looks like a lot of unicode and math terminology, but this project seems really compelling to me.

show 1 reply
myshapeprotocoltoday at 4:32 PM

[dead]

CuriousBuildertoday at 1:54 PM

[flagged]

redsocksfan45today at 1:36 PM

[dead]