mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 16:55:46 +00:00
Update to use v0.9.2 version of deposit contract
This commit is contained in:
@@ -23,7 +23,7 @@ use types::Hash256;
|
|||||||
pub const DEPOSIT_EVENT_TOPIC: &str =
|
pub const DEPOSIT_EVENT_TOPIC: &str =
|
||||||
"0x649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5";
|
"0x649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5";
|
||||||
/// `keccak("get_deposit_root()")[0..4]`
|
/// `keccak("get_deposit_root()")[0..4]`
|
||||||
pub const DEPOSIT_ROOT_FN_SIGNATURE: &str = "0x863a311b";
|
pub const DEPOSIT_ROOT_FN_SIGNATURE: &str = "0xc5f2892f";
|
||||||
/// `keccak("get_deposit_count()")[0..4]`
|
/// `keccak("get_deposit_count()")[0..4]`
|
||||||
pub const DEPOSIT_COUNT_FN_SIGNATURE: &str = "0x621fd130";
|
pub const DEPOSIT_COUNT_FN_SIGNATURE: &str = "0x621fd130";
|
||||||
|
|
||||||
|
|||||||
2
eth2/utils/deposit_contract/.gitignore
vendored
2
eth2/utils/deposit_contract/.gitignore
vendored
@@ -1 +1 @@
|
|||||||
contract/
|
contracts/
|
||||||
|
|||||||
@@ -3,21 +3,23 @@
|
|||||||
//!
|
//!
|
||||||
//! These files are required for some `include_bytes` calls used in this crate.
|
//! These files are required for some `include_bytes` calls used in this crate.
|
||||||
|
|
||||||
use reqwest::Response;
|
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
const GITHUB_RAW: &str = "https://raw.githubusercontent.com";
|
const TAG: &str = "v0.9.2";
|
||||||
const SPEC_REPO: &str = "ethereum/eth2.0-specs";
|
|
||||||
const SPEC_TAG: &str = "v0.8.3";
|
fn spec_url() -> String {
|
||||||
const ABI_FILE: &str = "validator_registration.json";
|
format!("https://raw.githubusercontent.com/ethereum/eth2.0-specs/{}/deposit_contract/contracts/validator_registration.json", TAG)
|
||||||
const BYTECODE_FILE: &str = "validator_registration.bytecode";
|
}
|
||||||
|
fn testnet_url() -> String {
|
||||||
|
format!("https://raw.githubusercontent.com/sigp/unsafe-eth2-deposit-contract/{}/unsafe_validator_registration.json", TAG)
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match init_deposit_contract_abi() {
|
match get_all_contracts() {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(e) => panic!(e),
|
Err(e) => panic!(e),
|
||||||
}
|
}
|
||||||
@@ -25,14 +27,33 @@ fn main() {
|
|||||||
|
|
||||||
/// Attempts to download the deposit contract ABI from github if a local copy is not already
|
/// Attempts to download the deposit contract ABI from github if a local copy is not already
|
||||||
/// present.
|
/// present.
|
||||||
pub fn init_deposit_contract_abi() -> Result<(), String> {
|
pub fn get_all_contracts() -> Result<(), String> {
|
||||||
let abi_file = abi_dir().join(format!("{}_{}", SPEC_TAG, ABI_FILE));
|
download_deposit_contract(
|
||||||
let bytecode_file = abi_dir().join(format!("{}_{}", SPEC_TAG, BYTECODE_FILE));
|
&spec_url(),
|
||||||
|
"validator_registration.json",
|
||||||
|
"validator_registration.bytecode",
|
||||||
|
)?;
|
||||||
|
download_deposit_contract(
|
||||||
|
&testnet_url(),
|
||||||
|
"testnet_validator_registration.json",
|
||||||
|
"testnet_validator_registration.bytecode",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Attempts to download the deposit contract ABI from github if a local copy is not already
|
||||||
|
/// present.
|
||||||
|
pub fn download_deposit_contract(
|
||||||
|
url: &str,
|
||||||
|
abi_file: &str,
|
||||||
|
bytecode_file: &str,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let abi_file = abi_dir().join(format!("{}_{}", TAG, abi_file));
|
||||||
|
let bytecode_file = abi_dir().join(format!("{}_{}", TAG, bytecode_file));
|
||||||
|
|
||||||
if abi_file.exists() {
|
if abi_file.exists() {
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
} else {
|
} else {
|
||||||
match download_abi() {
|
match reqwest::get(url) {
|
||||||
Ok(mut response) => {
|
Ok(mut response) => {
|
||||||
let mut abi_file = File::create(abi_file)
|
let mut abi_file = File::create(abi_file)
|
||||||
.map_err(|e| format!("Failed to create local abi file: {:?}", e))?;
|
.map_err(|e| format!("Failed to create local abi file: {:?}", e))?;
|
||||||
@@ -71,22 +92,13 @@ pub fn init_deposit_contract_abi() -> Result<(), String> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to download the deposit contract file from the Ethereum github.
|
|
||||||
fn download_abi() -> Result<Response, String> {
|
|
||||||
reqwest::get(&format!(
|
|
||||||
"{}/{}/{}/deposit_contract/contracts/{}",
|
|
||||||
GITHUB_RAW, SPEC_REPO, SPEC_TAG, ABI_FILE
|
|
||||||
))
|
|
||||||
.map_err(|e| format!("Failed to download deposit ABI from github: {:?}", e))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the directory that will be used to store the deposit contract ABI.
|
/// Returns the directory that will be used to store the deposit contract ABI.
|
||||||
fn abi_dir() -> PathBuf {
|
fn abi_dir() -> PathBuf {
|
||||||
let base = env::var("CARGO_MANIFEST_DIR")
|
let base = env::var("CARGO_MANIFEST_DIR")
|
||||||
.expect("should know manifest dir")
|
.expect("should know manifest dir")
|
||||||
.parse::<PathBuf>()
|
.parse::<PathBuf>()
|
||||||
.expect("should parse manifest dir as path")
|
.expect("should parse manifest dir as path")
|
||||||
.join("contract");
|
.join("contracts");
|
||||||
|
|
||||||
std::fs::create_dir_all(base.clone())
|
std::fs::create_dir_all(base.clone())
|
||||||
.expect("should be able to create abi directory in manifest");
|
.expect("should be able to create abi directory in manifest");
|
||||||
|
|||||||
@@ -1,21 +1,32 @@
|
|||||||
use ethabi::{Contract, Token};
|
use ethabi::{Contract, Token};
|
||||||
use ssz::Encode;
|
use ssz::Encode;
|
||||||
|
use tree_hash::TreeHash;
|
||||||
use types::DepositData;
|
use types::DepositData;
|
||||||
|
|
||||||
pub use ethabi::Error;
|
pub use ethabi::Error;
|
||||||
|
|
||||||
pub const CONTRACT_DEPLOY_GAS: usize = 4_000_000;
|
pub const CONTRACT_DEPLOY_GAS: usize = 4_000_000;
|
||||||
pub const DEPOSIT_GAS: usize = 4_000_000;
|
pub const DEPOSIT_GAS: usize = 4_000_000;
|
||||||
pub const ABI: &[u8] = include_bytes!("../contract/v0.8.3_validator_registration.json");
|
pub const ABI: &[u8] = include_bytes!("../contracts/v0.9.2_validator_registration.json");
|
||||||
pub const BYTECODE: &[u8] = include_bytes!("../contract/v0.8.3_validator_registration.bytecode");
|
pub const BYTECODE: &[u8] = include_bytes!("../contracts/v0.9.2_validator_registration.bytecode");
|
||||||
|
|
||||||
|
pub mod testnet {
|
||||||
|
pub const ABI: &[u8] =
|
||||||
|
include_bytes!("../contracts/v0.9.2_testnet_validator_registration.json");
|
||||||
|
pub const BYTECODE: &[u8] =
|
||||||
|
include_bytes!("../contracts/v0.9.2_testnet_validator_registration.bytecode");
|
||||||
|
}
|
||||||
|
|
||||||
pub fn eth1_tx_data(deposit_data: &DepositData) -> Result<Vec<u8>, Error> {
|
pub fn eth1_tx_data(deposit_data: &DepositData) -> Result<Vec<u8>, Error> {
|
||||||
let params = vec![
|
let params = vec![
|
||||||
Token::Bytes(deposit_data.pubkey.as_ssz_bytes()),
|
Token::Bytes(deposit_data.pubkey.as_ssz_bytes()),
|
||||||
Token::Bytes(deposit_data.withdrawal_credentials.as_ssz_bytes()),
|
Token::Bytes(deposit_data.withdrawal_credentials.as_ssz_bytes()),
|
||||||
Token::Bytes(deposit_data.signature.as_ssz_bytes()),
|
Token::Bytes(deposit_data.signature.as_ssz_bytes()),
|
||||||
|
Token::FixedBytes(deposit_data.tree_hash_root().as_ssz_bytes()),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Here we make an assumption that the `crate::testnet::ABI` has a superset of the features of
|
||||||
|
// the crate::ABI`.
|
||||||
let abi = Contract::load(ABI)?;
|
let abi = Contract::load(ABI)?;
|
||||||
let function = abi.function("deposit")?;
|
let function = abi.function("deposit")?;
|
||||||
function.encode_input(¶ms)
|
function.encode_input(¶ms)
|
||||||
|
|||||||
Reference in New Issue
Block a user