smart contract storage struct 未初始化 直接使用問題

https://github.com/knownsec/Ethereum-Smart-Contracts-Security-CheckList/blob/master/%E4%BB%A5%E5%A4%AA%E5%9D%8A%E6%99%BA%E8%83%BD%E5%90%88%E7%BA%A6%E5%AE%A1%E8%AE%A1CheckList.md#11-%E6%9C%AA%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9A%84%E5%82%A8%E5%AD%98%E6%8C%87%E9%92%88 https://www.chaindd.com/3102377.html https://blog.b9lab.com/storage-pointers-in-solidity-7dcfaa536089 https://medium.com/loom-network/ethereum-solidity-memory-vs-storage-how-to-initialize-an-array-inside-a-struct-184baf6aa2eb Use delete or new

2019-09-26 · 1 min · 8 words · Me

web3 deploy smart contract 1.2.1

Use https://remix.ethereum.org Get Contract json and data. In remix website, Compile finish. See Compliation Details. 1. ABI: click ABI buttion, get data. Use http://jsonviewer.stack.hu/ remove space 2. Compliation Details -> WEB3DEPLOY -> get data 3. cContract.options.from need put correct. var Web3 = require("web3"); var provider = new Web3.providers.HttpProvider("http://ganache:8545"); var web3 = new Web3(provider); //abi var cContract = new web3.eth.Contract([{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]) //bytecode cContract.options.data = '0x608060405234801561001057600080fd5b5060bf8061001f6000396000f30060806040526004361060485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166360fe47b18114604d5780636d4ce63c146064575b600080fd5b348015605857600080fd5b5060626004356088565b005b348015606f57600080fd5b506076608d565b60408051918252519081900360200190f35b600055565b600054905600a165627a7a72305820765480c908e5e28e3233e18bfa422944b42cad5fc08b77d7b22d3ddd7016a1380029' cContract.options.from = '0xoooxxxoooxxxoooxxxoooxxxoooxxx' cContract.options.gas = '4700000' console.log("web3 version: %o", web3.version) web3.eth.getAccounts().then(o=>{console.log(o)}) cContract.deploy().send() .on('error', (error) => { console.log("error: %o", error) }) .on('transactionHash', (transactionHash) => { console.log("transactionHash: %o", transactionHash) }) .on('receipt', (receipt) => { // receipt will contain deployed contract address console.log("receipt: %o", receipt) console.log("receipt.contractAddress: %o", receipt.contractAddress) }) .on('confirmation', (confirmationNumber, receipt) => { console.log("confirmationNumber: %o", confirmationNumber) console.log("confirmation receipt: %o", receipt) }) .then(function(newContractInstance){ if (typeof newContractInstance.options.address !== 'undefined') { console.log('Contract mined! address: ' + newContractInstance.options.address); }else{ console.log("newContractInstance.address is undefined!") } });

2019-09-26 · 1 min · 141 words · Me

HDWalletProvider web3 smart contract connection need to stop or pool

HDWalletProvider engine.stop() p = HDWalletProvider(MNEMONIC_SYSTEM, "http://ganache:8545", 0); p.engine.stop(); HDWalletProvider engine.stop() and pool export function GetHdProvider(id: number, rpcurl: string) { //return new HDWalletProvider(MNEMONIC_SYSTEM, url, id); return id==0?Provider1Pool.acquire():Provider2Pool.acquire(); } // Normal use const hdProvider0 = await GetHdProvider(0, providerUrl).then(function(client) {return client}).catch(function(err) {throw new HttpException(err.toString(), HttpStatus.BAD_REQUEST);}); const hdProvider1 = await GetHdProvider(1, providerUrl).then(function(client) {return client}).catch(function(err) {throw new HttpException(err.toString(), HttpStatus.BAD_REQUEST);}); // Normal release ReleaseHDProvider1(hdProvider1 ); // Pool code const genericPool = require("generic-pool"); const opts = { max: 10, // maximum size of the pool min: 2, // minimum size of the pool idleTimeoutMillis: 30000, log: true }; const factory0 = { // maybe different parms create: function() { return new HDWalletProvider(MNEMONIC_SYSTEM, RPCURL, 0); }, destroy: function(client) { client.engine.stop(); } }; const factory1 = { // maybe different parms create: function() { return new HDWalletProvider(MNEMONIC_SYSTEM, RPCURL, 1); }, destroy: function(client) { client.engine.stop(); } }; export function ReleaseHDProvider1(client){ Provider1Pool.release(client); console.log("Provider1Pool status: pool.size %o pool.available %o pool.pending %o", Provider1Pool.size, Provider1Pool.available, Provider1Pool.pending) } export function ReleaseHDProvider2(client){ Provider2Pool.release(client); console.log("Provider2Pool status: pool.size %o pool.available %o pool.pending %o", Provider2Pool.size, Provider2Pool.available, Provider2Pool.pending) } const Provider1Pool = genericPool.createPool(factory0, opts); const Provider2Pool = genericPool.createPool(factory1, opts);

2019-09-25 · 1 min · 179 words · Me

solc abigen docker

sol file put in ~/contracts/sol File list ~/contracts/sol/Contracts.sol RUN docker run -v ~/contracts:/sources ethereum/solc:0.4.23 -o /sources --abi --bin /sources/sol/Contract.sol File list ~/contracts/sol/Contracts.sol ~/contracts/Contracts.abi ~/contracts/Contracts.bin 0.4.23 check your contract version. This example is pragma solidity ^0.4.23; sol name need be changeed. This example is Contract.sol Permission denied just use root RUN docker run -v ~/contracts:/sources ethereum/client-go:alltools-v1.9.2 abigen --abi /sources/Contract.abi --pkg contracts --type Contract --out /sources/Contract.go --bin /sources/Contract.bin File list ~/contracts/sol/Contracts.sol ~/contracts/Contracts.abi ~/contracts/Contracts.bin ~/contracts/Contracts.go ...

2019-09-03 · 1 min · 141 words · Me

go-eth

https://medium.com/taipei-ethereum-meetup/%E4%BD%BF%E7%94%A8-go-%E8%88%87%E4%BB%A5%E5%A4%AA%E5%9D%8A%E5%8D%80%E5%A1%8A%E9%8F%88%E4%BA%92%E5%8B%95-%E4%B8%89-7b7b1f40c06a https://github.com/sc0Vu/go-eth

2019-09-02 · 1 min · 2 words · Me

ethereum explorer etherchain light

https://github.com/gobitfly/etherchain-light

2019-08-29 · 1 min · word · Me

[轉]Web3.js vs Ethers.js

https://github.com/adrianmcli/web3-vs-ethers

2019-08-29 · 1 min · word · Me

ethereum sign verify ECDSA part 3 Final ethereumjs-util Elliptic secp256k1

https://medium.com/@antonassocareer/web3-secp256k1-%E7%B0%BD%E7%AB%A0%E8%88%87solidity%E9%A9%97%E7%AB%A0-26ded518cfdc phone vs secp256k1 vs ethereumjs-util 那代表 phone 產生的是符合ethereum的格式 但因為 signed的長度不符合標準的 secp256k1 ,所以只能用ethereumjs-util的工具,從fromRpcSig 匯入處理,取得 s r v ,後就能進行處理了! Elliptic 和 secp256k1 各別需要不同的方式,請閱code const secp256k1 = require('secp256k1') const ejsu = require('ethereumjs-util') Web3 = require("web3") var web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546'); // phone // private key // address 0xAD44A8ea9A9Bb5eF66F041BB921A687331729eB4 // Message Signature Has 0xa05ac71b16172777f683edbc48e9709cffd713a82630232d7c98e0f0df5201d60329658dba83b53fed49307e03d9663c0d2e4476c8b7925c2ed02cc7f881f5271b // Message Hello // public key 034e17dc4aef81e0ce6d16686be5e194274795375fc5525f1cdc46fe0b4643d5d6 console.log("\n----- phone -----\n") var buf_Signed = Buffer.from(web3.utils.hexToBytes("0xa05ac71b16172777f683edbc48e9709cffd713a82630232d7c98e0f0df5201d60329658dba83b53fed49307e03d9663c0d2e4476c8b7925c2ed02cc7f881f5271b")) var buf_pubkey = Buffer.from(web3.utils.hexToBytes("0x034e17dc4aef81e0ce6d16686be5e194274795375fc5525f1cdc46fe0b4643d5d6")) console.log("\x1b[32m Public Key: \x1b[0m %s \nlength: %s \n", web3.utils.bytesToHex(buf_pubkey), buf_pubkey.length) console.log("\x1b[32m singature: \x1b[0m %o \nlength: %s \n", buf_Signed, buf_Signed.length) // ethereumjs-util import signature fromRpcSig console.log("\n===== ethereumjs-util =====\n") var fromSigned = ejsu.fromRpcSig(buf_Signed) console.log("\x1b[32m fromSigned: %o \n", fromSigned) var message = "Hello" prefix = '\x19Ethereum Signed Message:\n' + message.length.toString() console.log("\x1b[32m prefix: \x1b[0m %s \n", prefix) var message2 = prefix + message var buf_msgHash2 = ejsu.keccak256(message2); // this is ok var buf_msgHash = Buffer.from(web3.utils.hexToBytes(web3.utils.soliditySha3(prefix, message))) var ecrecover_public_key = ejsu.ecrecover(buf_msgHash, fromSigned.v, fromSigned.r, fromSigned.s) console.log("\x1b[32m ecrecover_public_key: \x1b[0m %s \n", web3.utils.bytesToHex(ecrecover_public_key)) var address = ejsu.pubToAddress(ecrecover_public_key) console.log("\x1b[32m address: \x1b[0m %s \n", web3.utils.bytesToHex(address)) console.log("\x1b[32m toChecksumAddress address: \x1b[0m %s \n", ejsu.toChecksumAddress(web3.utils.bytesToHex(address))) console.log("\x1b[32m address is same address: \x1b[0m %s \n", ejsu.toChecksumAddress(web3.utils.bytesToHex(address)) == '0xAD44A8ea9A9Bb5eF66F041BB921A687331729eB4') // Elliptic console.log("\n===== Elliptic-util =====\n") var EC = require('elliptic').ec; var ec = new EC('secp256k1'); //var key = ec.genKeyPair(); var key = ec.keyFromPublic(buf_pubkey); // No Private Key //r s https://github.com/ethereumjs/ethereumjs-util/blob/599ba5b1c7043a7e155e6032c50d7a01fc63aaf1/src/signature.ts#L70 var r = buf_Signed.slice(0, 32); var s = buf_Signed.slice(32, 64); console.log("\x1b[32m Elliptic verify: \x1b[0m %s \n", key.verify(buf_msgHash, {r: r, s: s})); //secp256k1 console.log("\n===== secp256k1 =====\n") var DER_signature = secp256k1.signatureExport(buf_Signed.slice(0, 64)) var signature = secp256k1.signatureImport(DER_signature) console.log("\x1b[32m phone Signed -> DER Signed -> signatureImport: \x1b[0m %s \nlength: %s \n", web3.utils.bytesToHex(signature), signature.length) console.log("\x1b[32m secp256k1 verify: \x1b[0m %s \n", secp256k1.verify(buf_msgHash, signature, buf_pubkey)); console.log("\n----- phone End -----\n") // secp256k1 // private key random => 0x9fc00a13bf199dc5606da92d61438c680eeddec04f7a1833405c1466a81c9bd7 console.log("\n----- secp256k1 -----\n") var buf_PrivateKey = Buffer.from(web3.utils.hexToBytes('0x9fc00a13bf199dc5606da92d61438c680eeddec04f7a1833405c1466a81c9bd7')) var buf_PublicKey = secp256k1.publicKeyCreate(buf_PrivateKey) console.log("\x1b[32m Public Key: \x1b[0m %s \nlength: %s \n", web3.utils.bytesToHex(buf_PublicKey), buf_PublicKey.length) var buf_msg = Buffer.alloc(32, "Hello") var singature = secp256k1.sign(buf_msg, buf_PrivateKey) console.log("\x1b[32m singature: \x1b[0m %o \nlength: %s \n", singature, singature.signature.length) console.log("\x1b[32m singature: \x1b[0m %s \n", web3.utils.bytesToHex(singature.signature)) var recover_public_key = secp256k1.recover(buf_msg, singature.signature, singature.recovery) console.log("\x1b[32m Get Back Pubkey: \x1b[0m %s \n", web3.utils.bytesToHex(recover_public_key)) console.log("\x1b[32m recover_public_key is same PublicKey: \x1b[0m %s", web3.utils.bytesToHex(recover_public_key) == web3.utils.bytesToHex(buf_PublicKey)) console.log("\n----- secp256k1 End -----\n") // ganache // private key 0x75b25b96be4313c5a102bd4daa6bbeb71414f23e0ae15c0f93fa6d17866003da // addresss 0xf8d3A2033ebfc7778CD59f676235a8E431b6eeD7 console.log("\n----- ganache -----\n") // ganache part is OK var buf_PrivateKey = Buffer.from(web3.utils.hexToBytes('0x75b25b96be4313c5a102bd4daa6bbeb71414f23e0ae15c0f93fa6d17866003da')) var buf_PublicKey = ejsu.privateToPublic(buf_PrivateKey) var buf_Address = ejsu.privateToAddress(buf_PrivateKey) console.log("\x1b[32m Public Key: \x1b[0m %s \nlength: %s \n", web3.utils.bytesToHex(buf_PublicKey), buf_PublicKey.length) console.log("\x1b[32m Address: \x1b[0m %s \nlength: %s \n", web3.utils.bytesToHex(buf_Address), buf_Address.length) var message = "Hello" var buf_msgHash = ejsu.keccak256(message); var singature = ejsu.ecsign(buf_msgHash, buf_PrivateKey) console.log("\x1b[32m singature: \x1b[0m %o \n", singature) // have r s v var ecrecover_public_key = ejsu.ecrecover(buf_msgHash, singature.v, singature.r, singature.s) console.log("\x1b[32m ecrecover_public_key: \x1b[0m %s \n", web3.utils.bytesToHex(ecrecover_public_key)) console.log("\x1b[32m ecrecover_public_key is same PublicKey: \x1b[0m %s", web3.utils.bytesToHex(ecrecover_public_key) == web3.utils.bytesToHex(buf_PublicKey)) console.log("\n----- ganache End -----\n") Result ----- phone ----- Public Key: 0x034e17dc4aef81e0ce6d16686be5e194274795375fc5525f1cdc46fe0b4643d5d6 length: 33 singature: <Buffer a0 5a c7 1b 16 17 27 77 f6 83 ed bc 48 e9 70 9c ff d7 13 a8 26 30 23 2d 7c 98 e0 f0 df 52 01 d6 03 29 65 8d ba 83 b5 3f ed 49 30 7e 03 d9 66 3c 0d 2e ... > length: 65 ===== ethereumjs-util ===== fromSigned: { v: 27, r: <Buffer a0 5a c7 1b 16 17 27 77 f6 83 ed bc 48 e9 70 9c ff d7 13 a8 26 30 23 2d 7c 98 e0 f0 df 52 01 d6>, s: <Buffer 03 29 65 8d ba 83 b5 3f ed 49 30 7e 03 d9 66 3c 0d 2e 44 76 c8 b7 92 5c 2e d0 2c c7 f8 81 f5 27> } prefix: Ethereum Signed Message: 5 ecrecover_public_key: 0x4e17dc4aef81e0ce6d16686be5e194274795375fc5525f1cdc46fe0b4643d5d66dcc58b79553ea878b6b514b8bd2552090d0fc810bd6f9b4d585f4709f43ed41 address: 0xad44a8ea9a9bb5ef66f041bb921a687331729eb4 toChecksumAddress address: 0xAD44A8ea9A9Bb5eF66F041BB921A687331729eB4 address is same address: true ===== Elliptic-util ===== Elliptic verify: true ===== secp256k1 ===== phone Signed -> DER Signed -> signatureImport: 0xa05ac71b16172777f683edbc48e9709cffd713a82630232d7c98e0f0df5201d60329658dba83b53fed49307e03d9663c0d2e4476c8b7925c2ed02cc7f881f527 length: 64 secp256k1 verify: true ----- phone End ----- ----- secp256k1 ----- Public Key: 0x037ff17f569a94f4b91317a36b54dc9a77cdd6ce004a00821ca0ebc12acaa5188d length: 33 singature: { signature: <Buffer 79 a4 11 c0 85 bd 1a 2d 7b bd a5 eb 1e 19 d6 75 f1 40 07 27 f7 83 82 9f 1d f6 2a d2 86 3c 8a eb 62 04 03 78 64 96 f9 10 27 61 d0 ea 79 2b 40 65 d5 45 ... >, recovery: 1 } length: 64 singature: 0x79a411c085bd1a2d7bbda5eb1e19d675f1400727f783829f1df62ad2863c8aeb620403786496f9102761d0ea792b4065d545608d7905af427ffa2b181b103e28 Get Back Pubkey: 0x037ff17f569a94f4b91317a36b54dc9a77cdd6ce004a00821ca0ebc12acaa5188d recover_public_key is same PublicKey: true ----- secp256k1 End ----- ----- ganache ----- Public Key: 0xba5ca43c6d8c8ec41a0449ddc35dfee96afd0a112c4667b9d09925913799be627d1a779b6114c8541650c3b31bf88d360b1e3ebc973267003c7452fef6f2da2e length: 64 Address: 0xf8d3a2033ebfc7778cd59f676235a8e431b6eed7 length: 20 singature: { r: <Buffer b7 f7 ff 3c 78 8f 10 db e5 46 d4 10 2a 17 cd 99 1f d3 2c 5a c8 86 e9 31 83 bc 53 8d 5f 92 8f 81>, s: <Buffer 6d c1 0d 0e 71 42 73 f5 64 64 96 af d4 e1 3d 49 18 09 5f 42 27 e0 0b ae 1f 5a 59 ec af 39 fd e2>, v: 27 } ecrecover_public_key: 0xba5ca43c6d8c8ec41a0449ddc35dfee96afd0a112c4667b9d09925913799be627d1a779b6114c8541650c3b31bf88d360b1e3ebc973267003c7452fef6f2da2e ecrecover_public_key is same PublicKey: true ----- ganache End -----

2019-08-17 · 4 min · 820 words · Me

ethereum sign verify ECDSA part 2

Sure ethereum signature is 65, but secp256k1 is 64 RangeError: signature length is invalid Web3 = require("web3") var web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546'); const secp256k1 = require('secp256k1') // or require('secp256k1/elliptic') // if you want to use pure js implementation in node //ethereum test https://github.com/ethereum/go-ethereum/blob/461291882edce0ac4a28f64c4e8725b7f57cbeae/crypto/signature_test.go msg = web3.utils.hexToBytes("0xd301ce462d3e639518f482c7f03821fec1e602018630ce621e1e7851c12343a6") signature = web3.utils.hexToBytes("0x638a54215d80a6713c8d523a6adc4e6e73652d859103a36b700851cb0e61b66b8ebfc1a610c57d732ec6e0a8f06a9a7a28df5051ece514702ff9cdff0b11f454") pubkey = web3.utils.hexToBytes("0x03ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd3138") console.log(secp256k1.verify(msg, signature, pubKey))

2019-08-16 · 1 min · 57 words · Me

ethereum sign verify ECDSA part 1

呼叫web3的部份,都需要使用ethereum geth,這部份有點麻煩 Call web3 must use ethereum, this mean need to run ganache or geth. No ok. jsrsasign is offline to compute ECDSA 相關的是 https://kjur.github.io/jsrsasign/sample/sample-ecdsa.html ===== https://medium.com/@angellopozo/ethereum-signing-and-validating-13a2d7cb0ee3 https://dzone.com/articles/signing-and-verifying-ethereum-signatures public address 只是 verify後拿來驗證是否相同 另一句話 verify後會產生public address,主要是拿sign後的值產生 r s v ,然後再用 合約的功能 ecrecover 處理 public address only for after verify product check Other way to explain is After verify get public address. Take signatures to make r s v, then use r s v with contract ecrecover(). ecrecover() run finish get public address. ...

2019-08-16 · 2 min · 252 words · Me

[轉]用Go来做以太坊开发

https://github.com/miguelmota/ethereum-development-with-go-book https://goethereumbook.org/zh/

2019-07-29 · 1 min · 2 words · Me

ethereum explorer

https://github.com/gobitfly/etherchain-light https://github.com/gobitfly/erc20-explorer https://github.com/carsenk/explorer https://github.com/Capgemini-AIE/ethereum-docker/tree/master/monitored-geth-client https://github.com/cubedro/eth-net-intelligence-api https://github.com/cubedro/eth-netstats Browse blocks and transactions It’s nice to have some simple analogue of Etherscan for your local chain browsing. It will be useful to examine transactions, balances, blocks and etc. It appeared that it is quite difficult to find an open-source good solution for geth. After several tries I found an acceptable solution called ETHExplorer V2. Clone it into explorer-v2 folder. To Dockerize it I had to make 2 changes. First create a Dockerfile ...

2019-07-28 · 1 min · 150 words · Me

[轉]PoA private network clique: 😱 block lost

https://github.com/ethereum/go-ethereum/issues/18405 That’s generally fine. The way clique works is that the in-turn sealer who should ideally sign next tries to sign and propagate the block immediately when the timer ticks. If no in-turn block appears within 500ms, the other signers start potentially creating alternative blocks (with random delays), this ensures that even if a signer is missing, the chain progresses more or less properly. Now, if the original in-turn signer does come around and publish its block with some delay, that might reorg out alternative blocks signer by out-of-turn signers. At that point those will complain that their block was lost. The scary smiley is mostly meant for ethash :) Clique blocks have no subsidy anyway :) ...

2019-07-19 · 1 min · 117 words · Me

ethereum geth keystore -> private key -> address (check)

Use keythereum, web3 npm install keythereum npm install web3 .datadir need to correct. UTC/keystore/UTC–2019-03-25T09-10-35.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx .address need correct “0xooooooooooooooooooooooooo” .password need correct, this example is empty. .web3 localhost is fake, don’t need have geth. var keythereum = require("keythereum"); var datadir = "UTC"; var address= "0xooooooooooooooooooooooooo"; const password = ""; var keyObject = keythereum.importFromFile(address, datadir); var privateKey = keythereum.recover(password, keyObject); console.log(privateKey.toString('hex')); Web3 = require('web3') web3 = new Web3(new Web3.providers.HttpProvider("localhost")); var address = web3.eth.accounts.privateKeyToAccount("0x"+privateKey.toString('hex')); console.log(address);

2019-07-18 · 1 min · 72 words · Me

ethereum Solidity v0.5.0 Breaking Changes

https://solidity.readthedocs.io/en/v0.5.0/050-breaking-changes.html#example https://github.com/ethereum/solidity/blob/develop/Changelog.md

2019-07-16 · 1 min · 2 words · Me

[轉]以太坊智能合约Solidity 0.5.0版本重大变化

https://zhuanlan.zhihu.com/p/54169418 随着solidity 0.5.0 nightly build版本的稳步推进,正式版也将在不久的将来与开发者见面.作为一个大版本更新,新版引入了很多特性,也废弃了很多关键字,比如 .call()不仅可以获知远程调用执行成功与否,还将获得远程调用执行的返回值 ABI解码做了新的处理规范,有效防御了"短地址攻击" address地址类型细分成 address和 address payable uintY和 bytesX不能直接转换 回退函数必须显式声明为 external可见性 构造函数必须用 constructor关键字定义 用于抛出异常的 throw关键字弃用, 函数状态可变性修饰符必须用 view,不能混用 constant和 view … 下面我们将对这些改变一一予以介绍,最后给出一个示例代码,对比展示新旧版solidity代码写法的区别,供大家参考. 显式声明 函数可见性 函数可见性必须显式声明. 之前, 函数如果不显式声明,将默认 public可见性. public: constructor构造函数必须声明为 public可见性,否则编译报错. external: 回退函数(fallback function), 接口(interface)的函数必须声明为 external可见性,否则编译报错. 存储位置 结构体(struct),数组(array),映射(mapping)类型的变量必须显式声明存储位置( storage, memeory, calldata),包括函数参数和返回值变量都必须显式声明. external 的函数参数需显式声明为 calldata. 合约与地址 contract合约类型不再包括 address类型的成员函数,必须显式转换成 address地址类型才能使用 send(), transfer(), balance等与之相关的成员函数/变量成员. address地址类型细分为 address和 address payable,只有 address payable可以使用 transfer(), send()函数. address payable类型可以直接转换为 address类型, 反之不能. 但是 address x可以通过 address(uint160(x)),强制转换成 address payable类型. 如果 contract A不具有 payable的回退函数, 那么 address(A)是 address类型. 如果 contract A具有 payable的回退函数, 那么 address(A)是 address payable类型. msg.sender属于 address payable类型. 转换与填充(padding) uintY与 bytesX 因为填充(padding)的时候, bytesX是右填充(低比特位补0),而 uintY是左填充(高比特位补0),二者直接转换可能会导致不符合预期的结果,所以现在当 bytesX和 uintY长度大小不一致(即X*8 != Y)时,不能直接转换,必须先转换到相同长度,再转换到相同类型. 10进制数值不能直接转换成 bytesX类型, 必须先转换到与 bytesX相同长度的 uintY,再转换到 bytesX类型 16进制数值如果长度与 bytesX不相等,也不能直接转换成 byteX类型 ABI 字面值必须显式转换成类型才能使用 abi.encodePacked() ABI编码器在构造外部函数入参和 abi.encode()会恰当地处理 bytes和 string类型的填充(padding),若不需要进行填充,请使用 abi.encodePacked() ABI解码器在解析函数入参和 abi.decode()时,如果发现 calldata太短或超长,将直接抛出异常,而不是像之前自动填充(补0)和截断处理,从而有效地遏制了短地址攻击. .call()族函数( .call(), .delegatecall(), .staticcall())和 哈希函数( keccak256(), sha256(), ripemd160())只接受一个参数 bytes,且不进行填充(padding)处理. .call()空参数必须写成 .call("") .call(sig,a,b,c)必须写成 .call(abi.encodeWithSignature(sig,a,b,c)),其他类推 keccak256(a,b,c)必须写成 keccak256(abi.encodePacked(a,b,c)),其他类推 另外, .call()族函数之前只返回函数执行成功是否的 bool, 现在还返回函数执行的返回值,即 (bool,bytes memory). 所以之前 boolresult=.call(sig,a,b,c)现在必须写成 (boolresult,bytes memory data)=.call(sig,a,b,c). 不允许的写法 在之前版本的solidity编译,以下不允许的写法只会导致 warnings报警,现在将直接 errors报错. ...

2019-07-16 · 3 min · 563 words · Me

etherniti swagger

https://www.etherniti.org/blog/development/swagger/ http://dev.proxy.etherniti.org/swagger/

2019-07-13 · 1 min · 2 words · Me

[轉]nodejs vs golang Web3 Performance comparison

https://docs.etherniti.org/architecture/benchmarks/performance_test/

2019-07-13 · 1 min · word · Me

golang ethereum address regexp check

https://docs.etherniti.org/architecture/optimizations/address-validation/ package main import ( "fmt" "regexp" ) var ( re := regexp.MustCompile("^0x[0-9a-fA-F]{40}$") ) func IsValidAddress(v string) bool { return re.MatchString(v) } func main() { fmt.Println(IsValidAddress("0x323b5d4c32345ced77393b3530b1eed0f346429d")) // true fmt.Println(IsValidAddress("0xXYZb5d4c32345ced77393b3530b1eed0f346429d")) // false }

2019-07-13 · 1 min · 32 words · Me

geth poa ethereum 出塊 時間間隔

創世區塊 g 30 seconds “period”: 30, why-ethereum-transfers-are-so-slow-how-fix https://born2invest.com/articles/why-ethereum-transfers-are-so-slow-how-fix/ Slow and steady Ethereum only processes 10 to 15 transactions per second, in large part because all nodes are required to help process all transactions made through the database. By comparison, a credit card company like Visa can process around 45,000 transactions per second.

2019-07-03 · 1 min · 52 words · Me