zink-lang / zink

Rustic programming language that targets the Ethereum Virtual Machine
https://zink-lang.org
GNU General Public License v3.0
139 stars 13 forks source link

feat(wasm(host)): Add AddMod and MulMod to host functions #283

Closed malik672 closed 3 days ago

malik672 commented 4 days ago

Resolves #275

0x30bE4D758d86cfb1Ae74Ae698f2CF4BA7dC8d693

malik672 commented 4 days ago

@clearloop this should be done

clearloop commented 4 days ago

@clearloop this should be done

nice! you already got how it works! btw could you please check my template implementation in issue-275-template, especially the commit 339daeb

feel free to copy my previous code to your PR!

malik672 commented 4 days ago

nice! you already got how it works! btw could you please check my template implementation in issue-275-template, especially the commit 339daeb

  • we need to complete this interface for the rust primitive numbers, e.g i8, u8...i64, u64
  • introduce a test in zink/examples/addmod.rs

feel free to copy my previous code to your PR!

a macro would be good for this tbh

clearloop commented 4 days ago

a macro would be good for this tbh

yes! feel free! you may interest with my template implementation for #252 as well e0e0f4b, there is a impl_byte macro just like what we need here ^ ^

malik672 commented 4 days ago

@clearloop didn't really get the test tbh

malik672 commented 4 days ago

Almost there! when you run the tests, you can do

RUST_LOG=trace cargo nextest run --example addmod --nocapture

so you will see error failed to load contract addmod_i32

  1. You should load addmod which is the name of the example, we're compiling each example as a contract, and with the logging you actually can debug what happened in the compiler
  2. add addmod & mulmod branches to HostFunc::TryFrom then we can emit ADDMOD & MULMOD instead of NOOP, feel free to optimize the TryFrom since our functions are increasing!

see also my workaround based on your commits: c6a1e38

yeah just looked at it, that would be messy a bit