Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitvec Dependency Bug #72

Closed
gluax opened this issue Nov 17, 2022 · 2 comments · Fixed by #73
Closed

Bitvec Dependency Bug #72

gluax opened this issue Nov 17, 2022 · 2 comments · Fixed by #73
Labels
bug Something isn't working

Comments

@gluax
Copy link

gluax commented Nov 17, 2022

Describe the bug
cargo building in some use cases, for example with the conjunction of the near-sdk-rs crate, of this crate causes rust error E0034 caused by a dependency.

To Reproduce
The code:

use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::near_bindgen;
use blsttc::{Signature, PublicKey};

#[near_bindgen]
#[derive(Default, BorshDeserialize, BorshSerialize)]
pub struct VerifySignature;
#[near_bindgen]
impl VerifySignature {
    #[payable]
    pub fn verify_sig(&mut self, message: Vec<u8>, signature: Vec<u8>, public_key: Vec<u8>) -> bool {   
        let signature: [u8; 96] = signature.try_into().expect("invalid signature");
        let public_key: [u8; 48] = public_key.try_into().expect("invalid pk");
        let sig = Signature::from_bytes(signature).expect("couldn't read signature");
        let pk = PublicKey::from_bytes(public_key).expect("couldn't read pk");
        pk.verify(&sig, message)
        
    }
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(test)]
mod tests {
    use super::*;
    use near_sdk::test_utils::VMContextBuilder;
    use near_sdk::{testing_env, VMContext};

    use blsttc::{PublicKey, SecretKey};


    fn get_context(is_view: bool) -> VMContext {
        VMContextBuilder::new()
            .signer_account_id("bob_near".parse().unwrap())
            .is_view(is_view)
            .build()
    }

    #[test]
    fn verify_msg() {
        let context = get_context(false);
        testing_env!(context);
        let mut contract = VerifySignature::default();

        let sk = SecretKey::random();
        let pk = sk.public_key();
        let message = "hello".try_to_vec().unwrap();
        let sig = sk.sign(message.clone());
        
        println!("sk: {:?}", sk);
        println!("pk: {:?}", pk);
        println!("sig: {:?}", sig);

        println!("pk_bytes: {:?}", pk.as_bytes());
        println!("sig_bytes: {:?}", sig.as_bytes());
        println!("sig_bytes: {:?}", sig.as_bytes());

        let sig_bytes = sig.to_bytes().to_vec();
        let pk_bytes= pk.to_bytes().to_vec();
        let verified = contract.verify_sig(message, sig_bytes, pk_bytes);

        println!("verified: {:?}", verified);

    }

}```

Deps:
```toml
near-sdk = "4.0.0"
blsttc = {version = "8.0.0"}
getrandom = {version = "0.2.8", features = ["js"]}

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
image

Versions
near-sdk: 4.0
blsttc: 8.0.0(this crate has since updated to version 8.0.0, but this still remains an issue).

Happens on linux and windows.

Additional context
Seems to be a known bug that affects older versions of the bitvec crate. I think since both crates import different versions somewhere down the line the issue is exposed when compiling.

This can be fixed by updating the version of the blstrs crate in the direct dependencies list and would be greatly appreciated :)

@gluax gluax added the bug Something isn't working label Nov 17, 2022
@gluax gluax changed the title Bitvec Dependency bug. Bitvec Dependency Bug Nov 17, 2022
@davidrusu davidrusu mentioned this issue Nov 17, 2022
@davidrusu
Copy link
Contributor

Thanks for the report, I did not reproduce the build failure locally but it's a good idea to keep dependencies updated anyways.

I've bumped blstrs in #73, hopefully that resolves your build issues. Please give us a shout if you still have problems

@gluax
Copy link
Author

gluax commented Nov 17, 2022

Can confirm if I set blsttc = { git = "https://github.com/maidsafe/blsttc", branch = "drusu/bump-blstrs-0.6.1" } in our cargo toml file this resolves the issue. Thanks a bunch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants