Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Feature/sha256 #240

Merged
merged 27 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c650e6c
0.3.26
Roaring30s Oct 20, 2023
fcb10b1
:mag: Experiment Sub Opcodes with Base 16
Roaring30s Oct 21, 2023
de0373e
:wrench: Fix CodeCopy Opcode
Roaring30s Oct 24, 2023
dfc9643
:hammer: Add SHL Opcode
Roaring30s Oct 24, 2023
63f6e21
:hammer: Add peek_step Function to Machine
Roaring30s Oct 24, 2023
dc1a110
:wrench: Remove CodeCopy Opcode Pop
Roaring30s Oct 24, 2023
6f25e7f
:wrench: Fix NOT Opcode
Roaring30s Oct 24, 2023
a5acbd7
:wrench: Fix ADD and MUL Opcodes
Roaring30s Oct 24, 2023
c2aa68f
:wrench: Fix DIV Opcode
Roaring30s Oct 24, 2023
12e491e
:mag: Inspect CALLER opcode
Roaring30s Oct 24, 2023
e15f1c9
docs: add opcodes
charmful0x Oct 25, 2023
ee48719
:hammer: Add get_window_data function
Roaring30s Oct 26, 2023
319c892
:hammer: Add Padding to Memory
Roaring30s Oct 26, 2023
84a24b4
:hammer: Add filter_left_zeros Function
Roaring30s Oct 26, 2023
8ae1092
:wrench: Fix MLOAD Opcode
Roaring30s Oct 26, 2023
7fa480f
:hammer: Add Test
Roaring30s Oct 27, 2023
6403d6d
Merge branch 'main' of https://github.com/Roaring30s/3em
Roaring30s Oct 27, 2023
3dd532d
:wrench: Fix CODECOPY Opcode
Roaring30s Oct 27, 2023
ced6d7f
:wrench: Fix COPYCODE Opcode Memory Allocation
Roaring30s Oct 28, 2023
32f083a
:hammer: Add EXM SHA256 Function
Roaring30s Nov 29, 2023
e046651
:wrench: Employ Cargo Fmt
Roaring30s Nov 29, 2023
b11c172
Merge branch 'main' of https://github.com/three-em/3em into feature/s…
Roaring30s Nov 29, 2023
bc3d5d1
:wrench: Retest
Roaring30s Nov 29, 2023
457f349
:hammer: Create SmartWeave convertString Function
Roaring30s Dec 11, 2023
74e156d
:hammer: Build convertTo Function for Smartweave
Roaring30s Dec 11, 2023
8dde212
:mag: Inspect CI Test
Roaring30s Dec 11, 2023
d87fa0d
:hammer: Run Cargo FMT
Roaring30s Dec 11, 2023
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
191 changes: 155 additions & 36 deletions crates/evm/lib.rs

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions crates/exm/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@
testDelKv() {
return this.kv;
}

async sha256(buffer) {
return subtle.digest('SHA-256', buffer).then((hashBuffer) => {
const hashArray = Array.from(new Uint8Array(hashBuffer));
Expand All @@ -248,7 +247,6 @@
return hashHex;
});
}

}

const ExmSymbol = Symbol('exm');
Expand Down
15 changes: 15 additions & 0 deletions crates/smartweave/smartweave.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,21 @@
};
}

get convertString() {
return {
async toSHA256(input) {
const encoder = new TextEncoder();
const data = encoder.encode(input);
const hashBuffer = await globalThis.SmartWeave.arweave.crypto.hash(data);
const hashArray = Array.from(hashBuffer);
const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join('');

return hashHex;

}
}
}

get unsafeClient() {
const txGetData = async (txId, opts) => {
try {
Expand Down
50 changes: 50 additions & 0 deletions docs/opcodes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

## List of the supported and tested 3EM EVM opcodes:

| opcodes | status |
|:---------:|:--------:|
| `CallValue` | ✅ |
| `Dup1` | ✅ |
| `IsZero` | ✅ |
| `Push3` | ✅ |
| `JumpI` | ✅ |
| `JumpDest` | ✅ |
| `Pop` | ✅ |
| `Push1` | ✅ |
| `MLoad` | ✅ |
| `CodeSize` | ✅ |
| `Sub` | ✅ |
| `CodeCopy` | ✅ |
| `Dup2` | ✅ |
| `Add` | ✅ |
| `MStore` | ✅ |
| `Swap1` | ✅ |
| `Swap2` | ✅ |
| `Jump` | ✅ |
| `Push0` | ✅ |
| `Dup3` | ✅ |
| `Dup5` | ✅ |
| `SLt` | ✅ |
| `Dup6` | ✅ |
| `Eq` | ✅ |
| `Swap3` | ✅ |
| `Push32` | ✅ |
| `Push8` | ✅ |
| `Gt` | ✅ |
| `SLoad` | ✅ |
| `Div` | ✅ |
| `And` | ✅ |
| `Lt` | ✅ |
| `Dup4` | ✅ |
| `Dup8` | ✅ |
| `Not` | ✅ |
| `Mul` | ✅ |
| `Shr` | ✅ |
| `Or` | ✅ |
| `Dup7` | ✅ |
| `SStore` | ✅ |
| `Caller` | ✅ |
| `Shl` | ✅ |
| `Push20` | ✅ |
| `Revert` | ✅ |
| `Mload` | ✅ |
45 changes: 41 additions & 4 deletions js/napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ mod tests {

let contract_result = contract.state;
let str_state = contract_result.to_string();
//println!("STATUS::::: {:#?}", str_state.contains("wearemintingyes"));
assert!(str_state.contains("wearemintingyes"));

}
Expand Down Expand Up @@ -753,16 +754,52 @@ mod tests {
};

let contract = simulate_contract(execution_context).await.unwrap();
//println!("{}", contract.exm_context);
//println!("{}", contract.result);
assert_eq!(contract.result, "[\"Yangtze\",\"Amazon\"]");
}


#[tokio::test]
pub async fn simulate_sha256() {
let contract_source_bytes =
include_bytes!("../../../testdata/contracts/sha256.js");
let contract_source_vec = contract_source_bytes.to_vec();
let execution_context: SimulateExecutionContext =
SimulateExecutionContext {
contract_id: String::new(),
interactions: vec![SimulateInput {
id: String::from("abcd"),
owner: String::from("210392sdaspd-asdm-asd_sa0d1293-lc"),
quantity: String::from("12301"),
reward: String::from("12931293"),
target: None,
tags: vec![],
block: None,
input: serde_json::json!({
"act": "1",
})
.to_string(),
}],
contract_init_state: Some(r#"{}"#.into()),
maybe_config: None,
maybe_cache: Some(false),
maybe_bundled_contract: None,
maybe_settings: None,
maybe_exm_context: Some(r#"{"requests": {}, "kv": {}, "initiated":[]}"#.into()),
maybe_contract_source: Some(ContractSource {
contract_src: contract_source_vec.into(),
contract_type: SimulateContractType::JAVASCRIPT,
}),
};

let contract = simulate_contract(execution_context).await.unwrap();
const hello_hash: &str = "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824";
assert_eq!(contract.state[0], hello_hash);
}

#[tokio::test]
pub async fn simulate_kv_get() {
let contract_source_bytes =
include_bytes!("../../../testdata/contracts/getKv.js");

let contract_source_vec = contract_source_bytes.to_vec();
let execution_context: SimulateExecutionContext =
SimulateExecutionContext {
Expand Down
8 changes: 8 additions & 0 deletions testdata/contracts/sha256.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export async function handle(state, action) {
try {
const someSha = await SmartWeave.convertString.toSHA256("hello");
return { state: [someSha] };
} catch(e) {
return { state: e.toString() }
}
}
Loading