You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code snippets break highlighting in all kind of ways:
Case 1
Exception in case statement
shl in proc parameter
shl in array type
whenisMainModule:
import../io/io_bigints
proctoString(glvSac: GLV_SAC): string=for j in0..< glvSac.M:
result.add"k"&$j &": ["for i incountdown(glvSac.LengthInDigits-1, 0):
result.add""& (block:
case glvSac[j][i]
of-1: "1\u{0305}" of0: "0" of1: "1"else:
raisenewException(ValueError, "Unexpected encoded value: "&$glvSac[j][i])
) # " # Unbreak VSCode highlighting bugresult.add" ]\n"funcbuildLookupTable[M: staticint](
P: string,
endomorphisms: array[M-1, string],
lut: vararray[1shl (M-1), string],
) =# Checking the LUT by building strings of endomorphisms additionsfor u in0..<1shl (M-1):
# The recoding allows usage of 2^(n-1) table instead of the usual 2^n with NAF
lut[u] = P
for u in0..<1shl (M-1):
for idx, bit inbits(u):
if bit ==1:
lut[u] &=" + "& endomorphisms[idx]
procmain() =const M =4# GLS-4 decompositionconst miniBitwidth =4# Bitwidth of the miniscalars resulting from scalar decompositionvar k: MultiScalar[M, miniBitwidth]
var kRecoded: GLV_SAC[M, miniBitwidth+1]
k[0].fromUint(11)
k[1].fromUint(6)
k[2].fromuint(14)
k[3].fromUint(3)
kRecoded.nDimMultiScalarRecoding(k)
echo kRecoded.toString()
var lut: array[1shl (M-1), string]
let
P ="P0"
endomorphisms = ["P1", "P2", "P3"]
buildLookupTable(P, endomorphisms, lut)
echo lut
doAssert lut[0] =="P0"doAssert lut[1] =="P0 + P1"doAssert lut[2] =="P0 + P2"doAssert lut[3] =="P0 + P1 + P2"doAssert lut[4] =="P0 + P3"doAssert lut[5] =="P0 + P1 + P3"doAssert lut[6] =="P0 + P2 + P3"doAssert lut[7] =="P0 + P1 + P2 + P3"main()
Case 2
emit
funcunsafeDiv2n1n*(q, r: varCt[uint64], n_hi, n_lo, d: Ct[uint64]) {.inline.}=## Division uint128 by uint64## Warning ⚠️ :## - if n_hi == d, quotient does not fit in an uint64 and will throw SIGFPE on some platforms## - if n_hi > d result is undefined
{.warning: "unsafeDiv2n1n is not constant-time at the moment on most hardware".}
var dblPrec {.noInit.}: uint128
{.emit:[dblPrec, " = (unsigned __int128)", n_hi," << 64 | (unsigned __int128)",n_lo,";"].}
# Don't forget to dereference the var param in C modewhendefined(cpp):
{.emit:[q, " = (NU64)(", dblPrec," / ", d, ");"].}
{.emit:[r, " = (NU64)(", dblPrec," % ", d, ");"].}
else:
{.emit:["*",q, " = (NU64)(", dblPrec," / ", d, ");"].}
{.emit:["*",r, " = (NU64)(", dblPrec," % ", d, ");"].}
funcmul*(hi, lo: varCt[uint64], a, b: Ct[uint64]) {.inline.} =## Extended precision multiplication## (hi, lo) <- a*b#### This is constant-time on most hardware## See: https://www.bearssl.org/ctmul.htmlblock:
var dblPrec {.noInit.}: uint128
{.emit:[dblPrec, " = (unsigned __int128)", a," * (unsigned __int128)", b,";"].}
# Don't forget to dereference the var param in C modewhendefined(cpp):
{.emit:[hi, " = (NU64)(", dblPrec," >> ", 64'u64, ");"].}
{.emit:[lo, " = (NU64)", dblPrec,";"].}
else:
{.emit:["*",hi, " = (NU64)(", dblPrec," >> ", 64'u64, ");"].}
{.emit:["*",lo, " = (NU64)", dblPrec,";"].}
The text was updated successfully, but these errors were encountered:
mratsim
changed the title
Hightlighting bugs
Highlighting bugs
Jun 7, 2020
The following code snippets break highlighting in all kind of ways:
Case 1
shl
in proc parametershl
in array typeCase 2
The text was updated successfully, but these errors were encountered: