Skip to content

Swift issues #47

@mhewett-ks

Description

@mhewett-ks
  1. bls.swift: bls_hashit() is private but public in JavaScript. I need this function to be visible.

  2. fp.swift: The fp*.swift files are missing fromBytes() and toBytes().

  3. var x = FP(1) is throwing an error (see below). var x = FP(0) works fine.

I'm using a 64-bit version of the Swift library created using config64.py and selecting only option 21 (BLS381). For now I'm using the actual source files collected by config64.py rather than using the compiled library. The only modifications I've made to the AMCL code are to make bls_hashit public and to comment out the "import amcl" lines due to the way I have imported the files.

Here is the stacktrace:

ECP()
::y = FP(1)       ecp.swift: line 37
::::nres()          fp.swift: line 144
::::::d = BIG.mul(self.x, FP.r2modp);        fp.swift: 42
::::::self.x = FP.mod(DBIG(ROM.Modulus))   fp.swift: 43
::::::::BIG.monty(ROM.Modulus, ROM.MConst, d)   fp.swift:129
::::::::::let (top, bot) = BIG.muladd(a, b, c, r)             big.swift:940
::::::::::::let (tp,bt)=a.multipliedFullWidth(by: b) .        big.swift:107
::::::::::::var bot = Chunk(bt)&CONFIG_BIG.BMASK    big.swift:108

ERROR: Fatal error: Not enough bits to represent the passed value.

Here are the values of a, b, c, r, and bt above:

a = Chunk    262029922845399286
b = Chunk    143833713099123371 
c = Chunk    0
r = Chunk    145867405174699950
bt = 0b1000010111111001110001100101111000101010010000010000100001010010

In big.swift:108, bot is inferred to be an Int64.

Int64.multipliedFullWidth returns (Int64, UInt64) so bt is a UINT64.

Chunk is an Int64.

I would guess that the problem is with Chunk(bt) which is equivalent to Int64(UInt64).

Since bt has the high bit set the type conversion is not accepted.

Moving the bitmask op from outside to inside the parentheses isn't allowed by Swift due to type incompatibilities.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions