From 00bcc7c69074c137d389c6a8688f63a6b4dd6c8e Mon Sep 17 00:00:00 2001 From: Nathan James Date: Tue, 21 May 2024 16:27:26 +0100 Subject: [PATCH] sanity check for initialization values and sum overflows --- .gitignore | 1 + README.md | 22 +++++++++++++++++++++- build.sh | 6 ++++++ bun.lockb | Bin 0 -> 27843 bytes eosio.fees.cpp | 3 ++- eosio.fees.hpp | 4 ++-- eosio.fees.spec.ts | 7 +++++++ 7 files changed, 39 insertions(+), 4 deletions(-) create mode 100755 build.sh create mode 100755 bun.lockb diff --git a/.gitignore b/.gitignore index ac706ed..8c94170 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea +.vscode *.abi *.wasm !/external/**/*.abi diff --git a/README.md b/README.md index e27885b..0ed9712 100644 --- a/README.md +++ b/README.md @@ -41,4 +41,24 @@ $ npm test > test > bun test -``` \ No newline at end of file +``` + +#### Exported memory errors + +``` +TypeError: undefined is not an object (evaluating 'this.memory.buffer') +``` + +If you're using a version of CDT to build that doesn't support exported memory, you'll need to export it manually for VeRT tests to work. + +```bash +# Grab wabt +sudo apt-get install wabt + +# Create a temporary wat file and export the memory +wasm2wat eosio.fees.wasm | sed -e 's|(memory |(memory (export "memory") |' > eosio.fees.wat +wat2wasm -o eosio.fees.wasm eosio.fees.wat +rm eosio.fees.wat +``` + +You can also use the `./build.sh` script that will handle building and exporting memory for you. \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..5651f82 --- /dev/null +++ b/build.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +cdt-cpp eosio.fees.cpp -I ./include +wasm2wat eosio.fees.wasm | sed -e 's|(memory |(memory (export "memory") |' > eosio.fees.wat +wat2wasm -o eosio.fees.wasm eosio.fees.wat +rm eosio.fees.wat \ No newline at end of file diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000000000000000000000000000000000000..7b520e3a6d2f66e52e9df83b239362a353669c79 GIT binary patch literal 27843 zcmeHQ33OCNy6!*_$dd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`#R3(AM)giyVCgkzPvcqOEr}k3kv((pe z5erO_V@pVL`3RhOqy{hEkgHoEF?6VI$6b($jcp~T&Q(Bj%2Glq?0hVJ99i~aBjj>q z7Z@S9bT?`+8D&zf1@3^cxC$1Oi7C(HFA4aAL3^1IDk-lB`h9jTvLXj|n7Zk>-Cpgj zaeI9B>VQ$^Srn)VhLprXe;{O(+KWTjOO9cWdNqivXCZbzj68OiBkchkIkv0SS{!84 z@`I-70&rqYYmrlD!A4TtUW6CD3PmsY9Br<-KpCjNE+AWT&K zc=LOt=Kw{HqZ6GG%(Hv&_~Ht|<~>zLAjn@Hh#_^f5(uLi$YRdvKH%+`&nsh)MCyPe zatx)#znPeeVc^UoHq5;W+6y}qTwGP`_r_>Dygi@@`0ENv70O!iOAfw}-Kg?}ppO^? zeA-~&kpK)^k7MeMc-gMr4#dZnK^%rsph}fZ#ceC10o6fKhn-s^@hl7DMi53%Z3x7X zNjDs`EwLk|(wsPW*+BwU4xtN79!eQxuQgni_9|DkCy4pkU**BicLZwe3u=s-Sd((3 z4u~Vi$~xm+$I*5Gjb_jr{);`8>++h~5b-T(!`ul4)I5U3yx+xcRlCgrspZsot0`1H znW`IM42zCd0!=idtXs)|r_4~T+g=lhbzwy-fhC&3gDm$Z(UV%E*i-7oJnX}r9d~J8 ztO@<}%49u_0X^l+6I)N*(EyqW^vWwPcKz`FHxS_iTo2g%j)%c-qY!}vw?No2>xUm{ z(Nnt-z;Dcylp7_L;X}6(vX|BPO6)#Ym7%7RQX^!P#GH9K;e>0kGtnH{qqW5Dles?v zq%^Rs+A>gf+ zhh}?t0pZ3^5|uBm@?heym*G)4#;8Usp^az;Qu59c+wz)hmHjjy;TuT<3o%E!z~?Xa z8kr?E*bxbu87?4^3F4%IpR20QacajSV#u#oL(_zgz<`<)yOg?uvF 0, "epoch_time_interval must be greater than 0" ); settings_table _settings( get_self(), get_self().value ); auto settings = _settings.get_or_default(); @@ -55,7 +56,7 @@ void fees::distribute() update_next_epoch(); strategies_table _strategies( get_self(), get_self().value ); - const uint16_t total_weight = get_total_weight(); + const uint32_t total_weight = get_total_weight(); // distributing fees in EOS const asset balance = eosio::token::get_balance( "eosio.token"_n, get_self(), symbol_code("EOS") ); diff --git a/eosio.fees.hpp b/eosio.fees.hpp index 9d769a2..cdb69c9 100644 --- a/eosio.fees.hpp +++ b/eosio.fees.hpp @@ -116,9 +116,9 @@ namespace eosio { * @param contract - contract name * @return uint16_t - total weight */ - static uint16_t get_total_weight( const name contract = "eosio.fees"_n ) { + static uint32_t get_total_weight( const name contract = "eosio.fees"_n ) { strategies_table _strategies( contract, contract.value ); - uint16_t total_weight = 0; + uint32_t total_weight = 0; for (auto& row : _strategies) { total_weight += row.weight; } diff --git a/eosio.fees.spec.ts b/eosio.fees.spec.ts index 05d5a87..73a627c 100644 --- a/eosio.fees.spec.ts +++ b/eosio.fees.spec.ts @@ -91,6 +91,13 @@ describe(fees_contract, () => { ) }); + test("Cannot init with a 0 interval", async () => { + await expectToThrow( + contracts.fees.actions.init([0]).send(), + "eosio_assert: epoch_time_interval must be greater than 0" + ) + }); + test('eosio.fees::init', async () => { await contracts.fees.actions.init([TEN_MINUTES]).send()