From ace7d84377d358ac8982a1963fd91596a802e67f Mon Sep 17 00:00:00 2001 From: malik Date: Wed, 27 Nov 2024 09:16:03 +0100 Subject: [PATCH 01/20] addmod --- codegen/src/wasm/host.rs | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/codegen/src/wasm/host.rs b/codegen/src/wasm/host.rs index 2fce8a2d4..e45f6ad94 100644 --- a/codegen/src/wasm/host.rs +++ b/codegen/src/wasm/host.rs @@ -72,6 +72,8 @@ impl TryFrom<(&str, &str)> for HostFunc { ("zinkc", "u256_sub") => Ok(Self::Evm(OpCode::SUB)), ("zinkc", "u256_lt") => Ok(Self::Evm(OpCode::LT)), ("zinkc", "u256_max") => Ok(Self::U256MAX), + ("zinkc", "u256_addmod") => Ok(Self::Evm(OpCode::ADDMOD)), + ("zinkc", "u256_mulmod") => Ok(Self::Evm(OpCode::MULMOD)), ("zinkc", "label_reserve_mem_32") => Ok(Self::Label(CompilerLabel::ReserveMemory32)), ("zinkc", "label_reserve_mem_64") => Ok(Self::Label(CompilerLabel::ReserveMemory64)), _ => { @@ -88,3 +90,74 @@ pub enum CompilerLabel { ReserveMemory32, ReserveMemory64, } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_addmod_mulmod_host_functions() { + // Test ADDMOD host function conversion + let addmod_func = HostFunc::try_from(("zinkc", "u256_addmod")); + assert!(addmod_func.is_ok()); + let addmod_host_func = addmod_func.unwrap(); + + // Verify it maps to the correct EVM opcode + match addmod_host_func { + HostFunc::Evm(OpCode::ADDMOD) => {}, + _ => panic!("Expected ADDMOD opcode"), + } + + // Verify stack input/output for ADDMOD + assert_eq!(addmod_host_func.stack_in(), 3); + assert_eq!(addmod_host_func.stack_out(), 1); + + // Test MULMOD host function conversion + let mulmod_func = HostFunc::try_from(("zinkc", "u256_mulmod")); + assert!(mulmod_func.is_ok()); + let mulmod_host_func = mulmod_func.unwrap(); + + // Verify it maps to the correct EVM opcode + match mulmod_host_func { + HostFunc::Evm(OpCode::MULMOD) => {}, + _ => panic!("Expected MULMOD opcode"), + } + + // Verify stack input/output for MULMOD + assert_eq!(mulmod_host_func.stack_in(), 3); + assert_eq!(mulmod_host_func.stack_out(), 1); + } + + #[test] + fn test_addmod_mulmod_example_scenarios() { + fn modular_add(a: u64, b: u64, n: u64) -> u64 { + ((a % n) + (b % n)) % n + } + + let test_cases = [ + (10u64, 20, 7, 2, 4), + (100, 200, 3, 0, 2), + (5, 6, 7, 4, 2), + (10, 11, 12, 9, 2) + ]; + + for (a, b, n, expected_add, expected_mul) in test_cases.iter() { + let actual_add = modular_add(*a, *b, *n); + let actual_mul = (*a * *b) % *n; + + println!( + "Debug: a={}, b={}, N={}, actual_add={}, expected_add={}", + a, b, n, actual_add, expected_add + ); + + assert_eq!(actual_add, *expected_add, + "ADDMOD failed for inputs {}, {}, {} (got {}, expected {})", + a, b, n, actual_add, expected_add); + + assert_eq!(actual_mul, *expected_mul, + "MULMOD failed for inputs {}, {}, {} (got {}, expected {})", + a, b, n, actual_mul, expected_mul); + } + } + +} \ No newline at end of file From 8b0c4ca6c2af653c0803dc63f6f0247f41c2c602 Mon Sep 17 00:00:00 2001 From: malik Date: Wed, 27 Nov 2024 15:28:13 +0100 Subject: [PATCH 02/20] changes --- codegen/src/wasm/host.rs | 51 +++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/codegen/src/wasm/host.rs b/codegen/src/wasm/host.rs index e45f6ad94..a6d58bd4c 100644 --- a/codegen/src/wasm/host.rs +++ b/codegen/src/wasm/host.rs @@ -101,63 +101,66 @@ mod tests { let addmod_func = HostFunc::try_from(("zinkc", "u256_addmod")); assert!(addmod_func.is_ok()); let addmod_host_func = addmod_func.unwrap(); - + // Verify it maps to the correct EVM opcode match addmod_host_func { - HostFunc::Evm(OpCode::ADDMOD) => {}, + HostFunc::Evm(OpCode::ADDMOD) => {} _ => panic!("Expected ADDMOD opcode"), } // Verify stack input/output for ADDMOD - assert_eq!(addmod_host_func.stack_in(), 3); - assert_eq!(addmod_host_func.stack_out(), 1); + assert_eq!(addmod_host_func.stack_in(), 3); + assert_eq!(addmod_host_func.stack_out(), 1); // Test MULMOD host function conversion let mulmod_func = HostFunc::try_from(("zinkc", "u256_mulmod")); assert!(mulmod_func.is_ok()); let mulmod_host_func = mulmod_func.unwrap(); - + // Verify it maps to the correct EVM opcode match mulmod_host_func { - HostFunc::Evm(OpCode::MULMOD) => {}, + HostFunc::Evm(OpCode::MULMOD) => {} _ => panic!("Expected MULMOD opcode"), } // Verify stack input/output for MULMOD - assert_eq!(mulmod_host_func.stack_in(), 3); - assert_eq!(mulmod_host_func.stack_out(), 1); + assert_eq!(mulmod_host_func.stack_in(), 3); + assert_eq!(mulmod_host_func.stack_out(), 1); } - + #[test] fn test_addmod_mulmod_example_scenarios() { fn modular_add(a: u64, b: u64, n: u64) -> u64 { ((a % n) + (b % n)) % n } - + let test_cases = [ - (10u64, 20, 7, 2, 4), - (100, 200, 3, 0, 2), - (5, 6, 7, 4, 2), - (10, 11, 12, 9, 2) + (10u64, 20, 7, 2, 4), + (100, 200, 3, 0, 2), + (5, 6, 7, 4, 2), + (10, 11, 12, 9, 2), ]; - + for (a, b, n, expected_add, expected_mul) in test_cases.iter() { let actual_add = modular_add(*a, *b, *n); let actual_mul = (*a * *b) % *n; - + println!( "Debug: a={}, b={}, N={}, actual_add={}, expected_add={}", a, b, n, actual_add, expected_add ); - - assert_eq!(actual_add, *expected_add, + + assert_eq!( + actual_add, *expected_add, "ADDMOD failed for inputs {}, {}, {} (got {}, expected {})", - a, b, n, actual_add, expected_add); - - assert_eq!(actual_mul, *expected_mul, + a, b, n, actual_add, expected_add + ); + + assert_eq!( + actual_mul, *expected_mul, "MULMOD failed for inputs {}, {}, {} (got {}, expected {})", - a, b, n, actual_mul, expected_mul); + a, b, n, actual_mul, expected_mul + ); } } - -} \ No newline at end of file +} From 4b1e4f673a6ad5b64350799f13558090d5bad6ac Mon Sep 17 00:00:00 2001 From: malik Date: Wed, 27 Nov 2024 17:19:54 +0100 Subject: [PATCH 03/20] changes --- codegen/src/wasm/host.rs | 71 ++++-------------------------- examples/addmod.rs | 79 ++++++++++++++++++++++++++++++++++ zink/src/ffi/asm.rs | 40 +++++++++++++++++ zink/src/ffi/mod.rs | 6 +++ zink/src/primitives/mod.rs | 1 + zink/src/primitives/numeric.rs | 36 ++++++++++++++++ zink/src/primitives/u256.rs | 12 ++++++ 7 files changed, 183 insertions(+), 62 deletions(-) create mode 100644 examples/addmod.rs create mode 100644 zink/src/primitives/numeric.rs diff --git a/codegen/src/wasm/host.rs b/codegen/src/wasm/host.rs index a6d58bd4c..cea5ec43b 100644 --- a/codegen/src/wasm/host.rs +++ b/codegen/src/wasm/host.rs @@ -93,74 +93,21 @@ pub enum CompilerLabel { #[cfg(test)] mod tests { + use anyhow::Ok; + use super::*; #[test] - fn test_addmod_mulmod_host_functions() { - // Test ADDMOD host function conversion - let addmod_func = HostFunc::try_from(("zinkc", "u256_addmod")); - assert!(addmod_func.is_ok()); - let addmod_host_func = addmod_func.unwrap(); - - // Verify it maps to the correct EVM opcode - match addmod_host_func { - HostFunc::Evm(OpCode::ADDMOD) => {} - _ => panic!("Expected ADDMOD opcode"), - } + fn test_addmod_mulmod_host_functions() -> anyhow::Result<()> { + - // Verify stack input/output for ADDMOD - assert_eq!(addmod_host_func.stack_in(), 3); - assert_eq!(addmod_host_func.stack_out(), 1); + let addmod_func = HostFunc::try_from(("zinkc", "u256_addmod"))?; + + assert_eq!(addmod_func, HostFunc::Evm(OpCode::ADDMOD)); // Test MULMOD host function conversion let mulmod_func = HostFunc::try_from(("zinkc", "u256_mulmod")); assert!(mulmod_func.is_ok()); - let mulmod_host_func = mulmod_func.unwrap(); - - // Verify it maps to the correct EVM opcode - match mulmod_host_func { - HostFunc::Evm(OpCode::MULMOD) => {} - _ => panic!("Expected MULMOD opcode"), - } - - // Verify stack input/output for MULMOD - assert_eq!(mulmod_host_func.stack_in(), 3); - assert_eq!(mulmod_host_func.stack_out(), 1); + Ok(()) } - - #[test] - fn test_addmod_mulmod_example_scenarios() { - fn modular_add(a: u64, b: u64, n: u64) -> u64 { - ((a % n) + (b % n)) % n - } - - let test_cases = [ - (10u64, 20, 7, 2, 4), - (100, 200, 3, 0, 2), - (5, 6, 7, 4, 2), - (10, 11, 12, 9, 2), - ]; - - for (a, b, n, expected_add, expected_mul) in test_cases.iter() { - let actual_add = modular_add(*a, *b, *n); - let actual_mul = (*a * *b) % *n; - - println!( - "Debug: a={}, b={}, N={}, actual_add={}, expected_add={}", - a, b, n, actual_add, expected_add - ); - - assert_eq!( - actual_add, *expected_add, - "ADDMOD failed for inputs {}, {}, {} (got {}, expected {})", - a, b, n, actual_add, expected_add - ); - - assert_eq!( - actual_mul, *expected_mul, - "MULMOD failed for inputs {}, {}, {} (got {}, expected {})", - a, b, n, actual_mul, expected_mul - ); - } - } -} +} \ No newline at end of file diff --git a/examples/addmod.rs b/examples/addmod.rs new file mode 100644 index 000000000..641b33b78 --- /dev/null +++ b/examples/addmod.rs @@ -0,0 +1,79 @@ +//! Addmod example for i64, i32, u64, u32. +#![cfg_attr(target_arch = "wasm32", no_std)] +#![cfg_attr(target_arch = "wasm32", no_main)] + +extern crate zink; +use zink::primitives::numeric::Numeric; +use zint::{Bytes32 as _, Contract}; + +#[zink::external] +pub fn addmod_i32(a: i32, b: i32, n: i32) -> i32 { + a.addmod(b, n) +} + +#[zink::external] +pub fn addmod_i64(a: i64, b: i64, n: i64) -> i64 { + a.addmod(b, n) +} + +#[zink::external] +pub fn addmod_u32(a: u32, b: u32, n: u32) -> u32 { + a.addmod(b, n) +} + +#[zink::external] +pub fn addmod_u64(a: u64, b: u64, n: u64) -> u64 { + a.addmod(b, n) +} + +#[cfg(not(target_arch = "wasm32"))] +fn main() {} + +// FIXME: this test should pass, fix it to learn how to +// add opcodes to the compiler +#[ignore] +#[test] +fn test() -> anyhow::Result<()> { + + // Test for i32 + let mut contract_i32 = Contract::search("addmod_i32")?.compile()?; + let info_i32 = contract_i32.execute([ + "addmod_i32(uint32,uint32,uint32)".as_bytes(), + &3i32.to_bytes32(), + &5i32.to_bytes32(), + &7i32.to_bytes32(), + ])?; + assert_eq!(info_i32.ret, 1i32.to_bytes32()); + + // Test for i64 + let mut contract_i64 = Contract::search("addmod_i64")?.compile()?; + let info_i64 = contract_i64.execute([ + "addmod_i64(int64,int64,int64)".as_bytes(), + &3i64.to_bytes32(), + &5i64.to_bytes32(), + &7i64.to_bytes32(), + ])?; + assert_eq!(info_i64.ret, 1i64.to_bytes32()); + + // Test for u32 + let mut contract_u32 = Contract::search("addmod_u32")?.compile()?; + let info_u32 = contract_u32.execute([ + "addmod_u32(uint32,uint32,uint32)".as_bytes(), + &3u32.to_bytes32(), + &5u32.to_bytes32(), + &7u32.to_bytes32(), + ])?; + assert_eq!(info_u32.ret, 1u32.to_bytes32()); + + // Test for u64 + let mut contract_u64 = Contract::search("addmod_u64")?.compile()?; + let info_u64 = contract_u64.execute([ + "addmod_u64(uint64,uint64,uint64)".as_bytes(), + &3u64.to_bytes32(), + &5u64.to_bytes32(), + &7u64.to_bytes32(), + ])?; + assert_eq!(info_u64.ret, 1u64.to_bytes32()); + + Ok(()) +} diff --git a/zink/src/ffi/asm.rs b/zink/src/ffi/asm.rs index b308531a0..cf1062888 100644 --- a/zink/src/ffi/asm.rs +++ b/zink/src/ffi/asm.rs @@ -35,6 +35,46 @@ extern "C" { /// Push u256 to stack pub fn push_u256(u256: U256); + /// Emit opcode ADDMOD + pub fn addmod_i8(a: i8, b: i8, n: i8) -> i8; + /// Emit opcode ADDMOD + pub fn mulmod_i8(a: i8, b: i8, n: i8) -> i8; + + /// Emit opcode ADDMOD + pub fn addmod_i16(a: i16, b: i16, n: i16) -> i16; + /// Emit opcode ADDMOD + pub fn mulmod_i16(a: i16, b: i16, n: i16) -> i16; + + /// Emit opcode ADDMOD + pub fn addmod_i32(a: i32, b: i32, n: i32) -> i32; + /// Emit opcode ADDMOD + pub fn mulmod_i32(a: i32, b: i32, n: i32) -> i32; + + /// Emit opcode ADDMOD + pub fn addmod_i64(a: i64, b: i64, n: i64) -> i64; + /// Emit opcode ADDMOD + pub fn mulmod_i64(a: i64, b: i64, n: i64) -> i64; + + /// Emit opcode ADDMOD + pub fn addmod_u8(a: u8, b: u8, n: u8) -> u8; + /// Emit opcode ADDMOD + pub fn mulmod_u8(a: u8, b: u8, n: u8) -> u8; + + /// Emit opcode ADDMOD + pub fn addmod_u16(a: u16, b: u16, n: u16) -> u16; + /// Emit opcode ADDMOD + pub fn mulmod_u16(a: u16, b: u16, n: u16) -> u16; + + /// Emit opcode ADDMOD + pub fn addmod_u32(a: u32, b: u32, n: u32) -> u32; + /// Emit opcode ADDMOD + pub fn mulmod_u32(a: u32, b: u32, n: u32) -> u32; + + /// Emit opcode ADDMOD + pub fn addmod_u64(a: u64, b: u64, n: u64) -> u64; + /// Emit opcode ADDMOD + pub fn mulmod_u64(a: u64, b: u64, n: u64) -> u64; + /// Revert with message in 32 bytes pub fn revert1(message: &'static str); diff --git a/zink/src/ffi/mod.rs b/zink/src/ffi/mod.rs index 410fcbce4..7b41ad736 100644 --- a/zink/src/ffi/mod.rs +++ b/zink/src/ffi/mod.rs @@ -26,6 +26,12 @@ extern "C" { /// Equal operation for addresses pub fn u256_max() -> U256; + /// Addmod operation for addresses + pub fn u256_addmod(this: U256, other: U256, modulus: U256) -> U256; + + /// Equal operation for addresses + pub fn u256_mulmod(this: U256, other: U256, modulus: U256) -> U256; + /// Set up a label for reserving 32 bytes in memory pub fn label_reserve_mem_32(); diff --git a/zink/src/primitives/mod.rs b/zink/src/primitives/mod.rs index 67b4af318..d2f3fe56c 100644 --- a/zink/src/primitives/mod.rs +++ b/zink/src/primitives/mod.rs @@ -2,6 +2,7 @@ mod address; mod u256; +pub mod numeric; pub use address::Address; pub use u256::U256; diff --git a/zink/src/primitives/numeric.rs b/zink/src/primitives/numeric.rs new file mode 100644 index 000000000..fee55f67d --- /dev/null +++ b/zink/src/primitives/numeric.rs @@ -0,0 +1,36 @@ +use crate::ffi; + +/// A trait for modular arithmetic operations on numeric types. +pub trait Numeric: Copy { + fn addmod(self, other: Self, n: Self) -> Self; + fn mulmod(self, other: Self, n: Self) -> Self; +} + +macro_rules! impl_numeric { + ($($t:ty, $addmod_fn:ident, $mulmod_fn:ident);* $(;)?) => { + $( + impl Numeric for $t { + #[inline(always)] + fn addmod(self, other: Self, n: Self) -> Self { + unsafe { ffi::asm::$addmod_fn(self, other, n) } + } + #[inline(always)] + fn mulmod(self, other: Self, n: Self) -> Self { + unsafe { ffi::asm::$mulmod_fn(self, other, n) } + } + } + )* + }; +} + + +impl_numeric! { + i8, addmod_i8, mulmod_i8; + u8, addmod_u8, mulmod_u8; + i16, addmod_i16, mulmod_i16; + u16, addmod_u16, mulmod_u16; + i32, addmod_i32, mulmod_i32; + u32, addmod_u32, mulmod_u32; + i64, addmod_i64, mulmod_i64; + u64, addmod_u64, mulmod_u64; +} diff --git a/zink/src/primitives/u256.rs b/zink/src/primitives/u256.rs index f6fed0283..b02449704 100644 --- a/zink/src/primitives/u256.rs +++ b/zink/src/primitives/u256.rs @@ -39,6 +39,18 @@ impl U256 { pub fn max() -> Self { unsafe { ffi::u256_max() } } + + /// Addmod for U256 + #[inline(always)] + pub fn addmod(self, other: Self, modulus: Self) -> Self { + unsafe { ffi::u256_addmod(self, other, modulus) } + } + + /// Mulmod for U256 + #[inline(always)] + pub fn mulmod(self, other: Self, modulus: Self) -> Self { + unsafe { ffi::u256_mulmod(self, other, modulus) } + } } impl Asm for U256 { From b3e6c786546a8eb49c2d10d28d839fa847042339 Mon Sep 17 00:00:00 2001 From: malik Date: Wed, 27 Nov 2024 17:23:56 +0100 Subject: [PATCH 04/20] Event --- codegen/src/wasm/host.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/codegen/src/wasm/host.rs b/codegen/src/wasm/host.rs index cea5ec43b..ae745301f 100644 --- a/codegen/src/wasm/host.rs +++ b/codegen/src/wasm/host.rs @@ -98,11 +98,9 @@ mod tests { use super::*; #[test] - fn test_addmod_mulmod_host_functions() -> anyhow::Result<()> { - - + fn test_addmod_mulmod_host_functions() -> anyhow::Result<()> { let addmod_func = HostFunc::try_from(("zinkc", "u256_addmod"))?; - + assert_eq!(addmod_func, HostFunc::Evm(OpCode::ADDMOD)); // Test MULMOD host function conversion @@ -110,4 +108,4 @@ mod tests { assert!(mulmod_func.is_ok()); Ok(()) } -} \ No newline at end of file +} From 9bc6e2180e2d85079c5a85c06bbe1f13cd22e245 Mon Sep 17 00:00:00 2001 From: malik Date: Wed, 27 Nov 2024 17:25:33 +0100 Subject: [PATCH 05/20] linter --- examples/addmod.rs | 1 - zink/src/primitives/mod.rs | 2 +- zink/src/primitives/numeric.rs | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/addmod.rs b/examples/addmod.rs index 641b33b78..24b510bb2 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -34,7 +34,6 @@ fn main() {} #[ignore] #[test] fn test() -> anyhow::Result<()> { - // Test for i32 let mut contract_i32 = Contract::search("addmod_i32")?.compile()?; let info_i32 = contract_i32.execute([ diff --git a/zink/src/primitives/mod.rs b/zink/src/primitives/mod.rs index d2f3fe56c..8bc47dcc7 100644 --- a/zink/src/primitives/mod.rs +++ b/zink/src/primitives/mod.rs @@ -1,8 +1,8 @@ //! Zink primitive types mod address; -mod u256; pub mod numeric; +mod u256; pub use address::Address; pub use u256::U256; diff --git a/zink/src/primitives/numeric.rs b/zink/src/primitives/numeric.rs index fee55f67d..b6ce4e4e2 100644 --- a/zink/src/primitives/numeric.rs +++ b/zink/src/primitives/numeric.rs @@ -23,7 +23,6 @@ macro_rules! impl_numeric { }; } - impl_numeric! { i8, addmod_i8, mulmod_i8; u8, addmod_u8, mulmod_u8; From b62603d58022e424d18593f4c27090803ed39d1c Mon Sep 17 00:00:00 2001 From: malik Date: Wed, 27 Nov 2024 17:51:48 +0100 Subject: [PATCH 06/20] refactor --- examples/addmod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/addmod.rs b/examples/addmod.rs index 24b510bb2..ef9f90781 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -4,7 +4,6 @@ extern crate zink; use zink::primitives::numeric::Numeric; -use zint::{Bytes32 as _, Contract}; #[zink::external] pub fn addmod_i32(a: i32, b: i32, n: i32) -> i32 { @@ -34,6 +33,9 @@ fn main() {} #[ignore] #[test] fn test() -> anyhow::Result<()> { + + use zint::{Bytes32 as _, Contract}; + // Test for i32 let mut contract_i32 = Contract::search("addmod_i32")?.compile()?; let info_i32 = contract_i32.execute([ From 377e7f7abdfef08044a6363d669423b362a8ea2e Mon Sep 17 00:00:00 2001 From: malik Date: Wed, 27 Nov 2024 17:53:15 +0100 Subject: [PATCH 07/20] refactor --- examples/addmod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/addmod.rs b/examples/addmod.rs index ef9f90781..f65834192 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -33,7 +33,6 @@ fn main() {} #[ignore] #[test] fn test() -> anyhow::Result<()> { - use zint::{Bytes32 as _, Contract}; // Test for i32 From af528e5b515e52a30dda213838defc6a093aeade Mon Sep 17 00:00:00 2001 From: malik Date: Thu, 28 Nov 2024 06:34:40 +0100 Subject: [PATCH 08/20] refactor --- examples/addmod.rs | 17 ++++++++++++++++- zink/src/primitives/numeric.rs | 4 ++-- zink/src/primitives/u256.rs | 4 ++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/examples/addmod.rs b/examples/addmod.rs index f65834192..f76dd0f8b 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -3,7 +3,7 @@ #![cfg_attr(target_arch = "wasm32", no_main)] extern crate zink; -use zink::primitives::numeric::Numeric; +use zink::primitives::{numeric::Numeric, U256}; #[zink::external] pub fn addmod_i32(a: i32, b: i32, n: i32) -> i32 { @@ -25,6 +25,11 @@ pub fn addmod_u64(a: u64, b: u64, n: u64) -> u64 { a.addmod(b, n) } +#[zink::external] +pub fn addmod_U256(a: U256, b: U256, n: U256) -> U256 { + a.addmod(b, n) +} + #[cfg(not(target_arch = "wasm32"))] fn main() {} @@ -75,5 +80,15 @@ fn test() -> anyhow::Result<()> { ])?; assert_eq!(info_u64.ret, 1u64.to_bytes32()); + // Test for U256 + let mut contract_u256 = Contract::search("addmod_U256")?.compile()?; + let info_u256 = contract_u256.execute([ + "addmod_U256(uint256,uint256,uint256)".as_bytes(), + &U256::from(3).to_bytes32(), + &U256::from(5).to_bytes32(), + &U256::from(7).to_bytes32(), + ])?; + assert_eq!(info_u256.ret, U256::from(1).to_bytes32()); + Ok(()) } diff --git a/zink/src/primitives/numeric.rs b/zink/src/primitives/numeric.rs index b6ce4e4e2..b819c6200 100644 --- a/zink/src/primitives/numeric.rs +++ b/zink/src/primitives/numeric.rs @@ -12,11 +12,11 @@ macro_rules! impl_numeric { impl Numeric for $t { #[inline(always)] fn addmod(self, other: Self, n: Self) -> Self { - unsafe { ffi::asm::$addmod_fn(self, other, n) } + unsafe { ffi::asm::$addmod_fn(n, other, self) } } #[inline(always)] fn mulmod(self, other: Self, n: Self) -> Self { - unsafe { ffi::asm::$mulmod_fn(self, other, n) } + unsafe { ffi::asm::$mulmod_fn(n, other, self) } } } )* diff --git a/zink/src/primitives/u256.rs b/zink/src/primitives/u256.rs index b02449704..becee567d 100644 --- a/zink/src/primitives/u256.rs +++ b/zink/src/primitives/u256.rs @@ -43,13 +43,13 @@ impl U256 { /// Addmod for U256 #[inline(always)] pub fn addmod(self, other: Self, modulus: Self) -> Self { - unsafe { ffi::u256_addmod(self, other, modulus) } + unsafe { ffi::u256_addmod(modulus,self, other) } } /// Mulmod for U256 #[inline(always)] pub fn mulmod(self, other: Self, modulus: Self) -> Self { - unsafe { ffi::u256_mulmod(self, other, modulus) } + unsafe { ffi::u256_mulmod(modulus, self, other) } } } From c6ed80c81bd84fb2be94d112865e61fd0bd7a57e Mon Sep 17 00:00:00 2001 From: malik Date: Thu, 28 Nov 2024 07:53:27 +0100 Subject: [PATCH 09/20] refactor --- codegen/src/wasm/host.rs | 4 ++++ examples/addmod.rs | 28 +++++++++++++--------------- zink/src/primitives/u256.rs | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/codegen/src/wasm/host.rs b/codegen/src/wasm/host.rs index ae745301f..488f92ff5 100644 --- a/codegen/src/wasm/host.rs +++ b/codegen/src/wasm/host.rs @@ -58,6 +58,10 @@ impl TryFrom<(&str, &str)> for HostFunc { // TODO: use anyhow instead of Error Ok(Self::Revert(count.parse().map_err(|e| anyhow!("{e}"))?)) + } else if name.starts_with("mulmod") { + Ok(Self::Evm(OpCode::MULMOD)) + } else if name.starts_with("addmod") { + Ok(Self::Evm(OpCode::ADDMOD)) } else { Ok(Self::NoOp) } diff --git a/examples/addmod.rs b/examples/addmod.rs index f76dd0f8b..e11135d0f 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -39,11 +39,10 @@ fn main() {} #[test] fn test() -> anyhow::Result<()> { use zint::{Bytes32 as _, Contract}; - // Test for i32 - let mut contract_i32 = Contract::search("addmod_i32")?.compile()?; - let info_i32 = contract_i32.execute([ - "addmod_i32(uint32,uint32,uint32)".as_bytes(), + let mut contract = Contract::search("addmod")?.compile()?; + let info_i32 = contract.execute([ + "addmod_i32(int32,int32,int32)".as_bytes(), &3i32.to_bytes32(), &5i32.to_bytes32(), &7i32.to_bytes32(), @@ -51,8 +50,7 @@ fn test() -> anyhow::Result<()> { assert_eq!(info_i32.ret, 1i32.to_bytes32()); // Test for i64 - let mut contract_i64 = Contract::search("addmod_i64")?.compile()?; - let info_i64 = contract_i64.execute([ + let info_i64 = contract.execute([ "addmod_i64(int64,int64,int64)".as_bytes(), &3i64.to_bytes32(), &5i64.to_bytes32(), @@ -80,15 +78,15 @@ fn test() -> anyhow::Result<()> { ])?; assert_eq!(info_u64.ret, 1u64.to_bytes32()); - // Test for U256 - let mut contract_u256 = Contract::search("addmod_U256")?.compile()?; - let info_u256 = contract_u256.execute([ - "addmod_U256(uint256,uint256,uint256)".as_bytes(), - &U256::from(3).to_bytes32(), - &U256::from(5).to_bytes32(), - &U256::from(7).to_bytes32(), - ])?; - assert_eq!(info_u256.ret, U256::from(1).to_bytes32()); + // // Test for U256 + // let mut contract_u256 = Contract::search("addmod_U256")?.compile()?; + // let info_u256 = contract_u256.execute([ + // "addmod_U256(uint256,uint256,uint256)".as_bytes(), + // &U256::from(3.into()).bytes32(), + // &U256::from(5.into()).bytes32(), + // &U256::from(7.into()).bytes32(), + // ])?; + // assert_eq!(info_u256.ret, U256::from(1.into()).bytes32()); Ok(()) } diff --git a/zink/src/primitives/u256.rs b/zink/src/primitives/u256.rs index becee567d..d544325a3 100644 --- a/zink/src/primitives/u256.rs +++ b/zink/src/primitives/u256.rs @@ -43,7 +43,7 @@ impl U256 { /// Addmod for U256 #[inline(always)] pub fn addmod(self, other: Self, modulus: Self) -> Self { - unsafe { ffi::u256_addmod(modulus,self, other) } + unsafe { ffi::u256_addmod(modulus, self, other) } } /// Mulmod for U256 From 08bb864eec6c0100eae8af8d79ae39fa59b7cf0d Mon Sep 17 00:00:00 2001 From: malik Date: Thu, 28 Nov 2024 09:57:10 +0100 Subject: [PATCH 10/20] fix --- examples/addmod.rs | 67 ++++++++++++++++++------------------- zink/src/primitives/u256.rs | 4 +-- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/examples/addmod.rs b/examples/addmod.rs index e11135d0f..5f4648475 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -35,48 +35,47 @@ fn main() {} // FIXME: this test should pass, fix it to learn how to // add opcodes to the compiler -#[ignore] + #[test] fn test() -> anyhow::Result<()> { use zint::{Bytes32 as _, Contract}; // Test for i32 let mut contract = Contract::search("addmod")?.compile()?; - let info_i32 = contract.execute([ - "addmod_i32(int32,int32,int32)".as_bytes(), - &3i32.to_bytes32(), - &5i32.to_bytes32(), - &7i32.to_bytes32(), - ])?; - assert_eq!(info_i32.ret, 1i32.to_bytes32()); + let a = contract.address; + println!("{a:?}"); + // let info_i32 = contract.execute([ + // "addmod_i32(int32,int32,int32)".as_bytes(), + // &3i32.to_bytes32(), + // &5i32.to_bytes32(), + // &7i32.to_bytes32(), + // ])?; + // assert_eq!(info_i32.ret, 1i32.to_bytes32()); - // Test for i64 - let info_i64 = contract.execute([ - "addmod_i64(int64,int64,int64)".as_bytes(), - &3i64.to_bytes32(), - &5i64.to_bytes32(), - &7i64.to_bytes32(), - ])?; - assert_eq!(info_i64.ret, 1i64.to_bytes32()); + // // Test for i64 + // let info_i64 = contract.execute([ + // "addmod_i64(int64,int64,int64)".as_bytes(), + // &3i64.to_bytes32(), + // &5i64.to_bytes32(), + // &7i64.to_bytes32(), + // ])?; + // assert_eq!(info_i64.ret, 1i64.to_bytes32()); - // Test for u32 - let mut contract_u32 = Contract::search("addmod_u32")?.compile()?; - let info_u32 = contract_u32.execute([ - "addmod_u32(uint32,uint32,uint32)".as_bytes(), - &3u32.to_bytes32(), - &5u32.to_bytes32(), - &7u32.to_bytes32(), - ])?; - assert_eq!(info_u32.ret, 1u32.to_bytes32()); + // let info_u32 = contract.execute([ + // "addmod_u32(uint32,uint32,uint32)".as_bytes(), + // &3u32.to_bytes32(), + // &5u32.to_bytes32(), + // &7u32.to_bytes32(), + // ])?; + // assert_eq!(info_u32.ret, 1u32.to_bytes32()); - // Test for u64 - let mut contract_u64 = Contract::search("addmod_u64")?.compile()?; - let info_u64 = contract_u64.execute([ - "addmod_u64(uint64,uint64,uint64)".as_bytes(), - &3u64.to_bytes32(), - &5u64.to_bytes32(), - &7u64.to_bytes32(), - ])?; - assert_eq!(info_u64.ret, 1u64.to_bytes32()); + // // Test for u64 + // let info_u64 = contract.execute([ + // "addmod_u64(uint64,uint64,uint64)".as_bytes(), + // &3u64.to_bytes32(), + // &5u64.to_bytes32(), + // &7u64.to_bytes32(), + // ])?; + // assert_eq!(info_u64.ret, 1u64.to_bytes32()); // // Test for U256 // let mut contract_u256 = Contract::search("addmod_U256")?.compile()?; diff --git a/zink/src/primitives/u256.rs b/zink/src/primitives/u256.rs index d544325a3..aa8f81e68 100644 --- a/zink/src/primitives/u256.rs +++ b/zink/src/primitives/u256.rs @@ -43,13 +43,13 @@ impl U256 { /// Addmod for U256 #[inline(always)] pub fn addmod(self, other: Self, modulus: Self) -> Self { - unsafe { ffi::u256_addmod(modulus, self, other) } + unsafe { ffi::u256_addmod(modulus, other, self) } } /// Mulmod for U256 #[inline(always)] pub fn mulmod(self, other: Self, modulus: Self) -> Self { - unsafe { ffi::u256_mulmod(modulus, self, other) } + unsafe { ffi::u256_mulmod(modulus, other, self) } } } From b28b16ff4e01ff38b851ec7fcde33aa7c6818682 Mon Sep 17 00:00:00 2001 From: malik Date: Thu, 28 Nov 2024 10:07:33 +0100 Subject: [PATCH 11/20] fix --- examples/addmod.rs | 80 ++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/examples/addmod.rs b/examples/addmod.rs index 5f4648475..edd71355a 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -41,51 +41,49 @@ fn test() -> anyhow::Result<()> { use zint::{Bytes32 as _, Contract}; // Test for i32 let mut contract = Contract::search("addmod")?.compile()?; - let a = contract.address; - println!("{a:?}"); - // let info_i32 = contract.execute([ - // "addmod_i32(int32,int32,int32)".as_bytes(), - // &3i32.to_bytes32(), - // &5i32.to_bytes32(), - // &7i32.to_bytes32(), - // ])?; - // assert_eq!(info_i32.ret, 1i32.to_bytes32()); - // // Test for i64 - // let info_i64 = contract.execute([ - // "addmod_i64(int64,int64,int64)".as_bytes(), - // &3i64.to_bytes32(), - // &5i64.to_bytes32(), - // &7i64.to_bytes32(), - // ])?; - // assert_eq!(info_i64.ret, 1i64.to_bytes32()); + let info_i32 = contract.execute([ + "addmod_i32(int32,int32,int32)".as_bytes(), + &3i32.to_bytes32(), + &5i32.to_bytes32(), + &7i32.to_bytes32(), + ])?; + assert_eq!(info_i32.ret, 1i32.to_bytes32()); - // let info_u32 = contract.execute([ - // "addmod_u32(uint32,uint32,uint32)".as_bytes(), - // &3u32.to_bytes32(), - // &5u32.to_bytes32(), - // &7u32.to_bytes32(), - // ])?; - // assert_eq!(info_u32.ret, 1u32.to_bytes32()); + // Test for i64 + let info_i64 = contract.execute([ + "addmod_i64(int64,int64,int64)".as_bytes(), + &3i64.to_bytes32(), + &5i64.to_bytes32(), + &7i64.to_bytes32(), + ])?; + assert_eq!(info_i64.ret, 1i64.to_bytes32()); - // // Test for u64 - // let info_u64 = contract.execute([ - // "addmod_u64(uint64,uint64,uint64)".as_bytes(), - // &3u64.to_bytes32(), - // &5u64.to_bytes32(), - // &7u64.to_bytes32(), - // ])?; - // assert_eq!(info_u64.ret, 1u64.to_bytes32()); + let info_u32 = contract.execute([ + "addmod_u32(uint32,uint32,uint32)".as_bytes(), + &3u32.to_bytes32(), + &5u32.to_bytes32(), + &7u32.to_bytes32(), + ])?; + assert_eq!(info_u32.ret, 1u32.to_bytes32()); - // // Test for U256 - // let mut contract_u256 = Contract::search("addmod_U256")?.compile()?; - // let info_u256 = contract_u256.execute([ - // "addmod_U256(uint256,uint256,uint256)".as_bytes(), - // &U256::from(3.into()).bytes32(), - // &U256::from(5.into()).bytes32(), - // &U256::from(7.into()).bytes32(), - // ])?; - // assert_eq!(info_u256.ret, U256::from(1.into()).bytes32()); + // Test for u64 + let info_u64 = contract.execute([ + "addmod_u64(uint64,uint64,uint64)".as_bytes(), + &3u64.to_bytes32(), + &5u64.to_bytes32(), + &7u64.to_bytes32(), + ])?; + assert_eq!(info_u64.ret, 1u64.to_bytes32()); + + //Test for U256 + let info_u256 = contract.execute([ + "addmod_U256(uint256,uint256,uint256)".as_bytes(), + &U256::from(3.into()).bytes32(), + &U256::from(5.into()).bytes32(), + &U256::from(7.into()).bytes32(), + ])?; + assert_eq!(info_u256.ret, U256::from(1.into()).bytes32()); Ok(()) } From dc3b2ccc98a6e21ff9d15fce113a7528afeb9be8 Mon Sep 17 00:00:00 2001 From: malik Date: Thu, 28 Nov 2024 10:10:51 +0100 Subject: [PATCH 12/20] fix --- examples/addmod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/addmod.rs b/examples/addmod.rs index edd71355a..9b65194ac 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -79,11 +79,11 @@ fn test() -> anyhow::Result<()> { //Test for U256 let info_u256 = contract.execute([ "addmod_U256(uint256,uint256,uint256)".as_bytes(), - &U256::from(3.into()).bytes32(), - &U256::from(5.into()).bytes32(), - &U256::from(7.into()).bytes32(), + 3.bytes32(), + 5.bytes32(), + 7.bytes32(), ])?; - assert_eq!(info_u256.ret, U256::from(1.into()).bytes32()); + assert_eq!(info_u256.ret, 1.bytes32()); Ok(()) } From 13656e807c32d091d490b5871ec152ddeb9e3c16 Mon Sep 17 00:00:00 2001 From: malik Date: Thu, 28 Nov 2024 10:16:08 +0100 Subject: [PATCH 13/20] fix --- examples/addmod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/addmod.rs b/examples/addmod.rs index 9b65194ac..2b7ebb53c 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -3,7 +3,7 @@ #![cfg_attr(target_arch = "wasm32", no_main)] extern crate zink; -use zink::primitives::{numeric::Numeric, U256}; +use zink::{primitives::{numeric::Numeric, U256}, Asm}; #[zink::external] pub fn addmod_i32(a: i32, b: i32, n: i32) -> i32 { @@ -79,9 +79,9 @@ fn test() -> anyhow::Result<()> { //Test for U256 let info_u256 = contract.execute([ "addmod_U256(uint256,uint256,uint256)".as_bytes(), - 3.bytes32(), - 5.bytes32(), - 7.bytes32(), + &3_i32.bytes32(), + &5_i32.bytes32(), + &7_i32.bytes32(), ])?; assert_eq!(info_u256.ret, 1.bytes32()); From d831c50ffe26ae0aa90f436f7893585aaf279620 Mon Sep 17 00:00:00 2001 From: malik Date: Thu, 28 Nov 2024 10:30:26 +0100 Subject: [PATCH 14/20] fix --- Cargo.lock | 9 ++++++++- Cargo.toml | 1 + examples/addmod.rs | 3 --- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 46d4116c6..e0569d53d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -943,6 +943,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09904adae26440d46daeacb5ed7922fee69d43ebf84d31e078cd49652cecd718" + [[package]] name = "fnv" version = "1.0.7" @@ -2627,6 +2633,7 @@ version = "0.1.11" dependencies = [ "anyhow", "evm-opcodes", + "fmt", "hex", "paste", "tiny-keccak", diff --git a/Cargo.toml b/Cargo.toml index 3415610a8..70ec8a899 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -97,6 +97,7 @@ readme = "zink/README.md" path = "zink/src/lib.rs" [dependencies] +fmt = "0.1.0" paste.workspace = true zink-codegen.workspace = true diff --git a/examples/addmod.rs b/examples/addmod.rs index 2b7ebb53c..9f2c3f2ab 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -33,9 +33,6 @@ pub fn addmod_U256(a: U256, b: U256, n: U256) -> U256 { #[cfg(not(target_arch = "wasm32"))] fn main() {} -// FIXME: this test should pass, fix it to learn how to -// add opcodes to the compiler - #[test] fn test() -> anyhow::Result<()> { use zint::{Bytes32 as _, Contract}; From b76e9b2d5ce0c4a8f5e6bf31c4a0ab26aa5183aa Mon Sep 17 00:00:00 2001 From: malik Date: Thu, 28 Nov 2024 10:32:35 +0100 Subject: [PATCH 15/20] fix --- examples/addmod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/addmod.rs b/examples/addmod.rs index 9f2c3f2ab..be388652d 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -3,7 +3,7 @@ #![cfg_attr(target_arch = "wasm32", no_main)] extern crate zink; -use zink::{primitives::{numeric::Numeric, U256}, Asm}; +use zink::primitives::{numeric::Numeric, U256}; #[zink::external] pub fn addmod_i32(a: i32, b: i32, n: i32) -> i32 { From 7065b1d03fa6e05f390f62c81f6d2bc711d70fa0 Mon Sep 17 00:00:00 2001 From: malik Date: Thu, 28 Nov 2024 10:35:46 +0100 Subject: [PATCH 16/20] fix --- examples/addmod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/addmod.rs b/examples/addmod.rs index be388652d..cb64e7a65 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -3,7 +3,7 @@ #![cfg_attr(target_arch = "wasm32", no_main)] extern crate zink; -use zink::primitives::{numeric::Numeric, U256}; +use zink::{primitives::{numeric::Numeric, U256}, Asm}; #[zink::external] pub fn addmod_i32(a: i32, b: i32, n: i32) -> i32 { @@ -76,11 +76,11 @@ fn test() -> anyhow::Result<()> { //Test for U256 let info_u256 = contract.execute([ "addmod_U256(uint256,uint256,uint256)".as_bytes(), - &3_i32.bytes32(), - &5_i32.bytes32(), - &7_i32.bytes32(), + &3i32.bytes32(), + &5i32.bytes32(), + &7i32.bytes32(), ])?; - assert_eq!(info_u256.ret, 1.bytes32()); + assert_eq!(info_u256.ret, 1i32.bytes32()); Ok(()) } From 7267e22ecb9b9c213cd7dafbbc32cbccb0c6144b Mon Sep 17 00:00:00 2001 From: malik Date: Thu, 28 Nov 2024 10:37:11 +0100 Subject: [PATCH 17/20] fix --- examples/addmod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/addmod.rs b/examples/addmod.rs index cb64e7a65..590422c34 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -3,7 +3,10 @@ #![cfg_attr(target_arch = "wasm32", no_main)] extern crate zink; -use zink::{primitives::{numeric::Numeric, U256}, Asm}; +use zink::{ + primitives::{numeric::Numeric, U256}, + Asm, +}; #[zink::external] pub fn addmod_i32(a: i32, b: i32, n: i32) -> i32 { From f701947502ae8d20d8860a3dd4fdde896dcdd8ca Mon Sep 17 00:00:00 2001 From: malik Date: Thu, 28 Nov 2024 10:40:11 +0100 Subject: [PATCH 18/20] fix --- examples/addmod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/addmod.rs b/examples/addmod.rs index 590422c34..438ae672a 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -3,10 +3,7 @@ #![cfg_attr(target_arch = "wasm32", no_main)] extern crate zink; -use zink::{ - primitives::{numeric::Numeric, U256}, - Asm, -}; +use zink::primitives::{numeric::Numeric, U256}; #[zink::external] pub fn addmod_i32(a: i32, b: i32, n: i32) -> i32 { @@ -39,6 +36,8 @@ fn main() {} #[test] fn test() -> anyhow::Result<()> { use zint::{Bytes32 as _, Contract}; + use zink::primitives::Asm; + // Test for i32 let mut contract = Contract::search("addmod")?.compile()?; From e43a7874c5592006083a098e08b2da10c73731f9 Mon Sep 17 00:00:00 2001 From: malik Date: Thu, 28 Nov 2024 10:45:41 +0100 Subject: [PATCH 19/20] fix --- examples/addmod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/addmod.rs b/examples/addmod.rs index 438ae672a..097b60f72 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -36,8 +36,7 @@ fn main() {} #[test] fn test() -> anyhow::Result<()> { use zint::{Bytes32 as _, Contract}; - use zink::primitives::Asm; - + // Test for i32 let mut contract = Contract::search("addmod")?.compile()?; From cb473bac06e787e310fffd6a38421826d2e636f2 Mon Sep 17 00:00:00 2001 From: malik Date: Thu, 28 Nov 2024 10:47:53 +0100 Subject: [PATCH 20/20] fix --- examples/addmod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/addmod.rs b/examples/addmod.rs index 097b60f72..3235b3df5 100644 --- a/examples/addmod.rs +++ b/examples/addmod.rs @@ -77,11 +77,11 @@ fn test() -> anyhow::Result<()> { //Test for U256 let info_u256 = contract.execute([ "addmod_U256(uint256,uint256,uint256)".as_bytes(), - &3i32.bytes32(), - &5i32.bytes32(), - &7i32.bytes32(), + &3i32.to_bytes32(), + &5i32.to_bytes32(), + &7i32.to_bytes32(), ])?; - assert_eq!(info_u256.ret, 1i32.bytes32()); + assert_eq!(info_u256.ret, 1i32.to_bytes32()); Ok(()) }