Closed colibrishin closed 1 year ago
After changing COMPILED_TIME_VAR, MemoryAccessViolation is thrown. Because public key and signature array sizes did not swap in bls binding. Had to change the const declaration and after than it worked.
Sorry for the late response.
I've added some codes such as bls_eth.cs
for the DLL with BLS_ETH.
https://github.com/herumi/bls/commit/4feb8e14e577496d59855fc05fbccb3cb1017f0f
I want to use
private fixed ulong v[SECRETKEY_UNIT_SIZE];
, then SECRETKEY_UNIT_SIZE
must be constant, so I think it is difficult to change those values in a constructor.
Do you have any good idea?
Thanks for your response. Sorry if I bothered you by closing the issue by myself.
No, I don't have any better idea. That's why I also go for hard-code. :( I'll give it a try with your dev branch.
And, one more thing. In C# binding, the ethereum's bls12_381 tests were failing. I don't have a clear reason why-, but
changing string
to byte[]
solves the problem. It seems taking a message as a string causes some difference during conversion (UTF8, ASCII or endianess?).
https://github.com/colibrishin/bls/commit/da82c1f787d912c40afbb9a0ec0b1de352bc1ea6
The dev branch works well on my side 👍 , but Serialize()
returns an unnecessarily large array of bytes 288 (e.g.. Signature.Serialize()
) by SIGNATURE_SERIALIZE_SIZE = SIGNATURE_UNIT_SIZE * 8
.
Thank you for the report. I've fixed it at https://github.com/herumi/bls/commit/6b0f6fe84968936559eee39d5ac2ce77bc9d53a1 .
I don't have a clear reason why-, but changing string to byte[] solves the problem.
Thank you for the advice. It's old apis. I supported it at https://github.com/herumi/bls/commit/3af40c71b42166b42c3e8737e5ce85fdbaf0f26f .
Thanks! Cross-validation with https://github.com/ethereum/bls12-381-tests is stuck at AggreateVerify
. I'll investigate further for debug.
In Progress...
FastAggreateVerify
is also failing however, If i mimic the behavior in C# (Aggregate Public Keys and call Verify()
) works fine.These are the keys, message and signature used for test.
input:
pubkeys: ['0xa491d1b0ecd9bb917989f0e74f0dea0422eac4a873e5e2644f368dffb9a6e20fd6e10c1b77654d067c0618f6e5a7f79a',
'0xb301803f8b5ac4a1133581fc676dfedc60d891dd5fa99028805e5ea5b08d3491af75d0707adab3b70c6a6a580217bf81',
'0xb53d21a4cfd562c469cc81514d4ce5a6b577d8403d32a394dc265dd190b47fa9f829fdd7963afdf972e5e77854051f6f']
message: '0xabababababababababababababababababababababababababababababababab'
signature: '0x9712c3edd73a209c742b8250759db12549b3eaf43b5ca61376d9f30e2747dbcf842d8b2ac0901d2a093713e20284a7670fcf6954e9ab93de991bb9b313e664785a075fc285806fa5224c82bde146561b446ccfc706a64b8579513cfc4ff1d930'
output: true
AggregateVerify
is bit complicated for me to mimic the behavior in C#. I tried to invoking with custom marshaler, and vectorized byte array, still fails.
input:
pubkeys: ['0xa491d1b0ecd9bb917989f0e74f0dea0422eac4a873e5e2644f368dffb9a6e20fd6e10c1b77654d067c0618f6e5a7f79a',
'0xb301803f8b5ac4a1133581fc676dfedc60d891dd5fa99028805e5ea5b08d3491af75d0707adab3b70c6a6a580217bf81',
'0xb53d21a4cfd562c469cc81514d4ce5a6b577d8403d32a394dc265dd190b47fa9f829fdd7963afdf972e5e77854051f6f']
messages: ['0x0000000000000000000000000000000000000000000000000000000000000000',
'0x5656565656565656565656565656565656565656565656565656565656565656', '0xabababababababababababababababababababababababababababababababab']
signature: '0x9104e74b9dfd3ad502f25d6a5ef57db0ed7d9a0e00f3500586d8ce44231212542fcfaf87840539b398bf07626705cf1105d246ca1062c6c2e1a53029a0f790ed5e3cb1f52f8234dc5144c45fc847c0cd37a92d68e7c5ba7c648a8a339f171244'
output: true
- Both of them use `PublicKey` struct array.
Okay, I'll check it later. Please wait for a while because I have a lot of work to do.
I added FastAggregateVerify and tests at https://github.com/herumi/bls/commit/0eacdc5788c5fd79a19d6247b40c853041221a9d . It seems okay.
Correct me if i'm wrong. What I have understood, FastAggregateVerify uses all public keys with aggregation. From the bls_c_impl.hpp, the definition of blsFastAggregateVerify
is taking a vector of publickey (or array of publicKey), but on the C# binding, the function defined use only one.
https://github.com/herumi/bls/blob/467dec02ecc89c05232953b1d0d20c3250fd87e6/ffi/cs/bls.cs#L466-L471
Passing the whole array fails the test on my side. Could you check whether it successes?
The TestFastAggregate runs well on my environments. Does not it run on yours?
but on the C# binding, the function defined use only one.
in pubVec[0]
of blsFastAggregateVerify
means to pass the head pointer of pubVec
and blsFastAggregateVerify
checks all of the array.
For example, if I comment out one element of pubVec
(https://github.com/herumi/bls/blob/dev/ffi/cs/bls_test.cs#L281), then the test fails.
Oh, Now I get it. Yes, it works on my machine too. passing the first address of array. I thought it would not be passed as pointer but only an array of index #0. Learned new thing.
Interesting to see that passing just array name with ref keyword is not working. 🤔
I have never thought about commenting out inputs. I'll try on AggregateVerify and see if it's work.
I've tried to pass the messages array with msg[0]
, and it seems like needs to be passed in another way. Do you have any clue about this..? https://github.com/colibrishin/bls/commit/42e6c38207c34e71c36e4967fc06f5e0d5903604
MSG_SIZE is 32 on Ethereum and byte[][]
does not mean C array.
I've added AggregateVerify to the dev branch.
Please see it.
https://github.com/herumi/bls/tree/dev
Thanks for your informative reply! I might have to hash the message before signing.
g_Q
should not be shared between other keys)?I have added a semaphore in code due to sharing local/static variables causing data corruption. What is your aspect of doing so (e.g.. Maybe like, static variable g_Q should not be shared between other keys)?
All functions of mcl/bls except for init
and some global configuration functions are thread-safe.
So we can use those functions in multi-thread after calling init().
g_Q
is constant after initialization.
If there are multiple instance of BLS, that saying multiple initialization is called, data shows different result. I'll prove with code later on. (Or, It might should track if it is already initialized once, not applying a semaphore for methods.)
If there are multiple instance of BLS, that saying multiple initialization is called, data shows different result.
If you do it, then the result will happen because blsInit is not thread-safe. https://github.com/herumi/bls/blob/master/include/bls/bls.h#L84
Why do you make multiple instances of BLS?
Sorry if it sounds aggressive but I'm not intended in such. My english skill is not good enough.
If I could, I wouldn't. As far as I know, the shared library created only once and requests are processed by one the loaded. Some classes using BLS (e.g., BLSPrivateKey or BLSPublicKey) will hold BLS library invoker for its own and it might be run in parallel.
For example, verifying block transactions for already in block chain and newly incoming block. Each cases will create two PublicKey and BLS library and they don't know whether library is initialized. (Fortunately, not thread-safeness has caught early in unit test. I wasn't aware of it.)
I think, If one doesn't create a PublicKey instance for required situation, then the BLS library will be passed and placed everywhere. That's why i wanted to do it such way. I would like to hear any suggestion.
(P.S. I added MultiVerify
in cs binding https://github.com/colibrishin/bls/commit/4a992583e96f5bbd1446e091efbda998261e9649 and it seems work.)
(P.S.2. I might have found the solution. I'll notify after double-check if it is working.)
Okay, I understand what you want. How about https://github.com/herumi/bls/commit/4e7800ce284f4367f98f35f604d92752dfb7e829 ?
Thanks! That's what i was going to do and wanted.
https://github.com/planetarium/bls-herumi/tree/master/ffi/cs
After some struggle, have done some modifications in C# binding for cross-platform. Would it be okay to publish in a NuGet package? and could you help me with what Id
is used for, and how the Share/Recover[Type]()
methods work?
I'll close this issue and create another due to the blsInit
problem has been solved.
I was planning to use this bls in C# with the binding you kindly made. If I set the
SET_ETH
, C# binding throws blsInit inInit()
.Compiled with CMake (+ VS 2019) with
SET_ETH=1
in windows x64 and uses a binding with C#, any other options stay the same.This is what returns when I run the bls.exe (C# binding) with previously built dll from CMake, and I tried to Init() with BLS12_381 and it also fails.
Some digging, I guess it seems to be a
MCLBN_COMPILED_TIME_VAR
related error. theerr
returns -246046.https://github.com/herumi/bls/blob/4a99be9f98669a59ef930765ddc546845c42dae7/ffi/cs/bls.cs#L15
https://github.com/herumi/bls/blob/4a99be9f98669a59ef930765ddc546845c42dae7/include/bls/bls.h#L12-L19