forked from neonevm/neon-evm
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NDEV-1396 Implement missing precompiled contracts (#197)
- Loading branch information
1 parent
882adc0
commit 86fe69e
Showing
2 changed files
with
31 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,32 @@ | ||
// use ethnum::U256; | ||
use ethnum::U256; | ||
|
||
#[must_use] | ||
pub fn big_mod_exp(_input: &[u8]) -> Vec<u8> { | ||
// Should be implemented via Solana syscall | ||
Vec::new() | ||
pub fn big_mod_exp(input: &[u8]) -> Vec<u8> { | ||
if input.len() < 96 { | ||
return vec![]; | ||
} | ||
|
||
// if input.len() < 96 { | ||
// return vec![]; | ||
// } | ||
let (base_len, rest) = input.split_at(32); | ||
let (exp_len, rest) = rest.split_at(32); | ||
let (mod_len, rest) = rest.split_at(32); | ||
|
||
// let (base_len, rest) = input.split_at(32); | ||
// let (exp_len, rest) = rest.split_at(32); | ||
// let (mod_len, rest) = rest.split_at(32); | ||
let Ok(base_len) = U256::from_be_bytes(base_len.try_into().unwrap()).try_into() else { | ||
return vec![]; | ||
}; | ||
let Ok(exp_len) = U256::from_be_bytes(exp_len.try_into().unwrap()).try_into() else { | ||
return vec![]; | ||
}; | ||
let Ok(mod_len) = U256::from_be_bytes(mod_len.try_into().unwrap()).try_into() else { | ||
return vec![]; | ||
}; | ||
|
||
// let base_len = match U256::from_be_bytes(base_len.try_into().unwrap()).try_into() { | ||
// Ok(value) => value, | ||
// Err(_) => return vec![] | ||
// }; | ||
// let exp_len = match U256::from_be_bytes(exp_len.try_into().unwrap()).try_into() { | ||
// Ok(value) => value, | ||
// Err(_) => return vec![] | ||
// }; | ||
// let mod_len = match U256::from_be_bytes(mod_len.try_into().unwrap()).try_into() { | ||
// Ok(value) => value, | ||
// Err(_) => return vec![] | ||
// }; | ||
if base_len == 0 && mod_len == 0 { | ||
return vec![0; 32]; | ||
} | ||
|
||
// if base_len == 0 && mod_len == 0 { | ||
// return vec![0; 32]; | ||
// } | ||
let (base_val, rest) = rest.split_at(base_len); | ||
let (exp_val, rest) = rest.split_at(exp_len); | ||
let (mod_val, _) = rest.split_at(mod_len); | ||
|
||
// let (base_val, rest) = rest.split_at(base_len); | ||
// let (exp_val, rest) = rest.split_at(exp_len); | ||
// let (mod_val, _) = rest.split_at(mod_len); | ||
|
||
// solana_program::big_mod_exp::big_mod_exp(base_val, exp_val, mod_val) | ||
solana_program::big_mod_exp::big_mod_exp(base_val, exp_val, mod_val) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,19 @@ | ||
// Should be implemented via Solana syscall | ||
// use solana_program::alt_bn128::prelude::*; | ||
use solana_program::alt_bn128::prelude::*; | ||
|
||
/// Call inner `bn256Add` | ||
#[must_use] | ||
pub fn bn256_add(_input: &[u8]) -> Vec<u8> { | ||
// Should be implemented via Solana syscall | ||
Vec::new() | ||
//alt_bn128_addition(input).unwrap_or_else(|_| vec![]) | ||
pub fn bn256_add(input: &[u8]) -> Vec<u8> { | ||
alt_bn128_addition(input).unwrap_or_else(|_| vec![]) | ||
} | ||
|
||
/// Call inner `bn256ScalarMul` | ||
#[must_use] | ||
pub fn bn256_scalar_mul(_input: &[u8]) -> Vec<u8> { | ||
// Should be implemented via Solana syscall | ||
Vec::new() | ||
//alt_bn128_multiplication(input).unwrap_or_else(|_| vec![]) | ||
pub fn bn256_scalar_mul(input: &[u8]) -> Vec<u8> { | ||
alt_bn128_multiplication(input).unwrap_or_else(|_| vec![]) | ||
} | ||
|
||
/// Call inner `bn256Pairing` | ||
#[must_use] | ||
pub fn bn256_pairing(_input: &[u8]) -> Vec<u8> { | ||
// Should be implemented via Solana syscall | ||
Vec::new() | ||
//alt_bn128_pairing(input).unwrap_or_else(|_| vec![]) | ||
pub fn bn256_pairing(input: &[u8]) -> Vec<u8> { | ||
alt_bn128_pairing(input).unwrap_or_else(|_| vec![]) | ||
} |