Skip to content

[WIP] - #129

Closed
bbyalcinkaya wants to merge 1 commit into
masterfrom
feat/i256-host-support
Closed

[WIP]#129
bbyalcinkaya wants to merge 1 commit into
masterfrom
feat/i256-host-support

Conversation

@bbyalcinkaya

Copy link
Copy Markdown
Member

No description provided.

…t object tags

Three defects in the I256 support added by #127, each checked against the
Soroban host rather than against the surrounding rules.

- The i256 arithmetic host functions report `(Object, ArithDomain)`, not
  `(Value, ArithDomain)`. The 6-argument arm of `impl_bignum_host_fns!` builds
  its error with `ScErrorType::Object`
  (soroban-env-host/src/host/num.rs:39-45), and `i256_add`, `_sub`, `_mul`,
  `_div` and `_rem_euclid` all expand through that arm
  (soroban-env-host/src/host.rs:1568-1578).

- `i256_rem_euclid` accepted `i256::MIN` by `-1` and returned `0`. `I256` is
  `ethnum::I256` (soroban-env-common/src/num.rs:10), whose
  `checked_rem_euclid` rejects `rhs == 0 || (self == MIN && rhs == -1)`
  (ethnum-1.5.2/src/int/api.rs:635-641) -- the same two pairs as
  `checked_div`, even though the mathematical remainder is representable.
  This was a silent wrong answer, not a stuck term.

  The comment above the rule was also wrong about `modInt`: K's `modInt` is
  e-division and always lands in `[0, absInt(B))` (domains.md:1262), so
  `absInt(B)` is redundant rather than load-bearing. Left the expression
  alone, corrected the claim.

- `getTagWithFlag(true, _)` was missing both 256-bit types. Under
  `alwaysAllocate`, `addObject` tags the handle with `getTagWithFlag(AA, SCV)`;
  with no entry, a value that fits the small encoding fell through to `owise`
  and took `getTag`, so an object stored in `<hostObjects>` was tagged
  `U256Small` (12) / `I256Small` (13). `isObject` is tag 64..77, so such a
  handle then failed `isObject` and `loadObject` took the `-small` branch,
  making `fromSmall` decode the object index as the value. U64, I64, U128,
  I128 and Symbol all carry this line for that reason; U256 and I256 were the
  only two small-capable types missing it.

Tag numbers confirmed against `Tag` in soroban-env-common/src/val.rs
(`U256Small = 12`, `U256Object = 70`, `I256Small = 13`, `I256Object = 71`).

i256.wast pins the first two: the six existing error assertions move to
`ErrObject`, and `i256::MIN rem_euclid -1` is added. The tag rules are only
reachable with `alwaysAllocate` set, which the .wast harness does not do;
they were checked by building with the cell forced to `true`, under which
u256.wast, double_u256.wast and i256.wast all fail before the change and pass
after.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants