Skip to content

Btor2Xcfa #348

Draft
szaboeva2004 wants to merge 82 commits intoftsrg:masterfrom
szaboeva2004:btor2xcfa
Draft

Btor2Xcfa #348
szaboeva2004 wants to merge 82 commits intoftsrg:masterfrom
szaboeva2004:btor2xcfa

Conversation

@szaboeva2004
Copy link
Copy Markdown

@szaboeva2004 szaboeva2004 commented Mar 3, 2025

🚀 Description

This PR introduces a direct frontend and transformation pipeline for BTOR2 hardware descriptions. By bypassing external intermediate C translation steps (such as Btor2C), this direct approach avoids the semantic mismatches and structural bloat associated with simulating hardware concurrency in sequential C code.

Key Impacts:

  • Significantly Reduces Structural Complexity: The direct transformation yields a highly concise intermediate representation, reducing variable counts by ~66% and atomic statements by ~82% compared to indirect methods.
  • Enhances Verification Efficiency: Provides a cleaner, less redundant state space that drastically lowers the memory footprint and improves algorithmic success rates, particularly for solvers utilizing predicate abstraction.

🛠️ Key Changes

Frontend & Parsing

  • Added Unofficial BTOR2 Grammar: Built using ANTLR4 to enable systematic parsing of domain-specific BTOR2 hardware descriptions.
  • Implemented Visitor Model: Allows for structured extraction and processing of circuit elements for transformation.

Core Logic & Transformation

  • BTOR2 to XCFA Transformation: Created a direct pipeline that maps hardware circuits to formal verification models.
  • Native Semantic Preservation: Bit-vector types now map directly to underlying SMT solver types, preserving precise semantics without manual bit-masking or temporary variables.
  • Natural Loop Representation: Cyclic hardware behavior and state updates are natively expressed as graph loops within the control-flow representation.
  • Systematic Node Mapping: Accurately maps core BTOR2 concepts, including constants, initial states (init), unconstrained inputs (havoc), sequential operations, safety properties (bad), and state transitions (next).
  • Optimizations: Implemented Btr2Passes to seamlessly integrate with the existing suite of optimization techniques already provided by Theta.
  • Witness Generation (Experimental): Added support for BTOR2 witness generation to .sat files. If the input is BTOR2, a .sat file is generated matching the BTOR2 witness format.

🧪 Testing

  • Manual Testing Resources: Added some HWMCC benchmark .btor2 and configuration files to validate the direct transformation workflow and witness generation, mostly for run configurations.

⚠️ Known Limitations & Future Work

  • Incomplete Language Support: Currently lacks support for the BTOR2 array sort and associated operations (e.g., read, write), preventing the verification of designs that rely on memory modeling.
  • Missing Operators: Specific arithmetic and bit-manipulation operators, such as overflow predicates (saddo, uaddo, etc.) and reduction operations (redand, redor, redxor), are not yet supported.
  • Limited Property Scope: Verification is currently restricted to safety properties (bad states). Liveness properties (e.g., justice, fairness) and other temporal specifications remain unsupported.
  • Witness Generation Testing: The .sat witness generation feature is experimental and needs to be validated by btor2sim.

✅ Checklist

  • Added an unofficial BTOR2 grammar
  • Implemented the Visitor model for the BTOR2 frontend
  • Implemented BTOR2 circuit to XCFA transformation
  • Added resources for test purposes
  • Implemented BTOR2 witness generation to .sat files

@szaboeva2004 szaboeva2004 marked this pull request as ready for review March 3, 2025 11:09
@szaboeva2004 szaboeva2004 marked this pull request as draft March 3, 2025 11:09
@AdamZsofi AdamZsofi self-requested a review March 3, 2025 12:41
@AdamZsofi AdamZsofi added enhancement xcfa Issue is XCFA specific (not core or XSTS or other formalisms) labels Mar 3, 2025
@AdamZsofi
Copy link
Copy Markdown
Member

AdamZsofi commented Mar 30, 2026

@szaboeva2004

  • I approved the CI to run, please check when it's done what's left to do based on that - I can already see that spotless needs to be run.
  • If witness generation is untested, can you remove or at least disable it, please? I think the witnesses can go into a separate PR later. If this is done, please unmark "draft", it's a proper PR now. :)

In the meantime, I'll do a quick review and ask others for review as well, but we can parallelize there.

@AdamZsofi AdamZsofi requested a review from mondokm March 30, 2026 10:20
@AdamZsofi
Copy link
Copy Markdown
Member

@mondokm I could not add Dani as a reviewer, but I think it's you two who are the main stakeholders in Btor2Xcfa currently - can either of you please review? Thanks!

Copy link
Copy Markdown
Member

@AdamZsofi AdamZsofi left a comment

Choose a reason for hiding this comment

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

I left quite a few small tasks, but overall, I think the frontend is a really nice shape, great work! You are almost there. :D


override fun getExpr(): Expr<BvType> {
val newU: BigInteger = u + BigInteger.valueOf(1)
// val newU: BigInteger = if (u == l) u + BigInteger.valueOf(1) else u
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remove commented code if not needed

}

override fun getStmt(): Stmt {
TODO("We might not even need this Stmt for states")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this a comment or a todo? What's the solution? If it's not implemented on purpose, please throw an appropriate exception, not a TODO

}

override fun getExpr(): Expr<*> {
TODO("Not yet implemented")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not implemented? Can it be? Or exception instead of TODO?

private val operationVisitor = OperationVisitor()
private val statefulVisitor = StateVisitor()

// private val logger = ConsoleLogger(Logger.Level.VERBOSE)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either remove or uncomment. Would be nice to have some verbose level logging, so maybe uncomment, if possible?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same for all the other logger calls around here.

val size = sort.width.toInt()
val binArray =
BooleanArray(size) { index ->
val hexDigit = value[index / 4]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These 3 lines are a bit of a magic code - can you maybe leave a short comment on how this formula works here?

var disable: Boolean = false,
@Parameter(names = ["--induction-solver", "--ind-solver"], description = "Induction solver name")
var indSolver: String = "Z3",
var indSolver: String = "mathsat:5.6.10",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was this changed on purpose? If not, change back, please. :)

description = "Interpolation solver name",
)
var itpSolver: String = "Z3",
var itpSolver: String = "mathsat:5.6.10",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was this changed on purpose? If not, change back, please. :)

data class MddConfig(
@Parameter(names = ["--solver", "--mdd-solver"], description = "MDD solver name")
var solver: String = "Z3",
var solver: String = "mathsat:5.6.10",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was this changed on purpose? If not, change back, please. :)

data class Ic3Config(
@Parameter(names = ["--solver", "--mdd-solver"], description = "MDD solver name")
var solver: String = "Z3",
var solver: String = "mathsat:5.6.10",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was this changed on purpose? If not, change back, please. :) (And just use the flag when running Theta, isntead of changing it in code?)

@@ -0,0 +1,92 @@
/*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please quickly remove the witnesses from this PR to a separate branch, so that half-done code is not merged to master.

@AdamZsofi AdamZsofi requested a review from dantpu March 31, 2026 12:42
fun visit(node: Btor2Const, param: P): R
}

object Btor2Circuit {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the parsed circuit being a singleton object is not a good pattern, we should instantiate a different object for each parsing.

}
}

// Ehhez a nidhez vezetünk be egy változót, bekötjük
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please only add english comments, or remove if this is not important

val visited = mutableSetOf<XcfaEdge>()
while (toVisit.isNotEmpty()) {
val visiting = toVisit.removeFirst()
val visiting = toVisit.removeAt(0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the reason for this change? I see that it was applied to quite a few files

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove this

implementation("com.zaxxer:nuprocess:2.0.5")
implementation("org.jetbrains.kotlin:kotlin-scripting-jsr223:${Versions.kotlin}")
implementation(project(mapOf("path" to ":theta-btor2-frontend")))
implementation(project(mapOf("path" to ":theta-btor2xcfa")))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pleae use the format that is used above for both imports:
implementation(project(":theta-btor2-frontend"))
implementation(project(":theta-btor2xcfa"))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement xcfa Issue is XCFA specific (not core or XSTS or other formalisms)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants