near / near-sdk-rs

Rust library for writing NEAR smart contracts
https://near-sdk.io
Apache License 2.0
457 stars 245 forks source link

Implement safe APIs for bn128 APIs #644

Open austinabell opened 2 years ago

austinabell commented 2 years ago

Similar to #642, not really sure there is a strong use case for this so I wouldn't jump into this yet, just adding the issue for tracking. bn128 is pairing cryptography used in zk proofs in ethereum. I assume these syscalls were added since they are precompiles for Ethereum and needed for Aurora, but I'm sure we can create an API that makes this consumable outside of this context!

I have no idea what this API would look like, whether it's a thin wrapper around the syscall or not. Open to ideas or thoughts.

austinabell commented 2 years ago

Related, but now out of date implementation https://github.com/near/near-sdk-rs/pull/188

The API added in this is very low level, and we might want to have a higher-level abstraction for zk proofs. Or maybe we stay unopinionated and let libraries be built on top of this interface.

(Would be nice to get Igor's input on this, but I don't know his github username to tag him)

itegulov commented 2 years ago

@austinabell are you talking about Igor Gulamov? If so, I believe he is the original author of #188

austinabell commented 2 years ago

@austinabell are you talking about Igor Gulamov? If so, I believe he is the original author of #188

Nope, Igor that just joined and is working on zk

PandaRR007 commented 2 years ago

I see bn128 APIs are supported in nearcore and near-sdk-js with nightly feature, but not in near-sdk-rs. We need this feature in our rust contract, and I think more and more projects need it. Is there any plan to implement these APIs in near-sdk-rs recently? Will it be supported in next release? Thanks.

austinabell commented 2 years ago

We will add higher-level APIs once the protocol change is upgraded on mainnet. The plan for the host function is to come in the next protocol upgrade (not this upcoming one that will happen on Tuesday).

The host function definition exists in near-sys currently which is accessible from the SDK or by itself, so anyone is able to easily create an API on top of this externally.

It's not quite clear what this API looks like to be helpful in a general use case.

PandaRR007 commented 2 years ago

Got it, thanks @austinabell .

frol commented 1 year ago

FYI, we exposed raw alt_bn128 methods in #1028. There is no high-level API for it yet, so this issue should not be closed, but I don't think it is a priority for near-sdk-rs team as none of us have experience with these APIs to design nice safe APIs.