Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 20 commits into from
Nov 28, 2024

Conversation

malik672
Copy link
Contributor

@malik672 malik672 commented Nov 27, 2024

Resolves #275

  • Add AddMod and MulMod to host functions
  • Implement Test for both

0x30bE4D758d86cfb1Ae74Ae698f2CF4BA7dC8d693

@malik672
Copy link
Contributor Author

@clearloop this should be done

@clearloop
Copy link
Member

clearloop commented Nov 27, 2024

@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

  • 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!

Copy link
Member

@clearloop clearloop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key point of this issue is implementing addmod & mumod for number types, you got a correct implementation for U256, congratulations!

However, you missed adding these functions to the U256 type, and other primitive number types, you are in the correct direction, just need common rust impls and tests in contracts then!

codegen/src/wasm/host.rs Outdated Show resolved Hide resolved
codegen/src/wasm/host.rs Outdated Show resolved Hide resolved
codegen/src/wasm/host.rs Outdated Show resolved Hide resolved
codegen/src/wasm/host.rs Outdated Show resolved Hide resolved
@malik672
Copy link
Contributor Author

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
Copy link
Member

clearloop commented Nov 27, 2024

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 malik672 requested a review from clearloop November 27, 2024 16:26
@malik672
Copy link
Contributor Author

@clearloop didn't really get the test tbh

Copy link
Member

@clearloop clearloop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

examples/addmod.rs Outdated Show resolved Hide resolved
zink/src/primitives/numeric.rs Outdated Show resolved Hide resolved
zink/src/primitives/u256.rs Outdated Show resolved Hide resolved
examples/addmod.rs Show resolved Hide resolved
@malik672
Copy link
Contributor Author

malik672 commented Nov 28, 2024

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

@malik672 malik672 requested a review from clearloop November 28, 2024 06:54
Copy link
Member

@clearloop clearloop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the test is still ignored, we need to pass the contract test to confirm that our implementation is correct

examples/addmod.rs Outdated Show resolved Hide resolved
examples/addmod.rs Outdated Show resolved Hide resolved
examples/addmod.rs Outdated Show resolved Hide resolved
zink/src/primitives/u256.rs Outdated Show resolved Hide resolved
zink/src/primitives/u256.rs Outdated Show resolved Hide resolved
examples/addmod.rs Outdated Show resolved Hide resolved
@malik672 malik672 requested a review from clearloop November 28, 2024 08:58
Copy link
Member

@clearloop clearloop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

Please fix the format check in CI btw, everything looks nice now! will transfer the budget once the CI pass!

examples/addmod.rs Outdated Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
examples/addmod.rs Show resolved Hide resolved
examples/addmod.rs Outdated Show resolved Hide resolved
@malik672 malik672 requested a review from clearloop November 28, 2024 09:49
Copy link
Member

@clearloop clearloop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clearloop clearloop merged commit 815c661 into zink-lang:main Nov 28, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce ADDMOD and MULMOD
2 participants