feat: add bigint constructor and fix BigInteger juice costs#575
feat: add bigint constructor and fix BigInteger juice costs#575aglichandrap wants to merge 2 commits into
Conversation
- Add BIGINT symbol to Symbols.java - Add bigint constructor function (code 259) to Core.java - Add bigint? predicate (code 260) to Core.java - Fix TODO: use Juice.costNumeric() for BigInteger construction costs - Add CVMBigInteger import to Core.java Fixes Convex-Dev/bounties#4
Implements Convex-Dev/bounties#10: - Deposit accounts to recycling market - Buy accounts with bonding curve pricing - Sell accounts back at market spread - Account clearing (undef, set-controller) - Security checks (controller verification) - Tests included Contract: convex/lab/account-recycler/actor.cvx Tests: convex/test/account-recycler.cvx
|
(Claude Comment) Thanks @aglichandrap. Two things after review: Branch mix-up: this branch currently contains the same changeset as #576 (account-recycler files included) — the intended bigint work appears to have been overwritten. If you pursue this further, please re-push a clean branch. On the substance — What would be genuinely valuable: the juice half of your PR intent. Closing the redundant constructor idea; happy to review a re-scoped juice PR. |
|
Thank you for this work across bounties #4 ( On For completeness, the change also couldn't have merged as written: it registers the new core functions with genesis codes (which would alter the immutable genesis hash), and code 259 is already On the account recycler (bounty #10) — that's independent work and this closure is not a judgement on it. It's currently bundled with the Thanks again for engaging with the bounties. — Claude (AI assistant helping maintain the Convex repository, on behalf of the maintainers) |
Changes
This PR adds a native
bigintconstructor function and fixes BigInteger juice costs for the CVM, addressing Convex-Dev/bounties#4.1.
bigintconstructor function (Core.java)BIGINTcore function (code 259) that converts any numeric value to anAInteger(BigInteger or Long as appropriate)Juice.costNumeric()2.
bigint?predicate (Core.java)BIGINT_Qpredicate (code 260) that returns true forCVMBigIntegerinstanceslong?,double?,int?3. BigInteger juice cost fix (Core.java)
TODO: bigint construction cost?in theintconstructorJuice.costNumeric(result)which charges proportional to byte length for BigInteger values (minJuice.MIN_NUMERIC_COST)4. Symbols
BIGINTandBIGINT_Qsymbols toSymbols.javaTechnical Details
Juice cost model for BigInteger:
Juice.costNumeric()returnsMath.max(MIN_NUMERIC_COST, byteLength)for CVMBigIntegerArithmetic operations already work:
The existing
+,-,*,/,mod,quot,abs,signumoperations already handle BigInteger through theAIntegerclass hierarchy. Long overflow automatically promotes to BigInteger (e.g.,(+ Long/MAX_VALUE 1)produces a BigInteger).What this PR adds:
bigintconstructor for CVM codebigint?type predicateTesting
EncodingTest.testEmbeddedBigInteger()covers BigInteger encodingArithmeticTestcover Long→BigInteger promotion(bigint 123456789012345678901234567890)should produce a BigInteger value