本文整理汇总了Golang中github.com/ethereum/go-ethereum/common.Bytes2Big函数的典型用法代码示例。如果您正苦于以下问题:Golang Bytes2Big函数的具体用法?Golang Bytes2Big怎么用?Golang Bytes2Big使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Bytes2Big函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ecrecoverFunc
func ecrecoverFunc(in []byte) []byte {
in = common.RightPadBytes(in, 128)
// "in" is (hash, v, r, s), each 32 bytes
// but for ecrecover we want (r, s, v)
r := common.BytesToBig(in[64:96])
s := common.BytesToBig(in[96:128])
// Treat V as a 256bit integer
vbig := common.Bytes2Big(in[32:64])
v := byte(vbig.Uint64())
if !crypto.ValidateSignatureValues(v, r, s) {
glog.V(logger.Error).Infof("EC RECOVER FAIL: v, r or s value invalid")
return nil
}
// v needs to be at the end and normalized for libsecp256k1
vbignormal := new(big.Int).Sub(vbig, big.NewInt(27))
vnormal := byte(vbignormal.Uint64())
rsv := append(in[64:128], vnormal)
pubKey, err := crypto.Ecrecover(in[:32], rsv)
// make sure the public key is a valid one
if err != nil {
glog.V(logger.Error).Infof("EC RECOVER FAIL: ", err)
return nil
}
// the first byte of pubkey is bitcoin heritage
return common.LeftPadBytes(crypto.Sha3(pubKey[1:])[12:], 32)
}
开发者ID:ssonneborn22,项目名称:go-ethereum,代码行数:30,代码来源:contracts.go
示例2: makePush
// make push instruction function
func makePush(size uint64, bsize *big.Int) instrFn {
return func(instr instruction, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) {
byts := getData(contract.Code, new(big.Int).SetUint64(*pc+1), bsize)
stack.push(common.Bytes2Big(byts))
*pc += size
}
}
开发者ID:obscuren,项目名称:etherapis,代码行数:8,代码来源:instructions.go
示例3: ecrecoverFunc
func ecrecoverFunc(in []byte) []byte {
// "in" is (hash, v, r, s), each 32 bytes
// but for ecrecover we want (r, s, v)
if len(in) < ecRecoverInputLength {
return nil
}
// Treat V as a 256bit integer
v := new(big.Int).Sub(common.Bytes2Big(in[32:64]), big.NewInt(27))
// Ethereum requires V to be either 0 or 1 => (27 || 28)
if !(v.Cmp(Zero) == 0 || v.Cmp(One) == 0) {
return nil
}
// v needs to be moved to the end
rsv := append(in[64:128], byte(v.Uint64()))
pubKey, err := crypto.Ecrecover(in[:32], rsv)
// make sure the public key is a valid one
if err != nil {
glog.V(logger.Error).Infof("EC RECOVER FAIL: ", err)
return nil
}
// the first byte of pubkey is bitcoin heritage
return common.LeftPadBytes(crypto.Sha3(pubKey[1:])[12:], 32)
}
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:26,代码来源:address.go
示例4: opCalldataLoad
func opCalldataLoad(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {
stack.push(common.Bytes2Big(getData(context.Input, stack.pop(), common.Big32)))
}
开发者ID:nellyk,项目名称:go-ethereum,代码行数:3,代码来源:instructions.go
示例5: opCaller
func opCaller(instr instruction, env Environment, context *Context, memory *Memory, stack *stack) {
stack.push(common.Bytes2Big(context.caller.Address().Bytes()))
}
开发者ID:nellyk,项目名称:go-ethereum,代码行数:3,代码来源:instructions.go
示例6: CompileProgram
//.........这里部分代码省略.........
program.addInstr(op, pc, opBalance, nil)
case ORIGIN:
program.addInstr(op, pc, opOrigin, nil)
case CALLER:
program.addInstr(op, pc, opCaller, nil)
case CALLVALUE:
program.addInstr(op, pc, opCallValue, nil)
case CALLDATALOAD:
program.addInstr(op, pc, opCalldataLoad, nil)
case CALLDATASIZE:
program.addInstr(op, pc, opCalldataSize, nil)
case CALLDATACOPY:
program.addInstr(op, pc, opCalldataCopy, nil)
case CODESIZE:
program.addInstr(op, pc, opCodeSize, nil)
case EXTCODESIZE:
program.addInstr(op, pc, opExtCodeSize, nil)
case CODECOPY:
program.addInstr(op, pc, opCodeCopy, nil)
case EXTCODECOPY:
program.addInstr(op, pc, opExtCodeCopy, nil)
case GASPRICE:
program.addInstr(op, pc, opGasprice, nil)
case BLOCKHASH:
program.addInstr(op, pc, opBlockhash, nil)
case COINBASE:
program.addInstr(op, pc, opCoinbase, nil)
case TIMESTAMP:
program.addInstr(op, pc, opTimestamp, nil)
case NUMBER:
program.addInstr(op, pc, opNumber, nil)
case DIFFICULTY:
program.addInstr(op, pc, opDifficulty, nil)
case GASLIMIT:
program.addInstr(op, pc, opGasLimit, nil)
case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32:
size := uint64(op - PUSH1 + 1)
bytes := getData([]byte(program.code), new(big.Int).SetUint64(pc+1), new(big.Int).SetUint64(size))
program.addInstr(op, pc, opPush, common.Bytes2Big(bytes))
pc += size
case POP:
program.addInstr(op, pc, opPop, nil)
case DUP1, DUP2, DUP3, DUP4, DUP5, DUP6, DUP7, DUP8, DUP9, DUP10, DUP11, DUP12, DUP13, DUP14, DUP15, DUP16:
program.addInstr(op, pc, opDup, big.NewInt(int64(op-DUP1+1)))
case SWAP1, SWAP2, SWAP3, SWAP4, SWAP5, SWAP6, SWAP7, SWAP8, SWAP9, SWAP10, SWAP11, SWAP12, SWAP13, SWAP14, SWAP15, SWAP16:
program.addInstr(op, pc, opSwap, big.NewInt(int64(op-SWAP1+2)))
case LOG0, LOG1, LOG2, LOG3, LOG4:
program.addInstr(op, pc, opLog, big.NewInt(int64(op-LOG0)))
case MLOAD:
program.addInstr(op, pc, opMload, nil)
case MSTORE:
program.addInstr(op, pc, opMstore, nil)
case MSTORE8:
program.addInstr(op, pc, opMstore8, nil)
case SLOAD:
program.addInstr(op, pc, opSload, nil)
case SSTORE:
program.addInstr(op, pc, opSstore, nil)
case JUMP:
program.addInstr(op, pc, opJump, nil)
case JUMPI:
program.addInstr(op, pc, opJumpi, nil)
case JUMPDEST:
program.addInstr(op, pc, opJumpdest, nil)
program.destinations[pc] = struct{}{}
case PC:
program.addInstr(op, pc, opPc, big.NewInt(int64(pc)))
case MSIZE:
program.addInstr(op, pc, opMsize, nil)
case GAS:
program.addInstr(op, pc, opGas, nil)
case CREATE:
program.addInstr(op, pc, opCreate, nil)
case DELEGATECALL:
// Instruction added regardless of homestead phase.
// Homestead (and execution of the opcode) is checked during
// runtime.
program.addInstr(op, pc, opDelegateCall, nil)
case CALL:
program.addInstr(op, pc, opCall, nil)
case CALLCODE:
program.addInstr(op, pc, opCallCode, nil)
case RETURN:
program.addInstr(op, pc, opReturn, nil)
case SUICIDE:
program.addInstr(op, pc, opSuicide, nil)
case STOP: // Stop the contract
program.addInstr(op, pc, opStop, nil)
default:
program.addInstr(op, pc, nil, nil)
}
}
optimiseProgram(program)
return nil
}
开发者ID:Codzart,项目名称:go-ethereum,代码行数:101,代码来源:jit.go
示例7: Big
func (b Bloom) Big() *big.Int {
return common.Bytes2Big(b[:])
}
开发者ID:Codzart,项目名称:go-ethereum,代码行数:3,代码来源:bloom9.go
示例8: verifyTxFields
func verifyTxFields(txTest TransactionTest, decodedTx *types.Transaction) (err error) {
defer func() {
if recovered := recover(); recovered != nil {
buf := make([]byte, 64<<10)
buf = buf[:runtime.Stack(buf, false)]
err = fmt.Errorf("%v\n%s", recovered, buf)
}
}()
decodedSender, err := decodedTx.From()
if err != nil {
return err
}
expectedSender := mustConvertAddress(txTest.Sender)
if expectedSender != decodedSender {
return fmt.Errorf("Sender mismatch: %v %v", expectedSender, decodedSender)
}
expectedData := mustConvertBytes(txTest.Transaction.Data)
if !bytes.Equal(expectedData, decodedTx.Payload) {
return fmt.Errorf("Tx input data mismatch: %#v %#v", expectedData, decodedTx.Payload)
}
expectedGasLimit := mustConvertBigInt(txTest.Transaction.GasLimit, 16)
if expectedGasLimit.Cmp(decodedTx.GasLimit) != 0 {
return fmt.Errorf("GasLimit mismatch: %v %v", expectedGasLimit, decodedTx.GasLimit)
}
expectedGasPrice := mustConvertBigInt(txTest.Transaction.GasPrice, 16)
if expectedGasPrice.Cmp(decodedTx.Price) != 0 {
return fmt.Errorf("GasPrice mismatch: %v %v", expectedGasPrice, decodedTx.Price)
}
expectedNonce := mustConvertUint(txTest.Transaction.Nonce, 16)
if expectedNonce != decodedTx.AccountNonce {
return fmt.Errorf("Nonce mismatch: %v %v", expectedNonce, decodedTx.AccountNonce)
}
expectedR := common.Bytes2Big(mustConvertBytes(txTest.Transaction.R))
if expectedR.Cmp(decodedTx.R) != 0 {
return fmt.Errorf("R mismatch: %v %v", expectedR, decodedTx.R)
}
expectedS := common.Bytes2Big(mustConvertBytes(txTest.Transaction.S))
if expectedS.Cmp(decodedTx.S) != 0 {
return fmt.Errorf("S mismatch: %v %v", expectedS, decodedTx.S)
}
expectedV := mustConvertUint(txTest.Transaction.V, 16)
if expectedV != uint64(decodedTx.V) {
return fmt.Errorf("V mismatch: %v %v", expectedV, uint64(decodedTx.V))
}
expectedTo := mustConvertAddress(txTest.Transaction.To)
if decodedTx.Recipient == nil {
if expectedTo != common.BytesToAddress([]byte{}) { // "empty" or "zero" address
return fmt.Errorf("To mismatch when recipient is nil (contract creation): %v", expectedTo)
}
} else {
if expectedTo != *decodedTx.Recipient {
return fmt.Errorf("To mismatch: %v %v", expectedTo, *decodedTx.Recipient)
}
}
expectedValue := mustConvertBigInt(txTest.Transaction.Value, 16)
if expectedValue.Cmp(decodedTx.Amount) != 0 {
return fmt.Errorf("Value mismatch: %v %v", expectedValue, decodedTx.Amount)
}
return nil
}
开发者ID:ssonneborn22,项目名称:go-ethereum,代码行数:72,代码来源:transaction_test_util.go
示例9: Run
//.........这里部分代码省略.........
x := stack.pop()
y := stack.pop()
z := stack.pop()
if z.Cmp(Zero) > 0 {
add := new(big.Int).Add(x, y)
base.Mod(add, z)
base = U256(base)
}
stack.push(base)
case MULMOD:
x := stack.pop()
y := stack.pop()
z := stack.pop()
if z.Cmp(Zero) > 0 {
mul := new(big.Int).Mul(x, y)
base.Mod(mul, z)
U256(base)
}
stack.push(base)
case SHA3:
offset, size := stack.pop(), stack.pop()
data := crypto.Sha3(mem.Get(offset.Int64(), size.Int64()))
stack.push(common.BigD(data))
case ADDRESS:
stack.push(common.Bytes2Big(context.Address().Bytes()))
case BALANCE:
addr := common.BigToAddress(stack.pop())
balance := statedb.GetBalance(addr)
stack.push(new(big.Int).Set(balance))
case ORIGIN:
origin := self.env.Origin()
stack.push(origin.Big())
case CALLER:
caller := context.caller.Address()
stack.push(common.Bytes2Big(caller.Bytes()))
case CALLVALUE:
stack.push(new(big.Int).Set(value))
case CALLDATALOAD:
data := getData(input, stack.pop(), common.Big32)
stack.push(common.Bytes2Big(data))
case CALLDATASIZE:
l := int64(len(input))
stack.push(big.NewInt(l))
case CALLDATACOPY:
var (
mOff = stack.pop()
cOff = stack.pop()
l = stack.pop()
开发者ID:nellyk,项目名称:go-ethereum,代码行数:67,代码来源:vm.go
示例10: opAddress
func opAddress(instr instruction, pc *uint64, env Environment, contract *Contract, memory *Memory, stack *stack) {
stack.push(common.Bytes2Big(contract.Address().Bytes()))
}
开发者ID:obscuren,项目名称:etherapis,代码行数:3,代码来源:instructions.go
示例11: SetSignatureValues
func (tx *Transaction) SetSignatureValues(sig []byte) error {
tx.R = common.Bytes2Big(sig[:32])
tx.S = common.Bytes2Big(sig[32:64])
tx.V = sig[64] + 27
return nil
}
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:6,代码来源:transaction.go
示例12: Run
//.........这里部分代码省略.........
base = U256(base)
}
self.Printf(" %v + %v %% %v = %v", x, y, z, base)
stack.push(base)
case MULMOD:
x := stack.pop()
y := stack.pop()
z := stack.pop()
if z.Cmp(Zero) > 0 {
mul := new(big.Int).Mul(x, y)
base.Mod(mul, z)
U256(base)
}
self.Printf(" %v + %v %% %v = %v", x, y, z, base)
stack.push(base)
// 0x20 range
case SHA3:
offset, size := stack.pop(), stack.pop()
data := crypto.Sha3(mem.Get(offset.Int64(), size.Int64()))
stack.push(common.BigD(data))
self.Printf(" => (%v) %x", size, data)
// 0x30 range
case ADDRESS:
stack.push(common.Bytes2Big(context.Address().Bytes()))
self.Printf(" => %x", context.Address())
case BALANCE:
addr := common.BigToAddress(stack.pop())
balance := statedb.GetBalance(addr)
stack.push(balance)
self.Printf(" => %v (%x)", balance, addr)
case ORIGIN:
origin := self.env.Origin()
stack.push(origin.Big())
self.Printf(" => %x", origin)
case CALLER:
caller := context.caller.Address()
stack.push(common.Bytes2Big(caller.Bytes()))
self.Printf(" => %x", caller)
case CALLVALUE:
stack.push(value)
self.Printf(" => %v", value)
case CALLDATALOAD:
data := getData(callData, stack.pop(), common.Big32)
self.Printf(" => 0x%x", data)
stack.push(common.Bytes2Big(data))
case CALLDATASIZE:
l := int64(len(callData))
开发者ID:CedarLogic,项目名称:go-ethereum,代码行数:67,代码来源:vm.go
注:本文中的github.com/ethereum/go-ethereum/common.Bytes2Big函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论