Coder Social home page Coder Social logo

Comments (13)

csjones avatar csjones commented on June 7, 2024

Hey @mattiaferrari02 👋

Would you mind sharing the relevant code? It's difficult to understand the compilation error without seeing how the secp256k1_surjectionproof is created in the first place.

from secp256k1.swift.

mattiaferrari02 avatar mattiaferrari02 commented on June 7, 2024

Ok sorry, this is a function that takes in input the secp256k1_surjectionproof data and creates the serialized version of the data used

@objc(proofSerialize:usedInputs:proofdata:)
    func proofSerialize(_ nInputs: NSNumber, usedInputs: NSString, proofdata: NSString) -> NSString {
        let context = secp256k1_context_create(UInt32(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY))!
        defer { secp256k1_context_destroy(context) }
        var proof: secp256k1_surjectionproof = secp256k1_surjectionproof()
        
        var parsedNInputs = nInputs as! Int
        var output = [UInt8](repeating: 0, count: 8258)
        var outLen: Int = Int()
        memcpy(&(proof.n_inputs), &parsedNInputs, MemoryLayout<size_t>.size)
        try! memcpy(&(proof.used_inputs), (usedInputs as String).bytes, 32)
        try! memcpy(&(proof.data), (proofdata as String).bytes, 8224) // This row causes compilation error
        
        secp256k1_surjectionproof_serialize(context, &output, &outLen, &proof)
        
        return String(bytes: output) as NSString
    }

from secp256k1.swift.

csjones avatar csjones commented on June 7, 2024

Looking over the API, I think you'll need to call secp256k1_surjectionproof_initialize and secp256k1_surjectionproof_generate before you get valid data from secp256k1_surjectionproof_serialize. If you're trying to load the struct with data, you'll need to use secp256k1_surjectionproof_parse and the package provides simple data copying functions so that you don't need memcpy.

from secp256k1.swift.

mattiaferrari02 avatar mattiaferrari02 commented on June 7, 2024

Screenshot 2022-12-29 at 11 20 25

Well ok, but the thing is that i can't ever use 'proof.data' because it isn't somehow recognised

from secp256k1.swift.

csjones avatar csjones commented on June 7, 2024

That's is odd because the secp256k1_surjectionproof struct doesn't seem to have a different access type when comparing to other structs supported by this package (likesecp256k1_ecdsa_recoverable_signature). When attempting to access the data property from secp256k1_ecdsa_recoverable_signature Swift, there are no issues which is what I would expect for you with secp256k1_surjectionproof.
Screenshot 2022-12-29 at 11 15 45 AM

You might have an issue exposing the Surjection Proof module to the codebase you're working in. I'll try and reproduce this issue from with this package. It's possible that we are missing something from the upstream secp256k1-zkp repo.

from secp256k1.swift.

mattiaferrari02 avatar mattiaferrari02 commented on June 7, 2024

I find it quite weird myself, but i guess as a workaround i'll need to write this code directly in c...
FYI i tried modifying manually the header file containing the struct of the secp256k1_surjectionproof, I replaced the length of the array with a much lesser number and then magically xcode didn't show the error anymore. At this point I think that's an error with the bridging header from c that somehow doesn't understand an array of that length.
Thanks for the help

from secp256k1.swift.

mattiaferrari02 avatar mattiaferrari02 commented on June 7, 2024

That's is odd because the secp256k1_surjectionproof struct doesn't seem to have a different access type when comparing to other structs supported by this package (likesecp256k1_ecdsa_recoverable_signature). When attempting to access the data property from secp256k1_ecdsa_recoverable_signature Swift, there are no issues which is what I would expect for you with secp256k1_surjectionproof. Screenshot 2022-12-29 at 11 15 45 AM

You might have an issue exposing the Surjection Proof module to the codebase you're working in. I'll try and reproduce this issue from with this package. It's possible that we are missing something from the upstream secp256k1-zkp repo.

Reguarding this, it seems that this is the reason https://developer.apple.com/forums/thread/125614
The swift bridge transforms the c arrays into tuples and there is a limitation of 4096 bytes to them, so the surjectionproof struct has an error because the length of data is 8224 but it should be interpreted correctly at compiler level

from secp256k1.swift.

csjones avatar csjones commented on June 7, 2024

but could you please try to call secp256k1_surjectionproof_parse with this hex string as input?

Hey @mattiaferrari02 do you still need help with this? I haven't made much progress

Reguarding this, it seems that this is the reason https://developer.apple.com/forums/thread/125614 The swift bridge transforms the c arrays into tuples and there is a limitation of 4096 bytes to them, so the surjectionproof struct has an error because the length of data is 8224 but it should be interpreted correctly at compiler level

This is a good find, thanks for sharing!

from secp256k1.swift.

mattiaferrari02 avatar mattiaferrari02 commented on June 7, 2024

but could you please try to call secp256k1_surjectionproof_parse with this hex string as input?

Hey @mattiaferrari02 do you still need help with this? I haven't made much progress

Yeah, still need help...
The serialized proof should be this 01000183c9c42d29f97befd28bc079a105ead7d36c5118cc4c1f542381cda81871bf121dfa5abc8ff90e4ad013c0666e6437dafc6a637f1853a6debc4c802b381032d8. This is 67 bytes long, is that correct? I read the code in of secp256k1_surjectionproof_parse but I did not understand how this string should become the 8224 bytes proof data

from secp256k1.swift.

csjones avatar csjones commented on June 7, 2024

Yeah, still need help... The serialized proof should be this 01000183c9c42d29f97befd28bc079a105ead7d36c5118cc4c1f542381cda81871bf121dfa5abc8ff90e4ad013c0666e6437dafc6a637f1853a6debc4c802b381032d8. This is 67 bytes long, is that correct? I read the code in of secp256k1_surjectionproof_parse but I did not understand how this string should become the 8224 bytes proof data

Are you using a reference implementation for Surjection Proof? I'm not aware of an official BIP that would tell us the expected bytes length.

from secp256k1.swift.

mattiaferrari02 avatar mattiaferrari02 commented on June 7, 2024

I don't know, everytime i tried it resulted like that

from secp256k1.swift.

csjones avatar csjones commented on June 7, 2024

@mattiaferrari02 I've started a draft PR with an initial implementation here: #325

Feel free to suggest any feedback you have 😁

EDIT: I'm still working through this documentation: https://elementsproject.org/features/confidential-transactions

from secp256k1.swift.

csjones avatar csjones commented on June 7, 2024

It's been a while since there was any activity on this thread. To keep issues organized, I'll be closing this thread. If you have any further questions or concerns related to this, please feel free to reopen it or create a new thread.

from secp256k1.swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.