Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/<your program>",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
20 changes: 11 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: "3.7"
services:
sgx_machine:
sgx_machine_kim:
image: osuketh/anonify:1804-1.1.3
volumes:
- .:/root/anonify
Expand All @@ -13,22 +13,22 @@ services:
stdin_open: true
tty: true
networks:
testing_net:
ipv4_address: 172.28.1.1
testing_net_kim:
ipv4_address: 172.48.1.1

ganache:
ganache_kim:
image: trufflesuite/ganache-cli:latest
ports:
- "8545:8545"
- "28545:8545"
volumes:
- ./ganache_data:/ganache_data
networks:
testing_net:
ipv4_address: 172.28.0.2
testing_net_kim:
ipv4_address: 172.48.0.2

networks:
testing_net:
testing_net_kim:
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
- subnet: 172.48.0.0/16
2 changes: 1 addition & 1 deletion example/erc20/server/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ async fn test_join_group_then_handshake() {
}

fn set_server_env_vars() {
env::set_var("ETH_URL", "http://172.28.0.2:8545");
env::set_var("ETH_URL", "http://172.48.0.2:8545");
env::set_var("ABI_PATH", "../../../contract-build/Anonify.abi");
env::set_var("BIN_PATH", "../../../contract-build/Anonify.bin");
env::set_var("CONFIRMATIONS", "0");
Expand Down
2 changes: 2 additions & 0 deletions frame/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ rand_core = { version = "0.3", optional = true }
rand_os = { version = "0.1", optional = true }
base64 = { version = "0.11", optional = true }
lazy_static = { version = "1.4", features = ["spin_no_std"] }
once_cell = "1.5.2"
parking_lot = "0.11.1"

[features]
default = ["std"]
Expand Down
9 changes: 9 additions & 0 deletions frame/common/src/benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// use crate::localstd::{collections::HashMap, time::SystemTime};
// use once_cell::sync::Lazy;
// use parking_lot::Mutex;

// static PENDING_TX: Lazy<Mutex<HashMap<i32, SystemTime>>> = Lazy::new(|| {
// let mut m = HashMap::new();
// m.insert(0, SystemTime::now());
// Mutex::new(m)
// });
1 change: 1 addition & 0 deletions frame/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use sgx_anyhow as local_anyhow;
#[macro_use]
extern crate lazy_static;

// pub mod benchmark;
pub mod crypto;
pub mod state_types;
pub mod traits;
Expand Down
7 changes: 7 additions & 0 deletions frame/enclave/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ macro_rules! register_ecall {
let input = EE::EI::decode(&mut &input_payload[..])
.map_err(|e| anyhow!("{:?}", e))?;
EE::eval_policy(&input)?;

let t4 = std::time::SystemTime::now();
println!("########## t4: {:?}", t4);
// txを送る側の場合、MsgSenderのhandleを、
// eventを取得する側の場合、MsgReceiverのhandleを実行
let res = EE::handle::<$runtime_exec, $ctx_ops>(input, $ctx, $max_mem)?;
let t5 = std::time::SystemTime::now();
println!("########## t5: {:?}", t5);

Ok(res.encode())
}
Expand Down
5 changes: 4 additions & 1 deletion frame/host/src/ecalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ impl EnclaveConnector {
let output_ptr = output_buf.as_mut_ptr();

let mut ret = EnclaveStatus::default();

let t3 = std::time::SystemTime::now();
println!("########## t3: {:?}", t3);
let status = unsafe {
ecall_entry_point(
self.eid,
Expand All @@ -64,6 +65,8 @@ impl EnclaveConnector {
&mut output_len,
)
};
let t6 = std::time::SystemTime::now();
println!("########## t6: {:?}", t6);

if status != sgx_status_t::SGX_SUCCESS {
return Err(FrameHostError::SgxStatus {
Expand Down
2 changes: 1 addition & 1 deletion frame/host/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub trait HostEngine {
let (ecall_input, host_output) = input.apply()?;
let ecall_output = EnclaveConnector::new(eid, Self::OUTPUT_MAX_LEN)
.invoke_ecall::<Self::EI, Self::EO>(Self::CMD, ecall_input)?;

host_output.set_ecall_output(ecall_output)
}
}
Expand Down
16 changes: 11 additions & 5 deletions modules/anonify-enclave/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,23 @@ impl<AP: AccessPolicy> EnclaveEngine for MsgSender<AP> {
R: RuntimeExecutor<C, S = StateType>,
C: ContextOps<S = StateType> + Clone,
{
// グループキー取得
let group_key = &mut *enclave_context.write_group_key();
let roster_idx = group_key.my_roster_idx() as usize;
// 送信側のグループ鍵交換
// ratchet sender's app keychain per tx.
group_key.sender_ratchet(roster_idx)?;

let account_id = ecall_input.access_policy().into_account_id();
// 暗号化された状態遷移コマンドを復号
let mut command = enclave_context.decrypt(ecall_input.encrypted_command)?;

// 暗号文作成(TX送信用?)
let ciphertext = Commands::<R, C>::new(ecall_input.call_id, &mut command, account_id)?
.encrypt(group_key, max_mem_size)?;

// 署名
let msg = Sha256::hash(&ciphertext.encode());
let enclave_sig = enclave_context.sign(msg.as_bytes())?;
// コマンド(TXに入れるやつ)生成
let command_output = output::Command::new(ciphertext, enclave_sig.0, enclave_sig.1);

enclave_context.set_notification(account_id);

Ok(command_output)
Expand All @@ -64,6 +66,7 @@ impl EnclaveEngine for MsgReceiver {
type EI = input::InsertCiphertext;
type EO = output::ReturnUpdatedState;

// BCからeventを取得して、その中に暗号文が入っている場合、Enclaveの中ではこの処理が実行される
fn handle<R, C>(
ecall_input: Self::EI,
enclave_context: &C,
Expand All @@ -86,10 +89,12 @@ impl EnclaveEngine for MsgReceiver {
// In addition to these, `sync_ratchet` fails even if the receiver generation is larger than that of the sender
// So if you run `sync_ratchet` first,
// it will either succeed or both fail for the mutable `app_keychain`, so it will be atomic.
// グループキー同期
group_key.sync_ratchet(roster_idx, msg_gen)?;
group_key.receiver_ratchet(roster_idx)?;

// Even if an error occurs in the state transition logic here, there is no problem because the state of `app_keychain` is consistent.
// 状態遷移ロジック実行
// 暗号文を平文に変換し、runtime上で状態遷移を実行
let iter_op = Commands::<R, C>::state_transition(
enclave_context.clone(),
ecall_input.ciphertext(),
Expand All @@ -98,6 +103,7 @@ impl EnclaveEngine for MsgReceiver {
let mut output = output::ReturnUpdatedState::default();

if let Some(updated_state_iter) = iter_op {
// 状態遷移処理が成功したらupdate_state -> insert_by_updated_state
if let Some(updated_state) = enclave_context.update_state(updated_state_iter) {
output.update(updated_state);
}
Expand Down
5 changes: 4 additions & 1 deletion modules/anonify-eth-driver/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,11 @@ where
gas,
);
let eid = inner.deployer.get_enclave_id();
let t2 = std::time::SystemTime::now();
println!("########## t2: {:?}", t2);
let host_output = CommandWorkflow::exec(input, eid)?;

let t7 = std::time::SystemTime::now();
println!("########## t7: {:?}", t7);
match &inner.sender {
Some(s) => s.send_command(host_output).await,
None => Err(HostError::AddressNotSet),
Expand Down
2 changes: 2 additions & 0 deletions modules/anonify-eth-driver/src/eth/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ impl Web3Contract {
enclave_sig.push(recovery_id);
let gas = output.gas;

let t8 = std::time::SystemTime::now();
println!("############### t8 {:?}", t8);
self.contract
.call(
"storeCommand",
Expand Down
19 changes: 14 additions & 5 deletions modules/anonify-eth-driver/src/eth/event_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@ impl Watcher for EventWatcher {
&self,
eid: sgx_enclave_id_t,
) -> Result<Option<Vec<UpdatedState<S>>>> {
let enclave_updated_state = self
let event_logs = self
.contract
.get_event(self.cache.clone(), self.contract.address())
.await?
.into_enclave_log()
.insert_enclave(eid)
.save_cache(self.contract.address());
.await?;

let t10 = std::time::SystemTime::now();
println!("########## t10: {:?}", t10);
let enclave_updated_state = event_logs.into_enclave_log()
.insert_enclave(eid);
let t11 = std::time::SystemTime::now();
println!("########## t11: {:?}", t11);

let enclave_updated_state = enclave_updated_state.save_cache(self.contract.address());

Ok(enclave_updated_state.updated_states())
}
Expand Down Expand Up @@ -194,6 +200,7 @@ impl EnclaveLog {
match self.inner {
Some(log) => {
let next_blc_num = log.latest_blc_num + 1;
// ここね!
let updated_states = log.invoke_ecall(eid);

EnclaveUpdatedState {
Expand Down Expand Up @@ -230,6 +237,7 @@ impl InnerEnclaveLog {

for e in self.payloads {
match e.payload {
// 暗号文が存在してたらそれをTEE上で処理する
Payload::Ciphertext(ciphertext) => {
info!(
"Fetch a ciphertext: roster_idx: {}, epoch: {}, generation: {}",
Expand All @@ -239,6 +247,7 @@ impl InnerEnclaveLog {
);

let inp = host_input::InsertCiphertext::new(ciphertext.clone());
// InsertCiphertextWorkflowのCMDは2
match InsertCiphertextWorkflow::exec(inp, eid)
.map_err(Into::into)
.and_then(|e| {
Expand Down
1 change: 1 addition & 0 deletions modules/anonify-eth-driver/src/eth/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl Sender for EthSender {

async fn send_command(&self, host_output: host_output::Command) -> Result<H256> {
info!("Sending a command to blockchain: {:?}", host_output);
// コントラクト実行
self.contract.send_command(host_output).await
}

Expand Down
18 changes: 9 additions & 9 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ cd ../tests/integration
RUST_BACKTRACE=1 RUST_LOG=debug cargo test -- --nocapture

cd ../../example/erc20/server
RUST_BACKTRACE=1 RUST_LOG=debug cargo test test_deploy_post -- --nocapture
sleep 1
RUST_BACKTRACE=1 RUST_LOG=debug cargo test test_multiple_messages -- --nocapture
sleep 1
RUST_BACKTRACE=1 RUST_LOG=debug cargo test test_skip_invalid_event -- --nocapture
sleep 1
RUST_BACKTRACE=1 RUST_LOG=debug cargo test test_node_recovery -- --nocapture
sleep 1
RUST_BACKTRACE=1 RUST_LOG=debug cargo test test_join_group_then_handshake -- --nocapture
# RUST_BACKTRACE=1 RUST_LOG=debug cargo test test_deploy_post -- --nocapture
# sleep 1
# RUST_BACKTRACE=1 RUST_LOG=debug cargo test test_multiple_messages -- --nocapture
# sleep 1
# RUST_BACKTRACE=1 RUST_LOG=debug cargo test test_skip_invalid_event -- --nocapture
# sleep 1
# RUST_BACKTRACE=1 RUST_LOG=debug cargo test test_node_recovery -- --nocapture
# sleep 1
# RUST_BACKTRACE=1 RUST_LOG=debug cargo test test_join_group_then_handshake -- --nocapture

echo "Unit testing..."
cd ../../../scripts
Expand Down
Loading