Skip to content

Commit 94386ea

Browse files
authored
chore(l2): bump ZisK to 0.15.0 & add modexp syscall (#5694)
0.15.0 introduces a new modexp syscall and fixes for the existing patches, apart from other optimizations (see https://github.com/0xPolygonHermez/zisk/releases/tag/v0.15.0) we found a regression some time ago in main, probably related to a ZisK patch, in which some blocks failed to execute with a gas mismatch error. We tested those blocks again and the regression was gone. So the new patches' versions contain fixes too.
1 parent b211ae9 commit 94386ea

File tree

8 files changed

+44
-110
lines changed

8 files changed

+44
-110
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/l2/prover/src/backend/zisk.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ pub fn prove(
105105
.into());
106106
}
107107

108-
let proof_bytes = std::fs::read(format!(
109-
"{OUTPUT_DIR_PATH}/vadcop_final_proof.compressed.bin"
110-
))?;
108+
let proof_bytes = std::fs::read(format!("{OUTPUT_DIR_PATH}/vadcop_final_proof.bin"))?;
111109
let output = ProveOutput(proof_bytes);
112110
Ok(output)
113111
}

crates/l2/prover/src/guest_program/src/zisk/Cargo.lock

Lines changed: 11 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/l2/prover/src/guest_program/src/zisk/Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2024"
66
[workspace]
77

88
[dependencies]
9-
ziskos = { git = "https://github.com/0xPolygonHermez/zisk.git", tag = "v0.14.0" }
9+
ziskos = { git = "https://github.com/0xPolygonHermez/zisk.git", tag = "v0.15.0" }
1010
sha2 = "0.10.9"
1111
rkyv = { version = "0.8.10", features = ["std", "unaligned"] }
1212

@@ -22,13 +22,13 @@ ethrex-blockchain = { path = "../../../../../../blockchain", default-features =
2222
] }
2323

2424
[patch.crates-io]
25-
sha2 = { git = "https://github.com/0xPolygonHermez/zisk-patch-hashes.git", tag = "patch-sha2-0.10.9-zisk-0.14.0" }
26-
sha3 = { git = "https://github.com/0xPolygonHermez/zisk-patch-hashes.git", tag = "patch-sha3-0.10.8-zisk-0.14.0" }
27-
k256 = { git = "https://github.com/0xPolygonHermez/zisk-patch-elliptic-curves.git", tag = "patch-k256-0.13.4-zisk-0.14.0" }
28-
substrate-bn = { git = "https://github.com/0xPolygonHermez/zisk-patch-bn.git", tag = "patch-0.6.0-zisk-0.14.0" }
29-
sp1_bls12_381 = { git = "https://github.com/0xPolygonHermez/zisk-patch-bls12-381", tag = "patch-0.8.0-zisk-0.14.0" }
30-
tiny-keccak = { git = "https://github.com/0xPolygonHermez/zisk-patch-tiny-keccak/", branch = "zisk" }
31-
kzg-rs = { git = "https://github.com/0xPolygonHermez/zisk-patch-kzg/", tag = "patch-0.2.7-zisk-0.14.0" }
25+
sha2 = { git = "https://github.com/0xPolygonHermez/zisk-patch-hashes.git", tag = "patch-sha2-0.10.9-zisk-0.15.0" }
26+
sha3 = { git = "https://github.com/0xPolygonHermez/zisk-patch-hashes.git", tag = "patch-sha3-0.10.8-zisk-0.15.0" }
27+
k256 = { git = "https://github.com/0xPolygonHermez/zisk-patch-elliptic-curves.git", tag = "patch-k256-0.13.4-zisk-0.15.0" }
28+
substrate-bn = { git = "https://github.com/0xPolygonHermez/zisk-patch-bn.git", tag = "patch-0.6.0-zisk-0.15.0" }
29+
sp1_bls12_381 = { git = "https://github.com/0xPolygonHermez/zisk-patch-bls12-381", tag = "patch-0.8.0-zisk-0.15.0" }
30+
tiny-keccak = { git = "https://github.com/0xPolygonHermez/zisk-patch-tiny-keccak/", tag = "patch-2.0.2-zisk-0.15.0" }
31+
kzg-rs = { git = "https://github.com/0xPolygonHermez/zisk-patch-kzg/", tag = "patch-0.2.7-zisk-0.15.0" }
3232

3333
[features]
3434
l2 = ["guest_program/l2"]

crates/l2/tee/quote-gen/Cargo.lock

Lines changed: 1 addition & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vm/levm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ strum = { version = "0.27.1", features = ["derive"] }
4343
k256.workspace = true
4444
substrate-bn = { version = "0.6.0", optional = true }
4545
secp256k1 = { workspace = true, optional = true }
46-
ziskos = { git = "https://github.com/0xPolygonHermez/zisk.git", tag = "v0.14.0", optional = true }
46+
ziskos = { git = "https://github.com/0xPolygonHermez/zisk.git", tag = "v0.15.0", optional = true }
4747

4848
bitvec = { version = "1.0.1", features = ["alloc"] }
4949

crates/vm/levm/src/opcode_handlers/arithmetic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ impl<'a> VM<'a> {
189189

190190
#[cfg(feature = "zisk")]
191191
let product_mod = {
192-
use ziskos::zisklib::mulmod256_ptr;
192+
use ziskos::zisklib::mulmod256_c;
193193
let mut product_mod = U256::zero();
194194
unsafe {
195-
mulmod256_ptr(
195+
mulmod256_c(
196196
multiplicand.0.as_ptr(),
197197
multiplier.0.as_ptr(),
198198
modulus.0.as_ptr(),

crates/vm/levm/src/precompiles.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,22 @@ fn mod_exp(base: Natural, exponent: Natural, modulus: Natural) -> Natural {
687687
} else if exponent == Natural::ZERO {
688688
Natural::from(1_u8) % modulus
689689
} else {
690-
let base_mod = base % &modulus; // malachite requires base to be reduced to modulus first
691-
base_mod.mod_pow(&exponent, &modulus)
690+
#[cfg(not(feature = "zisk"))]
691+
{
692+
let base_mod = base % &modulus; // malachite requires base to be reduced to modulus first
693+
base_mod.mod_pow(&exponent, &modulus)
694+
}
695+
696+
#[cfg(feature = "zisk")]
697+
{
698+
use ziskos::zisklib::modexp_u64;
699+
let (mut base, mut exponent, mut modulus) = (base, exponent, modulus);
700+
let base_limbs = base.to_limbs_asc();
701+
let exponent_limbs = exponent.to_limbs_asc();
702+
let modulus_limbs = modulus.to_limbs_asc();
703+
let result_limbs = modexp_u64(&base_limbs, &exponent_limbs, &modulus_limbs);
704+
Natural::from_owned_limbs_asc(result_limbs)
705+
}
692706
}
693707
}
694708

0 commit comments

Comments
 (0)