Skip to content

Commit

Permalink
add expected receipt in the extrisinct, actrully can get from last no…
Browse files Browse the repository at this point in the history
…de of proof? to safe space
  • Loading branch information
hackfisher committed Nov 29, 2019
1 parent 76ea95f commit cba6644
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
8 changes: 5 additions & 3 deletions core/sr-eth-primitives/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use rstd::prelude::*;
use codec::{Decode, Encode};
use primitive_types::{H256, U256};

#[derive(PartialEq, Eq, Clone, Encode, Decode)]
use sr_primitives::RuntimeDebug;

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
pub enum TransactionOutcome {
/// Status and state root are unknown under EIP-98 rules.
Unknown,
Expand All @@ -17,7 +19,7 @@ pub enum TransactionOutcome {
StatusCode(u8),
}

#[derive(PartialEq, Eq, Clone, RlpEncodable, RlpDecodable, Encode, Decode)]
#[derive(PartialEq, Eq, Clone, RlpEncodable, RlpDecodable, Encode, Decode, RuntimeDebug)]
pub struct LogEntry {
/// The address of the contract executing at the point of the `LOG` operation.
pub address: Address,
Expand All @@ -39,7 +41,7 @@ impl LogEntry {
}
}

#[derive(PartialEq, Eq, Clone, Encode, Decode)]
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
pub struct Receipt {
/// The total gas used in the block following execution of the transaction.
pub gas_used: U256,
Expand Down
27 changes: 11 additions & 16 deletions srml/ethereum-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use codec::{Decode, Encode};
use rstd::vec::Vec;
use sr_eth_primitives::{
header::EthHeader, pow::EthashPartial, pow::EthashSeal, BestBlock, BlockNumber as EthBlockNumber, H160, H256, H64,
U128, U256, U512,
header::EthHeader, pow::EthashPartial, pow::EthashSeal, receipt::Receipt, BestBlock, BlockNumber as EthBlockNumber,
H160, H256, H64, U128, U256, U512,
};

use ethash::{EthereumPatch, LightDAG};
Expand All @@ -21,7 +21,7 @@ use sr_primitives::RuntimeDebug;

use rlp::{decode, encode};

use merkle_patricia_trie::{trie::Trie, MerklePatriciaTrie};
use merkle_patricia_trie::{trie::Trie, MerklePatriciaTrie, Proof};

type DAG = LightDAG<EthereumPatch>;

Expand All @@ -30,11 +30,6 @@ pub trait Trait: system::Trait {
// type Hash: rstd::hash::Hash;
}

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
pub struct Proof {
pub nodes: Vec<Vec<u8>>,
}

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
pub struct ActionRecord {
pub index: u64,
Expand Down Expand Up @@ -92,31 +87,31 @@ decl_module! {
<Module<T>>::deposit_event(RawEvent::NewHeader(header));
}

pub fn check_receipt(origin, proof: ActionRecord) {
pub fn check_receipt(origin, receipt: Receipt, proof_record: ActionRecord) {
let _relayer = ensure_signed(origin)?;

let header_hash = proof.header_hash;
let header_hash = proof_record.header_hash;
if !HeaderOf::exists(header_hash) {
return Err("This block header does not exist.")
}

let header = HeaderOf::get(header_hash).unwrap();

let proof: Proof = rlp::decode(&proof_record.proof).unwrap();
let key = rlp::encode(&proof_record.index);

// let proof: Proof = rlp::decode(&rlp_proof).unwrap();
// let key = rlp::encode(&1usize);
let value = MerklePatriciaTrie::verify_proof(header.receipts_root(), proof.index, proof.proof)
let value = MerklePatriciaTrie::verify_proof(header.receipts_root().0.to_vec(), &key, proof)
.unwrap();
assert!(value.is_some());

// let expected: Vec<u8> = Vec::from_hex("f9010901835cdb6eb9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0").unwrap();
let receipt_encoded = rlp::encode(&receipt);

// assert_eq!(value.unwrap(), expected);
assert_eq!(value.unwrap(), receipt_encoded);
// confirm that the block hash is right
// get the receipt MPT trie root from the block header
// Using receipt MPT trie root to verify the proof and index etc.

<Module<T>>::deposit_event(RawEvent::RelayProof(proof));
<Module<T>>::deposit_event(RawEvent::RelayProof(proof_record));
}

pub fn submit_header(origin, header: EthHeader) {
Expand Down

0 comments on commit cba6644

Please sign in to comment.