Skip to content

Standard library: division #244

@schoen

Description

@schoen

Project

library

Describe the feature

Describe the feature

(Migrated from Simplex repository.) The feature request is general integer division for all pairs of numeric data types (currently only some are handled by jets). Or, I suppose, at least for all pairs of types where the denominator isn't a larger type than the numerator.

Tommy Volk said that this would be useful for calculating pro-rated apportionment of assets (some party is entitled to receive a certain fraction of a total amount of an asset). I suggested that it may be possible to outsource the division to the wallet and have the Simplicity contract instead check the asserted division result from the witness by performing a multiplication on it (as multiplication can readily be used to verify claims about the result of division!). However, there may be use cases where people would like to perform arbitrarily-sized divisions inside of their contracts.

The jets that we have make it possible to build up division operations for larger data types than those supported directly by the jets, but this is kind of a lot of work for the contract developer to get the division algorithm right, and it would be nice to provide library functions to take care of it.

Alternatively, if it's really the best approach, I can document the "make the wallet do it, give the answer in the witness, have the contract check that the answer is right by multiplication" pattern. It might be counterintuitive, but there may be many things that can be confirmed on-chain that don't need to be computed on-chain. (In this case it might be better not to compute it on-chain merely because it will increase the size of the contract's code so much, which would greatly outweigh the increase in transaction size attributable to expanding the witness with an extra intermediate value.)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions