Closed hadipourh closed 3 years ago
Could it be that the number of solutions is higher now due to additional switching variables? If you sort and filter the solutions with respect to the original input variables, the number of different solutions could be 256 as expected.
Greetings,
Axel
Hi,
First of all, thanks for the message. Indeed, @a1880 is on the right track -- we don't guarantee equivalent number of solutions. However, you can get the number of solutions as well. The way to do this is:
1) Get the CNF from Bosphorus by running: ./bosphorus --anfread myanf.anf --cnfwrite mycnf.cnf --solmap mysolmap.txt
2) Take the solution-var
variables in mysolmap.txt
, shift them up by 1, and add them to the CNF as c ind VAR1 VAR2 ... VARN 0
For example, if you have:
Internal-ANF-var 7 = solution-var 0
Internal-ANF-var 6 = solution-var 1
Internal-ANF-var 2 = solution-var 2
Internal-ANF-var 8 = solution-var 48
Internal-ANF-var 1 = solution-var 98
Write c ind 1 2 3 49 5 99
at the top of the CNF file (after p cnf ...
).
3) Run on CryptoMiniSat with:
./cryptominisat --maxsol 1000000 mycnf.cnf
Alternatively, you can run a projected model counter such as ApproxMC, it will use the projection set. This will work much better for large number of solutions (>500).
(Actually, this is such a great question, I will now fix this in the README and make it part of it)
Yay! I have now improved bosphorus
so you don't need to do all that complicated stuff above! You can just do this:
./bosphorus --anfread task2.txt --cnfwrite x.cnf
cryptominisat --maxsol 10000 x.cnf
The projection set is automatically written to the CNF :) Also, you can use approximate counting too!
./bosphorus --anfread task2.txt --cnfwrite x.cnf
approxmc x.cnf
I hope this helps. Also, I thanked you personally @hadipourh for this in the commit eaed7eac38f319728721136b5597b160228f6a8c and added a howto to the README :) Thanks again,
Mate
Thanks for your answers. The new feature added by Mate, makes the solution counting much easier. I appreciate it a lot.
As far as I know, the problem of ANF to CNF conversion has been well studied so far, and Bosphorus is one of the most efficient tools to do this task. However, to the best of my knowledge Bosphorus uses an extremely naive approach to convert a CNF to ANF in which the given CNF is translated to a set of ANF-s clause by clause. Hence, each clause is converted to an ANF individually without taking into account that whether there is an overlap between multiple clauses. Hence, it'd be very good if Bosphorus could support the more advanced methods such as the one proposed in On conversions from CNF to ANF. So, do you have a plan to improve the CNF to ANF converter of Bosphorus? If so, the Bosphorus will be a great bridge from the world of SAT solvers to the world of Algebraic methods.
Best wishes, Hosein
Hi,
That sounds like a great project for you to do it! I strongly recommend that you get working at once to implement it. You can start creating a Pull Request once you are done, please see here how:
We'll be glad to merge it, in case its quality is such that it can be merged with Bosphorus and it has associated test cases and/or fuzz tests as we have now.
Good luck with the work, and please let us know when you are done,
Mate
Hi,
I am creating a new tool in which CNF->ANF conversion is necessary. So, I'm currently implementing the algorithm proposed in On conversions from CNF to ANF. Let me know please if there is a better method. Given that Polybori is simply accessible via the SageMath, I'd prefer to create a preliminary prototype building upon the SageMath at first. Next, I'll try my best to work on Bosphorus, if I have enough time. I also will be happy if I can add it to the Bosphorus, and will inform you if I could do it.
Kind regards, Hosein
Hi,
I'd like to use the Bosphorus as a CNF to ANF converter in my new tool. However, I want to become sure whether the CNF reader works correctly. The following example taken from the previous closed issues represents that the CNF reader doesn't work properly. It should be noted that I reproduced the following results via the new version and noticed that there is still the same issue in the new version.
The attached file, contains the CNF of Skinny-128 Sbox in 'dimacs' format. The number of solutions for the given CNF must be 256, since it actually describe an 8-bit Sbox, and it is known that the number of possible (input, output) pairs, for a given 8-bit bijective Sbox must be 256. The CNF file has been attached, however you can reproduce it via the following command in SageMath:
CNF file: skinny64_sbox.zip I solved the above SAT problem via your nice tool, called CryptoMiniSat5 with the following command:
As you can see in solutions.zip, there are only 256 different solutions for this SAT problem. Let's simplify this CNF with the Bosphorus, to see whether it keeps the number of solutions unchanged or not. I simplified it via the following command:
The simplified version of the above SAT problem, has been included in the simplified.zip. When I solved the simplified.cnf with the CryptoMiniSat5, I observed that it has more than 256 solutions. I solved it via the following command:
As you can see in solutions1.txt file, there are more than 256 different solutions for the simplified CNF! So, I think the Bosphorus doesn't prereserve the equality. Let me know if I am wrong please.
Kind regards, Hosein
Originally posted by @hadipourh in https://github.com/meelgroup/bosphorus/issues/11#issuecomment-594105794