git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 69097f452f01a61429f16530219f9f1dc548b8d3

move things around

wanderer committed on 10/27/2016, 1:54:50 PM
Parent: 5626d2b938fbe2739a9576eb4bf4a2bdced83d13

Files changed

environment.jschanged
index.jschanged
interface.jschanged
address.jsdeleted
block.jsdeleted
deps/address.jsadded
deps/block.jsadded
deps/transaction.jsadded
deps/u256.jsadded
deps/utils.jsadded
transaction.jsdeleted
u256.jsdeleted
utils.jsdeleted
environment.jsView
@@ -1,7 +1,7 @@
1-const U256 = require('./u256.js')
2-const Address = require('./address.js')
3-const Block = require('./block.js')
1+const U256 = require('./deps/u256.js')
2+const Address = require('./deps/address.js')
3+const Block = require('./deps/block.js')
44 const fakeBlockChain = require('./fakeBlockChain.js')
55
66 module.exports = class Environment {
77 constructor (data) {
index.jsView
@@ -18,12 +18,12 @@
1818 // The Kernel Stores all of its state in the Environment. The Interface is used
1919 // to by the VM to retrive infromation from the Environment.
2020 const Environment = require('./environment.js')
2121 const DebugInterface = require('./debugInterface.js')
22-const Address = require('./address.js')
23-const U256 = require('./u256.js')
24-const Utils = require('./utils.js')
25-const Transaction = require('./transaction.js')
22+const Address = require('./deps/address.js')
23+const U256 = require('./deps/u256.js')
24+const Utils = require('./deps/utils.js')
25+const Transaction = require('./deps/transaction.js')
2626 const Precompile = require('./precompile.js')
2727
2828 const identityContract = new Address('0x0000000000000000000000000000000000000004')
2929 const meteringContract = new Address('0x000000000000000000000000000000000000000A')
interface.jsView
@@ -1,10 +1,10 @@
11 /**
22 * This is the Ethereum interface that is exposed to the WASM instance which
33 * enables to interact with the Ethereum Environment
44 */
5-const Address = require('./address.js')
6-const U256 = require('./u256.js')
5+const Address = require('./deps/address.js')
6+const U256 = require('./deps/u256.js')
77 const fs = require('fs')
88 const path = require('path')
99
1010 const U128_SIZE_BYTES = 16
@@ -498,12 +498,15 @@
498498 * from Memory
499499 * @param {interger} pathOffest the memory offset to load the the path from
500500 * @param {interger} valueOffset the memory offset to load the value from
501501 */
502- storageStore (pathOffset, valueOffset) {
502+ storageStore (pathOffset, valueOffset, cbDest) {
503+ console.log('sstore');
503504 const path = new Buffer(this.getMemory(pathOffset, U256_SIZE_BYTES)).toString('hex')
504505 // copy the value
505506 const value = this.getMemory(valueOffset, U256_SIZE_BYTES).slice(0)
507+ console.log('value:' + value)
508+ console.log('path:' + path)
506509 const oldValue = this.environment.state.get(path)
507510 const valIsZero = value.every((i) => i === 0)
508511
509512 this.takeGas(5000)
@@ -519,21 +522,30 @@
519522 this.environment.state.delete(path)
520523 } else {
521524 this.environment.state.set(path, value)
522525 }
526+
527+ setTimeout(() => {
528+ this.module.exports['0']()
529+ }, 0)
523530 }
524531
525532 /**
526533 * reterives a value at a given path in long term storage
527534 * @param {interger} pathOffest the memory offset to load the the path from
528535 * @param {interger} resultOffset the memory offset to load the value from
529536 */
530- storageLoad (pathOffset, resultOffset) {
537+ storageLoad (pathOffset, resultOffset, cbDest) {
538+ console.log('sload');
531539 this.takeGas(50)
532540
533541 const path = new Buffer(this.getMemory(pathOffset, U256_SIZE_BYTES)).toString('hex')
542+ console.log(path);
534543 const result = this.environment.state.get(path) || new Uint8Array(32)
535544 this.setMemory(resultOffset, U256_SIZE_BYTES, result)
545+ setTimeout(() => {
546+ this.module.exports['0']()
547+ }, 0)
536548 }
537549
538550 /**
539551 * Halt execution returning output data.
address.jsView
@@ -1,42 +1,0 @@
1-const BN = require('bn.js')
2-const U256 = require('./u256.js')
3-
4-module.exports = class Address extends U256 {
5- constructor (value) {
6- super(value)
7- if (this._value.byteLength() > 20) {
8- throw new Error('Invalid address length: ' + this._value.byteLength() + ' for ' + value)
9- }
10- }
11-
12- // This assumes Uint8Array in LSB (WASM code)
13- static fromMemory (value) {
14- return new Address(new BN(value, 16, 'le'))
15- }
16-
17- // This assumes Uint8Array in LSB (WASM code)
18- toMemory () {
19- return this._value.toBuffer('le', 20)
20- }
21-
22- toBuffer () {
23- return super.toBuffer(20)
24- }
25-
26- // Needs to be displayed as a hex always
27- toString () {
28- return '0x' + this._value.toString('hex', 40)
29- }
30-
31- static zero () {
32- return new Address('0x0000000000000000000000000000000000000000')
33- }
34-
35- isZero () {
36- return this._value.isZero()
37- }
38-
39- equals (address) {
40- return this.toString() === address.toString()
41- }
42-}
block.jsView
@@ -1,31 +1,0 @@
1-//
2-// This class parses a serialised Ethereum Block
3-//
4-// The input is a Buffer.
5-//
6-const Address = require('./address.js')
7-const ethUtil = require('ethereumjs-util')
8-const OldBlock = require('ethereumjs-block')
9-const U256 = require('./u256.js')
10-
11-module.exports = class Block extends OldBlock {
12- get number () {
13- return ethUtil.bufferToInt(this.header.number)
14- }
15-
16- get gasLimit () {
17- return ethUtil.bufferToInt(this.header.gasLimit)
18- }
19-
20- get difficulty () {
21- return new U256(this.header.difficulty)
22- }
23-
24- get timestamp () {
25- return ethUtil.bufferToInt(this.header.timestamp)
26- }
27-
28- get coinbase () {
29- return new Address(this.header.coinbase)
30- }
31-}
deps/address.jsView
@@ -1,0 +1,42 @@
1+const BN = require('bn.js')
2+const U256 = require('./u256.js')
3+
4+module.exports = class Address extends U256 {
5+ constructor (value) {
6+ super(value)
7+ if (this._value.byteLength() > 20) {
8+ throw new Error('Invalid address length: ' + this._value.byteLength() + ' for ' + value)
9+ }
10+ }
11+
12+ // This assumes Uint8Array in LSB (WASM code)
13+ static fromMemory (value) {
14+ return new Address(new BN(value, 16, 'le'))
15+ }
16+
17+ // This assumes Uint8Array in LSB (WASM code)
18+ toMemory () {
19+ return this._value.toBuffer('le', 20)
20+ }
21+
22+ toBuffer () {
23+ return super.toBuffer(20)
24+ }
25+
26+ // Needs to be displayed as a hex always
27+ toString () {
28+ return '0x' + this._value.toString('hex', 40)
29+ }
30+
31+ static zero () {
32+ return new Address('0x0000000000000000000000000000000000000000')
33+ }
34+
35+ isZero () {
36+ return this._value.isZero()
37+ }
38+
39+ equals (address) {
40+ return this.toString() === address.toString()
41+ }
42+}
deps/block.jsView
@@ -1,0 +1,31 @@
1+//
2+// This class parses a serialised Ethereum Block
3+//
4+// The input is a Buffer.
5+//
6+const Address = require('./address.js')
7+const ethUtil = require('ethereumjs-util')
8+const OldBlock = require('ethereumjs-block')
9+const U256 = require('./u256.js')
10+
11+module.exports = class Block extends OldBlock {
12+ get number () {
13+ return ethUtil.bufferToInt(this.header.number)
14+ }
15+
16+ get gasLimit () {
17+ return ethUtil.bufferToInt(this.header.gasLimit)
18+ }
19+
20+ get difficulty () {
21+ return new U256(this.header.difficulty)
22+ }
23+
24+ get timestamp () {
25+ return ethUtil.bufferToInt(this.header.timestamp)
26+ }
27+
28+ get coinbase () {
29+ return new Address(this.header.coinbase)
30+ }
31+}
deps/transaction.jsView
@@ -1,0 +1,49 @@
1+//
2+// This class parses a serialised Ethereum transaction
3+//
4+// The input is a Buffer.
5+//
6+const Address = require('./address.js')
7+const U256 = require('./u256.js')
8+const OldTx = require('ethereumjs-tx')
9+
10+module.exports = class Transaction {
11+ constructor (tx) {
12+ this._tx = new OldTx(tx)
13+ }
14+
15+ get valid () {
16+ return this._tx.verifySignature()
17+ }
18+
19+ get nonce () {
20+ return new U256(this._tx.nonce)
21+ }
22+
23+ get gasPrice () {
24+ return new U256(this._tx.gasPrice)
25+ }
26+
27+ get gasLimit () {
28+ return new U256(this._tx.gasLimit)
29+ }
30+
31+ get value () {
32+ return new U256(this._tx.value)
33+ }
34+
35+ get data () {
36+ return Uint8Array.from(this._tx.data)
37+ }
38+
39+ get from () {
40+ return new Address(this._tx.getSenderAddress())
41+ }
42+
43+ get to () {
44+ if (this._tx.to.length === 0) {
45+ return new Address('0x0000000000000000000000000000000000000000')
46+ }
47+ return new Address(this._tx.to)
48+ }
49+}
deps/u256.jsView
@@ -1,0 +1,65 @@
1+const BN = require('bn.js')
2+const ethUtil = require('ethereumjs-util')
3+
4+module.exports = class U256 {
5+ constructor (value) {
6+ // bn.js still doesn't support hex prefixes...
7+ if ((typeof value === 'string') && ethUtil.isHexPrefixed(value)) {
8+ this._value = new BN(ethUtil.stripHexPrefix(value), 16)
9+ } else {
10+ this._value = new BN(value, 10)
11+ }
12+ }
13+
14+ // This assumes Uint8Array in LSB (WASM code)
15+ static fromMemory (value) {
16+ return new U256(new BN(value, 16, 'le'))
17+ }
18+
19+ // This assumes Uint8Array in LSB (WASM code)
20+ toMemory (width) {
21+ return this._value.toBuffer('le', width || 32)
22+ }
23+
24+ toString (radix = 10) {
25+ if (radix === 16) {
26+ return '0x' + this._value.toString(16)
27+ }
28+ return this._value.toString(radix)
29+ }
30+
31+ toBuffer (width) {
32+ if (width <= 0 || width > 32) {
33+ throw new Error('Invalid U256 width')
34+ }
35+ return this._value.toBuffer('be', width || 32)
36+ }
37+
38+ isZero () {
39+ return this._value.isZero()
40+ }
41+
42+ sub (u256) {
43+ return new U256(this._value.sub(u256._value))
44+ }
45+
46+ add (u256) {
47+ return new U256(this._value.add(u256._value))
48+ }
49+
50+ mul (u256) {
51+ return new U256(this._value.mul(u256._value))
52+ }
53+
54+ div (u256) {
55+ return new U256(this._value.div(u256._value))
56+ }
57+
58+ lt (u256) {
59+ return this._value.lt(u256._value)
60+ }
61+
62+ gt (u256) {
63+ return this._value.gt(u256._value)
64+ }
65+}
deps/utils.jsView
@@ -1,0 +1,14 @@
1+const ethUtil = require('ethereumjs-util')
2+const Address = require('./address.js')
3+
4+var Utils = {}
5+
6+Utils.isWASMCode = function (code) {
7+ return code.slice(0, 4).toString() === new Uint8Array([0, 0x61, 0x73, 0x6d]).toString()
8+}
9+
10+Utils.newAccountAddress = function (sender, data) {
11+ return new Address('0x' + ethUtil.sha3(Buffer.concat([ sender.toBuffer(), Buffer.from(data) ])).slice(0, 20).toString('hex'))
12+}
13+
14+module.exports = Utils
transaction.jsView
@@ -1,49 +1,0 @@
1-//
2-// This class parses a serialised Ethereum transaction
3-//
4-// The input is a Buffer.
5-//
6-const Address = require('./address.js')
7-const U256 = require('./u256.js')
8-const OldTx = require('ethereumjs-tx')
9-
10-module.exports = class Transaction {
11- constructor (tx) {
12- this._tx = new OldTx(tx)
13- }
14-
15- get valid () {
16- return this._tx.verifySignature()
17- }
18-
19- get nonce () {
20- return new U256(this._tx.nonce)
21- }
22-
23- get gasPrice () {
24- return new U256(this._tx.gasPrice)
25- }
26-
27- get gasLimit () {
28- return new U256(this._tx.gasLimit)
29- }
30-
31- get value () {
32- return new U256(this._tx.value)
33- }
34-
35- get data () {
36- return Uint8Array.from(this._tx.data)
37- }
38-
39- get from () {
40- return new Address(this._tx.getSenderAddress())
41- }
42-
43- get to () {
44- if (this._tx.to.length === 0) {
45- return new Address('0x0000000000000000000000000000000000000000')
46- }
47- return new Address(this._tx.to)
48- }
49-}
u256.jsView
@@ -1,65 +1,0 @@
1-const BN = require('bn.js')
2-const ethUtil = require('ethereumjs-util')
3-
4-module.exports = class U256 {
5- constructor (value) {
6- // bn.js still doesn't support hex prefixes...
7- if ((typeof value === 'string') && ethUtil.isHexPrefixed(value)) {
8- this._value = new BN(ethUtil.stripHexPrefix(value), 16)
9- } else {
10- this._value = new BN(value, 10)
11- }
12- }
13-
14- // This assumes Uint8Array in LSB (WASM code)
15- static fromMemory (value) {
16- return new U256(new BN(value, 16, 'le'))
17- }
18-
19- // This assumes Uint8Array in LSB (WASM code)
20- toMemory (width) {
21- return this._value.toBuffer('le', width || 32)
22- }
23-
24- toString (radix = 10) {
25- if (radix === 16) {
26- return '0x' + this._value.toString(16)
27- }
28- return this._value.toString(radix)
29- }
30-
31- toBuffer (width) {
32- if (width <= 0 || width > 32) {
33- throw new Error('Invalid U256 width')
34- }
35- return this._value.toBuffer('be', width || 32)
36- }
37-
38- isZero () {
39- return this._value.isZero()
40- }
41-
42- sub (u256) {
43- return new U256(this._value.sub(u256._value))
44- }
45-
46- add (u256) {
47- return new U256(this._value.add(u256._value))
48- }
49-
50- mul (u256) {
51- return new U256(this._value.mul(u256._value))
52- }
53-
54- div (u256) {
55- return new U256(this._value.div(u256._value))
56- }
57-
58- lt (u256) {
59- return this._value.lt(u256._value)
60- }
61-
62- gt (u256) {
63- return this._value.gt(u256._value)
64- }
65-}
utils.jsView
@@ -1,14 +1,0 @@
1-const ethUtil = require('ethereumjs-util')
2-const Address = require('./address.js')
3-
4-var Utils = {}
5-
6-Utils.isWASMCode = function (code) {
7- return code.slice(0, 4).toString() === new Uint8Array([0, 0x61, 0x73, 0x6d]).toString()
8-}
9-
10-Utils.newAccountAddress = function (sender, data) {
11- return new Address('0x' + ethUtil.sha3(Buffer.concat([ sender.toBuffer(), Buffer.from(data) ])).slice(0, 20).toString('hex'))
12-}
13-
14-module.exports = Utils

Built with git-ssb-web