mirror of https://github.com/poanetwork/vdf.git
Fix install and run scripts
This commit is contained in:
parent
2994827edf
commit
fcb709b789
|
@ -12,15 +12,12 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#![deny(unsafe_code)]
|
||||
#![cfg_attr(not(test), forbid(warnings))]
|
||||
#![cfg_attr(test, deny(warnings))]
|
||||
use super::ClassGroup;
|
||||
use gmp::mpz::Mpz;
|
||||
use num_traits::{One, Zero};
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
cell::RefCell,
|
||||
fmt,
|
||||
mem::swap,
|
||||
ops::{Mul, MulAssign},
|
||||
};
|
||||
|
@ -66,13 +63,11 @@ thread_local! {
|
|||
static CTX: RefCell<Ctx> = Default::default();
|
||||
}
|
||||
|
||||
impl fmt::Display for GmpClassGroup {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{:?}\n{:?}", self.a, self.b)
|
||||
}
|
||||
}
|
||||
|
||||
impl GmpClassGroup {
|
||||
pub fn into_raw(self) -> (Mpz, Mpz) {
|
||||
(self.a, self.b)
|
||||
}
|
||||
|
||||
fn inner_multiply(&mut self, rhs: &Self, ctx: &mut Ctx) {
|
||||
self.assert_valid();
|
||||
rhs.assert_valid();
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#!/bin/sh --
|
||||
exec 2>/dev/null
|
||||
export RUSTFLAGS='-Clto -Cpanic=abort'
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
exec 2>/dev/null
|
||||
sudo apt-get -y -q update
|
||||
sudo apt-get install git build-essential libgmp3-dev -y -q
|
||||
sudo apt-get install git build-essential libgmp3-dev curl -y -q
|
||||
curl https://sh.rustup.rs -sSf | sh -s -- -y
|
||||
export PATH="$HOME/.cargo/bin:$PATH"
|
||||
. ~/.cargo/env
|
||||
rustup install nightly
|
||||
rustup default nightly
|
||||
cargo install --force --path=vdf-competition || :
|
||||
exit 0
|
||||
cargo install --force --path=vdf-competition
|
||||
|
|
14
test.sh
14
test.sh
|
@ -14,15 +14,5 @@
|
|||
# and limitations under the License.
|
||||
|
||||
# cargo run --release --bin=vdf-competition
|
||||
set -eu
|
||||
case $0 in
|
||||
(/*) cd "${0%/*}/";;
|
||||
(*/*) cd "./${0%/*}";;
|
||||
esac
|
||||
PATH=~/.cargo/bin:/usr/bin
|
||||
unset RUST_BACKTRACE CARGO_INCREMENTAL
|
||||
export RUSTFLAGS=-Clto
|
||||
# cargo build --release -pvdf-competition
|
||||
# LD_LIBRARY_PATH=~/.rustup/toolchains/beta-x86_64-unknown-linux-gnu/lib \
|
||||
cargo install --path=vdf-competition --force
|
||||
/bin/time vdf-competition -0xdc2a335cd2b355c99d3d8d92850122b3d8fe20d0f5360e7aaaecb448960d57bcddfee12a229bbd8d370feda5a17466fc725158ebb78a2a7d37d0a226d89b54434db9c3be9a9bb6ba2c2cd079221d873a17933ceb81a37b0665b9b7e247e8df66bdd45eb15ada12326db01e26c861adf0233666c01dec92bbb547df7369aed3b1fbdff867cfc670511cc270964fbd98e5c55fbe0947ac2b9803acbfd935f3abb8d9be6f938aa4b4cc6203f53c928a979a2f18a1ff501b2587a93e95a428a107545e451f0ac6c7f520a7e99bf77336b1659a2cb3dd1b60e0c6fcfffc05f74cfa763a1d0af7de9994b6e35a9682c4543ae991b3a39839230ef84dae63e88d90f457 10000 >/dev/null
|
||||
unset RUST_BACKTRACE
|
||||
exec ~/.cargo/bin/vdf-competition "$@"
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#![forbid(warnings)]
|
||||
#![forbid(unsafe_code)]
|
||||
use hex;
|
||||
|
||||
|
|
|
@ -13,60 +13,14 @@
|
|||
// limitations under the License.
|
||||
|
||||
use classgroup::{
|
||||
gmp::mpz::{mpz_ptr, Mpz},
|
||||
gmp::mpz::{mpz_ptr, Mpz, mpz_srcptr},
|
||||
gmp_classgroup::GmpClassGroup,
|
||||
ClassGroup,
|
||||
};
|
||||
use libc;
|
||||
use std::os::raw::c_void;
|
||||
use std::{env, process};
|
||||
|
||||
#[link = "gmp"]
|
||||
extern "C" {
|
||||
fn __gmp_set_memory_functions(
|
||||
arg1: Option<unsafe extern "C" fn(arg1: usize) -> *mut c_void>,
|
||||
arg2: Option<
|
||||
unsafe extern "C" fn(arg1: *mut c_void, arg2: usize, arg3: usize) -> *mut c_void,
|
||||
>,
|
||||
arg3: Option<unsafe extern "C" fn(arg1: *mut c_void, arg2: usize)>,
|
||||
);
|
||||
}
|
||||
|
||||
unsafe extern "C" fn do_realloc(
|
||||
old_ptr: *mut libc::c_void,
|
||||
old_len: libc::size_t,
|
||||
new_len: libc::size_t,
|
||||
) -> *mut libc::c_void {
|
||||
if old_len.max(2048) >= new_len {
|
||||
old_ptr
|
||||
} else {
|
||||
let q = libc::realloc(old_ptr, new_len);
|
||||
if q.is_null() {
|
||||
libc::abort()
|
||||
}
|
||||
q
|
||||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn do_malloc(len: libc::size_t) -> *mut libc::c_void {
|
||||
let q = libc::malloc(len.max(2048));
|
||||
if q.is_null() {
|
||||
libc::abort()
|
||||
}
|
||||
q
|
||||
}
|
||||
|
||||
unsafe extern "C" fn do_free(ptr: *mut libc::c_void, _len: libc::size_t) {
|
||||
if true {
|
||||
libc::free(ptr)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn main() {
|
||||
unsafe {
|
||||
__gmp_set_memory_functions(Some(do_malloc), Some(do_realloc), Some(do_free));
|
||||
}
|
||||
let fail = |q| {
|
||||
eprintln!("{}", q);
|
||||
process::exit(1)
|
||||
|
@ -81,6 +35,7 @@ fn main() {
|
|||
ptr: *const libc::c_char,
|
||||
base: libc::c_int,
|
||||
) -> libc::c_int;
|
||||
fn __gmpz_out_str(stream: *mut libc::FILE, base: libc::c_int, op: mpz_srcptr) -> libc::size_t;
|
||||
}
|
||||
|
||||
let mut args = env::args_os();
|
||||
|
@ -103,41 +58,13 @@ fn main() {
|
|||
if let Some(iterations) = args.next().unwrap().to_str().and_then(|x| x.parse().ok()) {
|
||||
let mut generator = GmpClassGroup::generator_for_discriminant(discriminant);
|
||||
generator.repeated_square(iterations);
|
||||
println!("{}", generator);
|
||||
let (a, b) = generator.into_raw();
|
||||
unsafe {
|
||||
__gmpz_out_str(std::ptr::null_mut(), 10, a.inner());
|
||||
libc::putchar(b'\n'.into());
|
||||
__gmpz_out_str(std::ptr::null_mut(), 10, b.inner());
|
||||
}
|
||||
} else {
|
||||
fail("Invalid number of iterations");
|
||||
}
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
fn main() {
|
||||
unsafe {
|
||||
__gmp_set_memory_functions(Some(do_malloc), Some(do_realloc), Some(do_free));
|
||||
}
|
||||
use std::str::FromStr;
|
||||
let fail = |q| {
|
||||
eprintln!("{}", q);
|
||||
process::exit(1)
|
||||
};
|
||||
let check_arg = |q: &mut env::ArgsOs| {
|
||||
if let Some(q) = q.next().and_then(|x| x.to_str().map(|x| x.to_owned())) {
|
||||
q
|
||||
} else {
|
||||
fail("Arguments must be valid UTF-8!".to_owned())
|
||||
}
|
||||
};
|
||||
let mut args = env::args_os();
|
||||
if args.len() != 3 {
|
||||
fail("Must have exactly two arguments".to_owned());
|
||||
}
|
||||
drop(args.next());
|
||||
let discriminant = Mpz::from_str_radix(&check_arg(&mut args), 0)
|
||||
.map_err(|x| fail(format!("{}", x)))
|
||||
.unwrap();
|
||||
let iterations: u64 = check_arg(&mut args)
|
||||
.parse()
|
||||
.map_err(|x| fail(format!("{}", x)))
|
||||
.unwrap();
|
||||
let mut generator = GmpClassGroup::generator_for_discriminant(discriminant);
|
||||
generator.repeated_square(iterations);
|
||||
println!("{}", generator);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#![forbid(warnings)]
|
||||
use std::{env, fs::File, io::Write, path::PathBuf, u16};
|
||||
|
||||
/// The number of odd primes less than 65536.
|
||||
|
|
Loading…
Reference in New Issue