Skip to content

Commit

Permalink
Merge branch 'feature/refactor-txn-keys' into alphanet
Browse files Browse the repository at this point in the history
  • Loading branch information
talekhinezh committed Sep 23, 2022
2 parents e7c531a + 542d6b9 commit 2594576
Show file tree
Hide file tree
Showing 35 changed files with 382 additions and 605 deletions.
23 changes: 12 additions & 11 deletions radix-engine/benches/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use criterion::{criterion_group, criterion_main, Criterion};
use radix_engine::types::*;
use transaction::builder::ManifestBuilder;
use transaction::builder::TransactionBuilder;
use transaction::model::TransactionHeader;
use transaction::model::{NotarizedTransaction, TransactionHeader};
use transaction::signing::EcdsaSecp256k1PrivateKey;
use transaction::signing::EddsaEd25519PrivateKey;
use transaction::validation::recover_ecdsa_secp256k1;
use transaction::validation::verify_ecdsa_secp256k1;
use transaction::validation::verify_eddsa_ed25519;
use transaction::validation::NotarizedTransactionValidator;
use transaction::validation::TestIntentHashManager;
use transaction::validation::TransactionValidator;
use transaction::validation::ValidationConfig;
use transaction::validation::{recover_ecdsa_secp256k1, TransactionValidator};

fn bench_ecdsa_secp256k1_validation(c: &mut Criterion) {
let message = "This is a long message".repeat(100);
Expand Down Expand Up @@ -80,20 +80,21 @@ fn bench_transaction_validation(c: &mut Criterion) {
let transaction_bytes = transaction.to_bytes();
println!("Transaction size: {} bytes", transaction_bytes.len());

let validator = NotarizedTransactionValidator::new(ValidationConfig {
network_id: NetworkDefinition::simulator().id,
current_epoch: 1,
max_cost_unit_limit: 10_000_000,
min_tip_percentage: 0,
});

c.bench_function("Transaction validation", |b| {
b.iter(|| {
let intent_hash_manager = TestIntentHashManager::new();
let config: ValidationConfig = ValidationConfig {
network_id: NetworkDefinition::simulator().id,
current_epoch: 1,
max_cost_unit_limit: 10_000_000,
min_tip_percentage: 0,
};

TransactionValidator::validate_from_slice(
TransactionValidator::<NotarizedTransaction>::validate_from_slice(
&validator,
&transaction_bytes,
&intent_hash_manager,
&config,
)
.unwrap();
})
Expand Down
45 changes: 2 additions & 43 deletions radix-engine/src/engine/call_frame.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use transaction::validation::*;

use crate::engine::*;
use crate::fee::FeeReserve;
use crate::model::*;
Expand Down Expand Up @@ -28,46 +26,7 @@ pub struct CallFrame {
}

impl CallFrame {
pub fn new_root(signer_public_keys: Vec<PublicKey>) -> Self {
// TODO: Cleanup initialization of authzone

let mut ecdsa_secp256k1_non_fungible_ids = BTreeSet::new();
let mut eddsa_ed25519_non_fungible_ids = BTreeSet::new();
for pk in signer_public_keys {
match pk {
PublicKey::EcdsaSecp256k1(pk) => {
ecdsa_secp256k1_non_fungible_ids.insert(NonFungibleId::from_bytes(pk.to_vec()))
}
PublicKey::EddsaEd25519(pk) => {
eddsa_ed25519_non_fungible_ids.insert(NonFungibleId::from_bytes(pk.to_vec()))
}
};
}

let mut initial_auth_zone_proofs = Vec::new();
if !ecdsa_secp256k1_non_fungible_ids.is_empty() {
// Proofs can't be zero amount
let mut ecdsa_secp256k1_bucket = Bucket::new(ResourceContainer::new_non_fungible(
ECDSA_TOKEN,
ecdsa_secp256k1_non_fungible_ids,
));
let ecdsa_secp256k1_proof = ecdsa_secp256k1_bucket
.create_proof(ECDSA_TOKEN_BUCKET_ID)
.expect("Failed to construct ECDSA signature proof");
initial_auth_zone_proofs.push(ecdsa_secp256k1_proof);
}
if !eddsa_ed25519_non_fungible_ids.is_empty() {
// Proofs can't be zero amount
let mut eddsa_ed25519_bucket = Bucket::new(ResourceContainer::new_non_fungible(
ED25519_TOKEN,
eddsa_ed25519_non_fungible_ids,
));
let eddsa_ed25519_proof = eddsa_ed25519_bucket
.create_proof(ED25519_TOKEN_BUCKET_ID)
.expect("Failed to construct ED25519 signature proof");
initial_auth_zone_proofs.push(eddsa_ed25519_proof);
}

pub fn new_root() -> Self {
Self {
depth: 0,
actor: REActor {
Expand All @@ -79,7 +38,7 @@ impl CallFrame {
},
node_refs: HashMap::new(),
owned_heap_nodes: HashMap::new(),
auth_zone: AuthZone::new_with_proofs(initial_auth_zone_proofs),
auth_zone: AuthZone::new(),
}
}

Expand Down
36 changes: 22 additions & 14 deletions radix-engine/src/engine/kernel.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use transaction::errors::IdAllocationError;
use transaction::model::ExecutableInstruction;
use transaction::model::Instruction;
use transaction::validation::*;

use crate::engine::*;
Expand Down Expand Up @@ -69,9 +69,8 @@ where
{
pub fn new(
transaction_hash: Hash,
transaction_signers: Vec<PublicKey>,
initial_proofs: Vec<NonFungibleAddress>,
blobs: &'g HashMap<Hash, Vec<u8>>,
is_system: bool,
max_depth: usize,
track: &'g mut Track<'s, R>,
wasm_engine: &'g mut W,
Expand All @@ -80,7 +79,7 @@ where
execution_trace: &'g mut ExecutionTrace,
modules: Vec<Box<dyn Module<R>>>,
) -> Self {
let frame = CallFrame::new_root(transaction_signers);
let frame = CallFrame::new_root();
let mut kernel = Self {
transaction_hash,
blobs,
Expand All @@ -96,30 +95,39 @@ where
phantom: PhantomData,
};

if is_system {
let non_fungible_ids = [NonFungibleId::from_u32(0)].into_iter().collect();
// Initial authzone
// TODO: Move into module initialization
let mut proofs_to_create = BTreeMap::<ResourceAddress, BTreeSet<NonFungibleId>>::new();
for non_fungible in initial_proofs {
proofs_to_create
.entry(non_fungible.resource_address())
.or_insert(BTreeSet::new())
.insert(non_fungible.non_fungible_id());
}
for (resource_address, non_fungible_ids) in proofs_to_create {
let bucket_id = match kernel
.node_create(HeapRENode::Bucket(Bucket::new(
ResourceContainer::new_non_fungible(SYSTEM_TOKEN, non_fungible_ids),
ResourceContainer::new_non_fungible(resource_address, non_fungible_ids),
)))
.expect("Failed to create SYSTEM_TOKEN bucket")
.expect("Failed to create bucket")
{
RENodeId::Bucket(bucket_id) => bucket_id,
_ => panic!("Expected Bucket RENodeId but received something else"),
};
let substate_id = SubstateId::Bucket(bucket_id);
let mut node_ref = kernel
.substate_borrow_mut(&substate_id)
.expect("Failed to borrow SYSTEM_TOKEN bucket substate");
.expect("Failed to borrow bucket substate");
let bucket = node_ref.bucket();
let system_proof = bucket
let proof = bucket
.create_proof(bucket_id)
.expect("Failed to create SYSTEM_TOKEN proof");
.expect("Failed to create proof");
Self::current_frame_mut(&mut kernel.call_frames)
.auth_zone
.proofs
.push(system_proof);
.push(proof);
}

kernel
}

Expand Down Expand Up @@ -536,8 +544,8 @@ where
scrypto_decode(&input.raw).expect("Transaction processor received invalid input");
for instruction in &input.instructions {
match instruction {
ExecutableInstruction::CallFunction { args, .. }
| ExecutableInstruction::CallMethod { args, .. } => {
Instruction::CallFunction { args, .. }
| Instruction::CallMethod { args, .. } => {
let scrypto_value =
ScryptoValue::from_slice(&args).expect("Invalid CALL arguments");
component_addresses.extend(scrypto_value.refed_component_addresses);
Expand Down
2 changes: 1 addition & 1 deletion radix-engine/src/engine/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl<'s, R: FeeReserve> Track<'s, R> {
.and_then(|()| {
self.fee_reserve.consume(
self.fee_table.tx_signature_verification_per_sig()
* transaction.signer_public_keys().len() as u32,
* transaction.initial_proofs().len() as u32,
"verify_signatures",
false,
)
Expand Down
Loading

0 comments on commit 2594576

Please sign in to comment.