Comments (13)
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.
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.
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.
from secp256k1.swift.
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
.
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.
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.
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 thedata
property fromsecp256k1_ecdsa_recoverable_signature
Swift, there are no issues which is what I would expect for you withsecp256k1_surjectionproof
.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.
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.
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.
Yeah, still need help... The serialized proof should be this
01000183c9c42d29f97befd28bc079a105ead7d36c5118cc4c1f542381cda81871bf121dfa5abc8ff90e4ad013c0666e6437dafc6a637f1853a6debc4c802b381032d8
. This is 67 bytes long, is that correct? I read the code in ofsecp256k1_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.
I don't know, everytime i tried it resulted like that
from secp256k1.swift.
@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.
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)
- Why my web app and ios app gets different shared secret? HOT 13
- Code example of signing using hashed message? HOT 4
- library release on cocoapods? HOT 10
- Could not find module 'secp256k1' for target 'x86_64-apple-ios-simulator' HOT 3
- nvm I need the podspec for this, i'm so sorry... HOT 2
- Contructing a PublicKey with rawRepresentation fails with incorrect size HOT 3
- Differenct signature result with other libraries HOT 2
- Do you have any examples of how you would sign a taproot input using this library? HOT 1
- Did library already support sign a taproot input? HOT 4
- Taproot address format HOT 9
- Cannot install package via SPM when importing it from another package HOT 3
- Is it possible to generate an invalid PrivateKey when no secret it passed? HOT 9
- How to use secp256k1_ec_pubkey_combine HOT 10
- How to create PrivateKey by importing pem private key? HOT 7
- Test/Example for `sharedSecretFromKeyAgreement` with `handler`? HOT 8
- xcodebuild fails for 0.13.0 HOT 1
- secp256k1/ECDH.swift:180:20 Value of type 'UnsafeMutablePointer<UInt8>' has no member 'update' HOT 1
- #include "./secp256k1.h" Report an error './secp256k1.h' file not found HOT 6
- Is there really a random k injected when calculating an ECDSA signature ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from secp256k1.swift.