SIMD-0129

Alt_BN128 Syscalls - Simplified Error Code

Author: Emanuele Cesena · Category: Core Protocol GitHub →

Feature Gate Status

Mainnet Active E635
Testnet Active E644
Devnet Active E714

JDn5q3GBeqzvUa7z67BbmVHVdE3EbUAjvFep3weR3jxX

TL;DR

Simplify the return error code for the family of Alt_BN128 syscalls: `sol_alt_bn128_group_op`, `sol_alt_bn128_compression` and `sol_poseidon`. A single error code is sufficient, in line with all other syscalls.

Summary

Simplify the return error code for the family of Alt_BN128 syscalls: `sol_alt_bn128_group_op`, `sol_alt_bn128_compression` and `sol_poseidon`. A single error code is sufficient, in line with all other syscalls.

Motivation

Syscalls in Solana can return: - Success, e.g. represented in Rust as `Ok(0)` or `Ok(SUCCESS)` - Error to the program, e.g. represented in Rust as `Ok(1)` - Fatal error to the VM, aborting the transaction, e.g. represented in Rust as `Err(<something>)` Most syscalls only have a single error code returned to the program, i.e. `Ok(1)`. The family of Alt_BN128 syscalls, vice versa, has a richer set of error codes. This proposal aims to simplify the error value for these syscalls, in line with all the other syscalls, and simply return `Ok(1)` (in addition to fatal errors, that are left unchanged). We stress that multiple error codes cause a maintenance burden for the validators. Moreover, if two different implementation were to return different error codes, an attacker could exploit the different behavior to cause consensus failure.

Key Changes

  • group_op: the operation to perform:
  • 0: point add in G1
  • 1: (reserved for) point sub in G1
  • 2: scalar multiplication in G1
  • input: the serialized inputs to the operation.
  • Input and output depend on the operation. In all cases they are serialized in standard big endian format.
  • Points and scalars must be validated.
  • Point sub in G1 is not implemented. The group_op value 1 is reserved.
  • Validate group_op is 0, 2, or 3 (known operation).
  • Compute units
  • Memory mapping for input/output
  • op: the operation to perform:
  • 0: G1 compress
  • 1: G1 decompress
  • 2: G2 compress
  • 3: G2 decompress
  • input: the input point to compress / decompress, serialized in standard big endian format.
  • Validate op is 0, 1, 2, or 3 (known operation).
  • parameters: 0 to represent the choice of the Alt_BN128 curve.
  • endianness: 0 for big endian input/output, 1 for little endian.

Impact

Implementing the error logic inside validators will be much easier and less error prone. Dapp developers will have less fine-grained errors, but this is in line with all the other syscalls.

Backwards Compatibility

The syscall `sol_alt_bn128_group_op` is enabled in testnet, therefore we'll feature gate the change. Programs using this syscall may need to adapt to the simplified error code, but this isn't expected to be an issue in practice. For simplicity, we'll keep the change to all 3 syscalls under the same feature gate.

Security Considerations

Simplifying to one single error code reduces the risk of two different validator implementations returining different error codes, which could be exploited to cause a consensus failure. This change will also hide some internal implementation details, for example the err code `TryIntoVecError`, which is a plus from a security perspective. The implementation should be straightforward: change the return from `Ok(err_num)` to `Ok(1)`, so low risk.