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

Constantine 0.1.0 compilation error with Nim 2.2.0/2.0.10 on Win10/macOS Sonoma #474

Open
kornwind opened this issue Oct 5, 2024 · 4 comments

Comments

@kornwind
Copy link

kornwind commented Oct 5, 2024

After updating Nim from version 2.0.8 to 2.2.0, a compilation error appeared in Constantine 0.1.0:

D:\nim\choosenim>choosenim.exe 2.2.0
Info: C:\Users\kornw.choosenim\downloads\dlls.zip already downloaded
Extracting dlls.zip
Switched to Nim 2.2.0

D:\az\prg\nim\constantine_issue>nim c test_chacha20.nim
Hint: used config file 'C:\Users\kornw.choosenim\toolchains\nim-2.2.0\config\nim.cfg' [Conf] Hint: used config file 'C:\Users\kornw.choosenim\toolchains\nim-2.2.0\config\config.nims' [Conf] .....................................................................................................................
C:\Users\kornw.nimble\pkgs2\constantine-0.1.0-7dd8d47cf5c1bb7df2a501f1a7a4170fc4f6f23f\constantine\platforms\abstractions.nim(68, 34) template/generic instantiation of log2_vartime from here C:\Users\kornw.nimble\pkgs2\constantine-0.1.0-7dd8d47cf5c1bb7df2a501f1a7a4170fc4f6f23f\constantine\platforms\bithacks.nim(105, 28) Error: type mismatch: got 'cint' for 'log2_c_compiler_vartime(n)' but expected 'uint32'

The same thing happens when switching to Nim 2.0.10:

D:\nim\choosenim>choosenim.exe 2.0.10
Info: C:\Users\kornw.choosenim\downloads\dlls.zip already downloaded Extracting dlls.zip
Switched to Nim 2.0.10
D:\az\prg\nim\constantine_issue>nim c test_chacha20.nim Hint: used config file 'C:\Users\kornw.choosenim\toolchains\nim-2.0.10\config\nim.cfg' [Conf] Hint: used config file 'C:\Users\kornw.choosenim\toolchains\nim-2.0.10\config\config.nims' [Conf] ......................................................................................................................
C:\Users\kornw.nimble\pkgs2\constantine-0.1.0-7dd8d47cf5c1bb7df2a501f1a7a4170fc4f6f23f\constantine\platforms\abstractions.nim(68, 34) template/generic instantiation of log2_vartime from here C:\Users\kornw.nimble\pkgs2\constantine-0.1.0-7dd8d47cf5c1bb7df2a501f1a7a4170fc4f6f23f\constantine\platforms\bithacks.nim(105, 28) Error: type mismatch: got 'cint' for 'log2_c_compiler_vartime(n)' but expected 'uint32'

But if you go back to Nim 2.0.8, the application compiles without errors and works as expected:

D:\nim\choosenim>choosenim.exe 2.0.8
Info: C:\Users\kornw.choosenim\downloads\dlls.zip already downloaded Extracting dlls.zip
Switched to Nim 2.0.8
D:\az\prg\nim\constantine_issue>nim c test_chacha20.nim Hint: used config file 'C:\Users\kornw.choosenim\toolchains\nim-2.0.8\config\nim.cfg' [Conf] Hint: used config file 'C:\Users\kornw.choosenim\toolchains\nim-2.0.8\config\config.nims' [Conf] .......................................................................................................................
Hint: [Link]
Hint: mm: orc; threads: on; opt: none (DEBUG BUILD, -d:release generates faster code) 49336 lines; 1.103s; 70.945MiB peakmem; proj: D:\az\prg\nim\constantine_issue\test_chacha20.nim; out: D:\az\prg\nim\constantine_issue\test_chacha20.exe [SuccessX]


App source:

import
constantine/ciphers/chacha20,
ed25519

var
kPair1, kPair2: KeyPair
ss: SharedSecret
sd: Seed
data: string = "Hello, world!!!"
nonce: array[12, byte]

kPair1 = createKeypair(seed())
kPair2 = createKeypair(seed())

ss = keyExchange(kPair2[0], kPair1[1])
sd = seed()
copyMem(nonce[0].addr, sd[0].addr, len(nonce))

discard chacha20_cipher(ss, counter = 1, nonce, data)

echo "Encrypted: ", data

discard chacha20_cipher(ss, counter = 1, nonce, data)

echo "Decrypted: ", data

===

The situation repeats under mac OS Sonoma

@mratsim
Copy link
Owner

mratsim commented Oct 7, 2024

Can you confirm whether you are on the latest master branch? I had this error 2 weeks ago #469 but it was fixed in august.

I'll create a new release later in the day.

@kornwind
Copy link
Author

kornwind commented Oct 7, 2024

I updated Nim with the
choosenim 2.2.0,
then installed constantine to version 0.1.0 using
nimble install constantine.
It happened on October 4th. I suppose there was the latest up-to-date version of constantine on GitHub at that time?

@kornwind
Copy link
Author

kornwind commented Oct 7, 2024

I began to compare the sources of bithacks.nim on GitHub and those installed locally (attached screenshots). And I found that the code is different. It looks like nimble has installed something wrong.
bithacks_log2_vartime_GITHUB
bithacks_log2_vartime

@kornwind
Copy link
Author

kornwind commented Oct 7, 2024

I downloaded the code from GitHub as a zip and updated the library manually. Everything is going to be ready. Apparently, the point is that nimble, for some reason, receives an incorrect version from GitHub.

Thank you for your excellent libraries!

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

No branches or pull requests

2 participants