mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 06:21:02 +00:00
Solidity contract that accepts unverified substrate headers (#65)
* solidity contract * continue * upd * cargo update * fixes * ehtereum_headers -> headers * extracted some common stuff * ethereum_sync.rs -> sync.rs * make sync generic * continue extracting * continue * add eth-contract argument * continue * some fixes * contract v2 * continue * more fixes * more fixes * deal with duplicated params * removed multiple call_rpc variants * bail_on_error!() * fn submit_ethereum_transaction * more fixes * cargo fmt --all * fix * bail_on_arg_error!() * fix * fix * remove async_extra stuff * substrate-bridge.json -> substrate-bridge-abi.json * get rid of substrate transactions hashes * get rid of ethereum transactions hashes * extracted contract bytecode to separate file * cargo fmt --all * avoid duplicate import in contracts * removed Default::default() * swapped configurations for sub2eth && eth2sub * fix compilation * do not double gas limit when submitting Substrate headers * cargo fmt --all * solidity contract removed * consts * extracted solc compilation details to separate file * removed (obsolete in future Vec<u8> justification) * fixed cli option description * fix typos * fix grumble * extracted constants * log decoded header * cargo fmt --all * comment
This commit is contained in:
committed by
Bastian Köcher
parent
50d6ed186f
commit
3d15ac7c90
@@ -0,0 +1,20 @@
|
||||
[package]
|
||||
name = "ethereum-contract-builtin"
|
||||
description = "Small crate that helps Solidity contract to verify finality proof."
|
||||
version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
|
||||
# General dependencies
|
||||
|
||||
codec = { package = "parity-scale-codec", version = "1.0.0" }
|
||||
finality-grandpa = { version = "0.11.2", features = ["derive-codec"] }
|
||||
sp-blockchain = "2.0.0-alpha.5"
|
||||
sp-finality-grandpa = "2.0.0-alpha.5"
|
||||
sp-runtime = "2.0.0-alpha.5"
|
||||
|
||||
# Runtime/chain specific dependencies
|
||||
|
||||
bridge-node-runtime = { path = "../../../bin/node/runtime" }
|
||||
@@ -0,0 +1,79 @@
|
||||
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Bridges Common is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use bridge_node_runtime::{BlockNumber, Hash, Header as RuntimeHeader};
|
||||
use codec::Decode;
|
||||
use sp_blockchain::Error as ClientError;
|
||||
|
||||
/// Builtin errors.
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
/// Failed to decode Substrate header.
|
||||
HeaderDecode(codec::Error),
|
||||
/// Failed to decode best voters set.
|
||||
BestVotersDecode(codec::Error),
|
||||
/// Failed to decode finality proof.
|
||||
FinalityProofDecode(codec::Error),
|
||||
/// Failed to verify justification.
|
||||
JustificationVerify(ClientError),
|
||||
}
|
||||
|
||||
/// Substrate header.
|
||||
#[derive(Debug)]
|
||||
pub struct Header {
|
||||
/// Header hash.
|
||||
pub hash: Hash,
|
||||
/// Parent header hash.
|
||||
pub parent_hash: Hash,
|
||||
/// Header number.
|
||||
pub number: BlockNumber,
|
||||
/// GRANDPA validators change signal.
|
||||
pub signal: Option<ValidatorsSetSignal>,
|
||||
}
|
||||
|
||||
/// GRANDPA validators set change signal.
|
||||
#[derive(Debug)]
|
||||
pub struct ValidatorsSetSignal {
|
||||
/// Signal delay.
|
||||
pub delay: BlockNumber,
|
||||
/// New validators set.
|
||||
pub validators: Vec<u8>,
|
||||
}
|
||||
|
||||
/// Parse Substrate header.
|
||||
pub fn parse_substrate_header(raw_header: &[u8]) -> Result<Header, Error> {
|
||||
RuntimeHeader::decode(&mut &raw_header[..])
|
||||
.map(|header| Header {
|
||||
hash: header.hash(),
|
||||
parent_hash: header.parent_hash,
|
||||
number: header.number,
|
||||
signal: None, // TODO: parse me
|
||||
})
|
||||
.map_err(Error::HeaderDecode)
|
||||
}
|
||||
|
||||
/// Verify GRANDPA finality proof.
|
||||
pub fn verify_substrate_finality_proof(
|
||||
_best_set_id: u64,
|
||||
_raw_best_voters: &[u8],
|
||||
_raw_best_header: &[u8],
|
||||
_raw_headers: &[&[u8]],
|
||||
_raw_finality_proof: &[u8],
|
||||
) -> Result<(usize, usize), Error> {
|
||||
Err(Error::JustificationVerify(ClientError::Msg(
|
||||
"Not yet implemented".into(),
|
||||
))) // TODO: implement me
|
||||
}
|
||||
Reference in New Issue
Block a user