Skip to content

Instantly share code, notes, and snippets.

View CHAOWEICHIU's full-sized avatar
🎯
Focusing

Wayne Chiu CHAOWEICHIU

🎯
Focusing
View GitHub Profile
@CHAOWEICHIU
CHAOWEICHIU / uploadEncryptedZipFile.js
Last active March 7, 2019 23:45
implementation for storing encrypted zip file on the blockchain - 1/2 encrypt and upload
const IpfsHttpClient = require('ipfs-http-client')
const EthCrypto = require('eth-crypto')
const intoStream = require('into-stream')
const ipfs = IpfsHttpClient({
host: 'ipfs.infura.io',
port: '5001',
protocol: 'https',
})
@CHAOWEICHIU
CHAOWEICHIU / message_encrypt_decrypt_for_blockchain.js
Last active February 28, 2019 01:12
encrypt and decrypt message with public key and private key
/*
Requirement
--------------
node: v8.10.0
npm: v5.6.0
--------------
npm installation
-----------------------
@CHAOWEICHIU
CHAOWEICHIU / privateKey_to_publicKey_to_address.js
Created February 27, 2019 23:42
use private to get public key and wallet address
/*
Requirement
--------------
node: v8.10.0
npm: v5.6.0
--------------
npm installation
/*
Contract source: https://github.com/dexon-foundation/hello-dexon/blob/master/contracts/Hello.sol
Deployed Contract address: 0xFF24A07D64C2c6E5e3309028828836099968c6A4
Method: get()
curl -X POST --data '{"jsonrpc": "2.0", "method": "eth_call", "params": [{"to": "0xa66dd3a9905a71e67006dfaa0aa82a302f247014", "data": "0x..."}, "latest"], "id": 1 }' http://testnet.dexon.org:8545 -H 'Content-Type: application/json'
*/
const Web3 = require('web3')
@CHAOWEICHIU
CHAOWEICHIU / rpc.js
Last active January 31, 2019 03:15
The comparison of using RPC call and Web3.js in order to get balance for target wallet address
/*
RPC Call
curl -X POST --data \
'{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x8ECedB018bDdf5bC05C756cA6ED67dbad208CAFf", "latest"],"id":1}' \
http://testnet.dexon.org:8545 \
-H 'Content-Type: application/json'
RPC Response
{"jsonrpc":"2.0","id":1,"result":"0x360b405b6db5ac3000"}
@CHAOWEICHIU
CHAOWEICHIU / 04_Manipulate_Lottery_Outcome.sol
Created January 27, 2019 23:44
Solidity Smart Contract Vulnerability
pragma solidity ^0.5.0;
contract Lottery {
address[] public losers;
address[] public winnners;
function imaginaryTruelyRandomNumber() public view returns (uint256) {
return block.timestamp;
}
@CHAOWEICHIU
CHAOWEICHIU / derivation_path.js
Last active January 27, 2019 01:11
BIP39 - mnemonic - demo how derivation path works
const HDWalletProvider = require("truffle-hdwallet-provider")
const mnemonic = 'pretty runway design riot organ cloud skate able tide frozen lunar awesome'
const provider237 = new HDWalletProvider(
mnemonic,
"http://testnet.dexon.org:8545",
0,
1,
true,
"m/44'/237'/0'/0/", /* For DEXON Network */
@CHAOWEICHIU
CHAOWEICHIU / 04_Math_Division.sol
Created January 25, 2019 02:10
Solidity Smart Contract Vulnerability
pragma solidity ^0.5.0;
contract FloatingInSolidity {
address payable public Owner;
constructor() public {
Owner = msg.sender;
}
@CHAOWEICHIU
CHAOWEICHIU / 03_Useless_Ownership.sol
Last active January 23, 2019 00:58
Solidity Smart Contract Vulnerability
pragma solidity ^0.5.0;
contract Owned {
address payable public owner;
constructor() public {
owner = msg.sender;
}
modifier onlyOwner{ if (msg.sender != owner) revert(); _; }
}
@CHAOWEICHIU
CHAOWEICHIU / 02_Unfair_Equation.sol
Created January 22, 2019 21:39
Solidity Smart Contract Vulnerability
pragma solidity ^0.5.0;
contract MultiplicatorX3 {
address payable public Owner;
constructor() public {
Owner = msg.sender;
}
function withdraw() payable public {