Skip to content

256-bit host fn docs say errors returned when they trap #1629

@leighmcculloch

Description

@leighmcculloch

The 256-bit maths host fns say in their docs that an error is returned, but from the guest perspective no error is returned rather a trap occurs.

{
"export": "n",
"name": "u256_add",
"args": [
{
"name": "lhs",
"type": "U256Val"
},
{
"name": "rhs",
"type": "U256Val"
}
],
"return": "U256Val",
"docs": "Performs checked integer addition. Computes `lhs + rhs`, returning `ScError` if overflow occurred. "
},
{
"export": "o",
"name": "u256_sub",
"args": [
{
"name": "lhs",
"type": "U256Val"
},
{
"name": "rhs",
"type": "U256Val"
}
],
"return": "U256Val",
"docs": "Performs checked integer subtraction. Computes `lhs - rhs`, returning `ScError` if overflow occurred. "
},
{
"export": "p",
"name": "u256_mul",
"args": [
{
"name": "lhs",
"type": "U256Val"
},
{
"name": "rhs",
"type": "U256Val"
}
],
"return": "U256Val",
"docs": "Performs checked integer multiplication. Computes `lhs * rhs`, returning `ScError` if overflow occurred. "
},
{
"export": "q",
"name": "u256_div",
"args": [
{
"name": "lhs",
"type": "U256Val"
},
{
"name": "rhs",
"type": "U256Val"
}
],
"return": "U256Val",
"docs": "Performs checked integer division. Computes `lhs / rhs`, returning `ScError` if `rhs == 0` or overflow occurred. "
},
{
"export": "r",
"name": "u256_rem_euclid",
"args": [
{
"name": "lhs",
"type": "U256Val"
},
{
"name": "rhs",
"type": "U256Val"
}
],
"return": "U256Val",
"docs": "Performs checked Euclidean modulo. Computes `lhs % rhs`, returning `ScError` if `rhs == 0` or overflow occurred. "
},
{
"export": "s",
"name": "u256_pow",
"args": [
{
"name": "lhs",
"type": "U256Val"
},
{
"name": "rhs",
"type": "U32Val"
}
],
"return": "U256Val",
"docs": "Performs checked exponentiation. Computes `lhs.exp(rhs)`, returning `ScError` if overflow occurred. "
},
{
"export": "t",
"name": "u256_shl",
"args": [
{
"name": "lhs",
"type": "U256Val"
},
{
"name": "rhs",
"type": "U32Val"
}
],
"return": "U256Val",
"docs": "Performs checked shift left. Computes `lhs << rhs`, returning `ScError` if `rhs` is larger than or equal to the number of bits in `lhs`."
},
{
"export": "u",
"name": "u256_shr",
"args": [
{
"name": "lhs",
"type": "U256Val"
},
{
"name": "rhs",
"type": "U32Val"
}
],
"return": "U256Val",
"docs": "Performs checked shift right. Computes `lhs >> rhs`, returning `ScError` if `rhs` is larger than or equal to the number of bits in `lhs`."
},
{
"export": "v",
"name": "i256_add",
"args": [
{
"name": "lhs",
"type": "I256Val"
},
{
"name": "rhs",
"type": "I256Val"
}
],
"return": "I256Val",
"docs": "Performs checked integer addition. Computes `lhs + rhs`, returning `ScError` if overflow occurred. "
},
{
"export": "w",
"name": "i256_sub",
"args": [
{
"name": "lhs",
"type": "I256Val"
},
{
"name": "rhs",
"type": "I256Val"
}
],
"return": "I256Val",
"docs": "Performs checked integer subtraction. Computes `lhs - rhs`, returning `ScError` if overflow occurred. "
},
{
"export": "x",
"name": "i256_mul",
"args": [
{
"name": "lhs",
"type": "I256Val"
},
{
"name": "rhs",
"type": "I256Val"
}
],
"return": "I256Val",
"docs": "Performs checked integer multiplication. Computes `lhs * rhs`, returning `ScError` if overflow occurred. "
},
{
"export": "y",
"name": "i256_div",
"args": [
{
"name": "lhs",
"type": "I256Val"
},
{
"name": "rhs",
"type": "I256Val"
}
],
"return": "I256Val",
"docs": "Performs checked integer division. Computes `lhs / rhs`, returning `ScError` if `rhs == 0` or overflow occurred. "
},
{
"export": "z",
"name": "i256_rem_euclid",
"args": [
{
"name": "lhs",
"type": "I256Val"
},
{
"name": "rhs",
"type": "I256Val"
}
],
"return": "I256Val",
"docs": "Performs checked Euclidean modulo. Computes `lhs % rhs`, returning `ScError` if `rhs == 0` or overflow occurred. "
},
{
"export": "A",
"name": "i256_pow",
"args": [
{
"name": "lhs",
"type": "I256Val"
},
{
"name": "rhs",
"type": "U32Val"
}
],
"return": "I256Val",
"docs": "Performs checked exponentiation. Computes `lhs.exp(rhs)`, returning `ScError` if overflow occurred. "
},
{
"export": "B",
"name": "i256_shl",
"args": [
{
"name": "lhs",
"type": "I256Val"
},
{
"name": "rhs",
"type": "U32Val"
}
],
"return": "I256Val",
"docs": "Performs checked shift left. Computes `lhs << rhs`, returning `ScError` if `rhs` is larger than or equal to the number of bits in `lhs`."
},
{
"export": "C",
"name": "i256_shr",
"args": [
{
"name": "lhs",
"type": "I256Val"
},
{
"name": "rhs",
"type": "U32Val"
}
],
"return": "I256Val",
"docs": "Performs checked shift right. Computes `lhs >> rhs`, returning `ScError` if `rhs` is larger than or equal to the number of bits in `lhs`."

Typically the env.json docs are written from the perspective of the guest, and fns that trap typically say Traps if ....

"docs": "Get the value for a key from a map. Traps if key is not found."

We should update the docs to indicate the maths fns trap.

Originally posted by @leighmcculloch in #1659

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions