solana-idl-foundation / solana-idl-spec

Specifying a Solana IDL Standard, inspired from the Anchor IDL Standard
Apache License 2.0
20 stars 2 forks source link

Provide builtin type for `u256` and `i256` #6

Open seanyoung opened 1 year ago

seanyoung commented 1 year ago

Solidity uses 256 bit integer types, we would like them natively supported.

LucasSte commented 1 year ago

Solidity uses 256 bit integer types, we would like them natively supported.

Native support for them in Rust is complicated. If we are targeting Rust too, a proper standard/crate must be defined to support these types of integers across all Rust contracts.

callensm commented 1 year ago

has anyone looked at the viability of ethnum for providing the i256 and u256 type capabilities?

LucasSte commented 1 year ago

has anyone looked at the viability of ethnum for providing the i256 and u256 type capabilities?

I think this is a possibility. It works on an Anchor contract and the Rust eBPF compiler did not complain about it. It should be a temporary solution, until someone optimizes a library for BPF.

callensm commented 1 year ago

what needs to be done (or what adjustments to ethnum) to have a bpf/sbf optimized implementation?

seanyoung commented 1 year ago

I think this is a possibility. It works on an Anchor contract and the Rust eBPF compiler did not complain about it. It should be a temporary solution, until someone optimizes a library for BPF.

The ethnum crate leaves it up to llvm to implement optimized 256 bit arithmetic. It is up to the Solana llvm compiler team to make sure that the output is optimized for BPF.

What makes you think these routines are not optimized for BPF? The codegen should be the same as for most other 64 bit target (x86_64 has some special instructions which are useful here which are not available on BPF).

LucasSte commented 1 year ago

An update on this issue:

I added support for 256-bit integers on Anchor IDL and client-side code:

https://github.com/coral-xyz/anchor/pull/2260

LucasSte commented 1 year ago

An update on this issue:

I added support for 256-bit integers on Anchor IDL and client-side code:

coral-xyz/anchor#2260

Should I open a PR to update this data structure?