👋 Had a question about the implementation of impl_bignum_host_fns in the env (https://github.com/stellar/rs-soroban-env/blob/main/soroban-env-host/src/host/num.rs#L28) that I ran into while trying to add more num functions to the SDK's [u/i]256 bit structs.
It looks like I should be able to perform a bad action (for example. env.i256_add(i256::MAX, 123))) and get an Error returned to the caller.
When testing adding checked_ variations of the i256 and u256 functions, I'm seeing it panic instead of return a Result(Error) with:
Event log (newest first):
0: [Diagnostic Event] topics:[error, Error(Object, ArithDomain)], data:"escalating error to panic"
1: [Diagnostic Event] topics:[error, Error(Object, ArithDomain)], data:["overflow has occured", 115792089237316195423570985008687907853269984665640564039457584007913129639935, 1]
Code (soroban-sdk/src/num.rs):
pub fn checked_add(&self, other: &U256) -> Option<U256> {
self.env.check_same_env(&other.env).unwrap_infallible();
if let Ok(val) = self.env.u256_add(self.val, other.val) {
Some(U256 {
env: self.env.clone(),
val,
})
} else {
None
}
}
Mostly confused because the self.err code path doesn't look like it forces a panic anywhere. Would appreciate some thoughts!