How to use Copy method of vm Package

Best Syzkaller code snippet using vm.Copy

abstract-ops.go

Source:abstract-ops.go Github

copy

Full Screen

1// Copyright 2018 MPI-SWS, Valentin Wuestholz, and ConsenSys AG23// This file is part of Bran.4//5// Bran is free software: you can redistribute it and/or modify6// it under the terms of the GNU Lesser General Public License as published by7// the Free Software Foundation, either version 3 of the License, or8// (at your option) any later version.9//10// Bran is distributed in the hope that it will be useful,11// but WITHOUT ANY WARRANTY; without even the implied warranty of12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13// GNU Lesser General Public License for more details.14//15// You should have received a copy of the GNU Lesser General Public License16// along with Bran. If not, see <https://www.gnu.org/licenses/>.1718package analysis1920import (21 "math/big"2223 "github.com/practical-formal-methods/bran/vm"24)2526// pcAndSt is a pair of program counter and state.27type pcAndSt struct {28 pc pcType29 st absState30}3132// stepRes represents the result of executing an abstract transformer.33type stepRes struct {34 mayFail bool35 failureCause string36 postStates []pcAndSt // list of post states37}3839// emptyRes returns a result with no post-states.40func emptyRes() stepRes {41 return stepRes{}42}4344// initRes returns the initial program state (i.e., PC is 0 and stack and memory are empty).45func initRes() stepRes {46 return stepRes{47 postStates: []pcAndSt{48 {49 pc: 0,50 st: absState{51 stack: emptyStack(),52 mem: absMem{53 mem: vm.NewMemory(),54 },55 },56 },57 },58 }59}6061// falRes returns a result that indicates a possible failure.62func failRes(cause string) stepRes {63 return stepRes{64 mayFail: true,65 failureCause: cause,66 }67}6869// nextPcRes produces a result from the current execution environment for non-jump instructions (i.e., PC incremented).70func nextPcRes(env execEnv) stepRes {71 return stepRes{72 postStates: []pcAndSt{73 {74 pc: *env.pc + 1,75 st: env.st,76 },77 },78 }79}8081// absJumpTable represents a jump table for abstract operations.82type absJumpTable [256]absOp8384// execFn is the type of functions executing abstract operations.85// It should not modify any part of the environment (except possibly for the integer pool in the EVM object).86type execFn func(env execEnv) (stepRes, error)8788// absOp represents an abstract operation.89type absOp struct {90 // valid is true if the operation has been initialized.91 valid bool92 // memSize calculates how much memory the operation needs.93 // If unset, the operation should not access memory.94 memSize memSizeFn95 // exec executes an abstract operation.96 // exec can safely assume that by the time it executes, the following will hold:97 // 1) the state and stack will not be top98 // 2) the stack will have been validated (but top values in it are still possible)99 // 3) the memory will have been resized, but it can also be top100 exec execFn101}102103// fromExec creates a valid abstract operation.104func fromExec(exec execFn) absOp {105 return absOp{106 valid: true,107 exec: exec,108 }109}110111// noOpOp is the no-op abstract operation.112var noOpOp = fromExec(func(env execEnv) (stepRes, error) {113 return nextPcRes(env), nil114})115116// mayFailOp is the operation that always fails.117var mayFailOp = fromExec(func(env execEnv) (stepRes, error) {118 return failRes(UnsupportedOpcodeFail), nil119})120121// emptyResOp is the operation that returns an empty state (used for stopping execution).122var emptyResOp = fromExec(func(env execEnv) (stepRes, error) {123 return emptyRes(), nil124})125126// execEnv is the (abstract) execution environment.127type execEnv struct {128 pc *pcType129 interpreter *vm.EVMInterpreter130 contract *vm.Contract131 ppcMap *prevPCMap132 st absState133 conc vm.Operation134}135136// memSizeFn calculates the new size of the memory.137type memSizeFn func(stack absStack, conc vm.MemorySizeFunc) (uint64, bool, bool, error)138139// withSt returns an environment identical to the current one, except for the new state.140func (e execEnv) withSt(newSt absState) execEnv {141 return execEnv{142 pc: e.pc,143 interpreter: e.interpreter,144 contract: e.contract,145 ppcMap: e.ppcMap,146 st: newSt,147 conc: e.conc,148 }149}150151// withStackCopy returns an execution environment with a clone of the current stack.152func (e execEnv) withStackCopy() execEnv {153 return e.withSt(e.st.withStackCopy())154}155156// withMemCopy returns an execution environment with a clone of the current memory.157func (e execEnv) withMemCopy() execEnv {158 return e.withSt(e.st.withMemCopy())159}160161// withPcCopy returns an execution environment with a clone of the current PC.162func (e execEnv) withPcCopy() execEnv {163 cpc := *e.pc164 return execEnv{165 pc: &cpc,166 interpreter: e.interpreter,167 contract: e.contract,168 ppcMap: e.ppcMap,169 st: e.st,170 conc: e.conc,171 }172}173174func (e execEnv) unpack() (*vm.Stack, absMem) {175 return e.st.stack.stack, e.st.mem176}177178// execConc executes the concrete operation in the environment.179func execConc(env execEnv) error {180 interpreter := env.interpreter181 if interpreter.IntPool == nil {182 interpreter.IntPool = vm.PoolOfIntPools.Get()183 defer func() {184 vm.PoolOfIntPools.Put(interpreter.IntPool)185 interpreter.IntPool = nil186 }()187 }188 _, err := env.conc.Execute((*uint64)(env.pc), interpreter, env.contract, env.st.mem.mem, env.st.stack.stack)189 return err190}191192// makeMemFn returns a function that computes the abstract memory size.193func makeMemFn(indices ...int) memSizeFn {194 return func(stack absStack, conc vm.MemorySizeFunc) (uint64, bool, bool, error) {195 hasTop, err := stack.hasTop(indices...)196 if err != nil {197 return 0, false, false, err198 }199 if hasTop {200 return 0, false, true, nil201 }202 sz, overflow := conc(stack.stack)203 return sz, overflow, false, nil204 }205}206207// newAbsJumpTable creates an abstract jump table.208func newAbsJumpTable(forPrefix bool) absJumpTable {209 opCreate := mayFailOp210 opCall := mayFailOp211 opCallCode := mayFailOp212 opDelegateCall := mayFailOp213 opStaticCall := mayFailOp214 opCreate2 := mayFailOp215 if forPrefix {216 opCreate = absOp{217 valid: true,218 memSize: makeMemFn(1, 2),219 exec: makePopPushTopFn(3, 1),220 }221 opCall = absOp{222 valid: true,223 memSize: makeMemFn(3, 4, 5, 6),224 exec: makePopPushMemTopFn(7, 1, 5, 6),225 }226 opCallCode = absOp{227 valid: true,228 memSize: makeMemFn(3, 4, 5, 6),229 exec: makePopPushMemTopFn(7, 1, 5, 6),230 }231 opDelegateCall = absOp{232 valid: true,233 memSize: makeMemFn(2, 3, 4, 5),234 exec: makePopPushMemTopFn(6, 1, 4, 5),235 }236 opStaticCall = absOp{237 valid: true,238 memSize: makeMemFn(2, 3, 4, 5),239 exec: makePopPushMemTopFn(6, 1, 4, 5),240 }241 opCreate2 = absOp{242 valid: true,243 memSize: makeMemFn(1, 2),244 exec: makePopPushTopFn(4, 1),245 }246 }247 return absJumpTable{248 vm.STOP: emptyResOp,249250 vm.ADD: makeStackOp(2, 1),251 vm.MUL: makeStackOp(2, 1),252 vm.SUB: makeStackOp(2, 1),253 vm.DIV: makeStackOp(2, 1),254 vm.SDIV: makeStackOp(2, 1),255 vm.MOD: makeStackOp(2, 1),256 vm.SMOD: makeStackOp(2, 1),257 vm.ADDMOD: makeStackOp(3, 1),258 vm.MULMOD: makeStackOp(3, 1),259 vm.EXP: makeStackOp(2, 1),260 vm.SIGNEXTEND: makeStackOp(2, 1),261262 vm.LT: makeStackOp(2, 1),263 vm.GT: makeStackOp(2, 1),264 vm.SLT: makeStackOp(2, 1),265 vm.SGT: makeStackOp(2, 1),266 vm.EQ: makeStackOp(2, 1),267 vm.ISZERO: makeStackOp(1, 1),268 vm.AND: makeStackOp(2, 1),269 vm.XOR: makeStackOp(2, 1),270 vm.OR: makeStackOp(2, 1),271 vm.NOT: makeStackOp(1, 1),272 vm.BYTE: makeStackOp(2, 1),273 vm.SHA3: absOp{274 valid: true,275 memSize: makeMemFn(0, 1),276 exec: opSha3,277 },278279 vm.SHL: makeStackOp(2, 1),280 vm.SHR: makeStackOp(2, 1),281 vm.SAR: makeStackOp(2, 1),282283 vm.ADDRESS: makePopPushTopOp(0, 1),284 vm.BALANCE: makePopPushTopOp(1, 1),285 vm.ORIGIN: makePopPushTopOp(0, 1),286 vm.CALLER: makePopPushTopOp(0, 1),287 vm.CALLVALUE: makePopPushTopOp(0, 1),288 vm.CALLDATALOAD: makePopPushTopOp(1, 1),289 vm.CALLDATASIZE: makePopPushTopOp(0, 1),290 vm.CALLDATACOPY: absOp{291 valid: true,292 memSize: makeMemFn(0, 2),293 exec: opCallDataCopy,294 },295 vm.CODESIZE: fromExec(delegateConcStackOp),296 vm.CODECOPY: absOp{297 valid: true,298 memSize: makeMemFn(0, 2),299 exec: opCodeCopy,300 },301 vm.GASPRICE: makePopPushTopOp(0, 1),302 vm.EXTCODESIZE: makePopPushTopOp(1, 1),303 vm.EXTCODECOPY: absOp{304 valid: true,305 memSize: makeMemFn(1, 3),306 exec: opExtCodeCopy,307 },308309 vm.RETURNDATASIZE: makePopPushTopOp(0, 1),310 vm.RETURNDATACOPY: absOp{311 valid: true,312 memSize: makeMemFn(0, 2),313 exec: opReturnDataCopy,314 },315 vm.EXTCODEHASH: makePopPushTopOp(1, 1),316317 vm.BLOCKHASH: makePopPushTopOp(1, 1),318 vm.COINBASE: makePopPushTopOp(0, 1),319 vm.TIMESTAMP: makePopPushTopOp(0, 1),320 vm.NUMBER: makePopPushTopOp(0, 1),321 vm.DIFFICULTY: makePopPushTopOp(0, 1),322 vm.GASLIMIT: makePopPushTopOp(0, 1),323 vm.CHAINID: makePopPushTopOp(0, 1),324 vm.SELFBALANCE: makePopPushTopOp(0, 1),325326 vm.POP: makeStackOp(1, 0),327328 vm.MLOAD: absOp{329 valid: true,330 memSize: makeMemFn(0),331 exec: opMload,332 },333 vm.MSTORE: absOp{334 valid: true,335 memSize: makeMemFn(0),336 exec: opMstore,337 },338 vm.MSTORE8: absOp{339 valid: true,340 memSize: makeMemFn(0),341 exec: opMstore8,342 },343344 vm.SLOAD: makePopPushTopOp(1, 1),345 vm.SSTORE: makePopPushTopOp(2, 0),346347 vm.JUMP: fromExec(opJump),348 vm.JUMPI: fromExec(opJumpi),349350 vm.PC: fromExec(delegateConcStackOp),351 vm.MSIZE: fromExec(opMsize),352 vm.GAS: makePopPushTopOp(0, 1),353 vm.JUMPDEST: noOpOp,354355 vm.PUSH1: fromExec(delegateConcStackOp),356 vm.PUSH2: fromExec(delegateConcStackOp),357 vm.PUSH3: fromExec(delegateConcStackOp),358 vm.PUSH4: fromExec(delegateConcStackOp),359 vm.PUSH5: fromExec(delegateConcStackOp),360 vm.PUSH6: fromExec(delegateConcStackOp),361 vm.PUSH7: fromExec(delegateConcStackOp),362 vm.PUSH8: fromExec(delegateConcStackOp),363 vm.PUSH9: fromExec(delegateConcStackOp),364 vm.PUSH10: fromExec(delegateConcStackOp),365 vm.PUSH11: fromExec(delegateConcStackOp),366 vm.PUSH12: fromExec(delegateConcStackOp),367 vm.PUSH13: fromExec(delegateConcStackOp),368 vm.PUSH14: fromExec(delegateConcStackOp),369 vm.PUSH15: fromExec(delegateConcStackOp),370 vm.PUSH16: fromExec(delegateConcStackOp),371 vm.PUSH17: fromExec(delegateConcStackOp),372 vm.PUSH18: fromExec(delegateConcStackOp),373 vm.PUSH19: fromExec(delegateConcStackOp),374 vm.PUSH20: fromExec(delegateConcStackOp),375 vm.PUSH21: fromExec(delegateConcStackOp),376 vm.PUSH22: fromExec(delegateConcStackOp),377 vm.PUSH23: fromExec(delegateConcStackOp),378 vm.PUSH24: fromExec(delegateConcStackOp),379 vm.PUSH25: fromExec(delegateConcStackOp),380 vm.PUSH26: fromExec(delegateConcStackOp),381 vm.PUSH27: fromExec(delegateConcStackOp),382 vm.PUSH28: fromExec(delegateConcStackOp),383 vm.PUSH29: fromExec(delegateConcStackOp),384 vm.PUSH30: fromExec(delegateConcStackOp),385 vm.PUSH31: fromExec(delegateConcStackOp),386 vm.PUSH32: fromExec(delegateConcStackOp),387388 vm.DUP1: fromExec(delegateConcStackOp),389 vm.DUP2: fromExec(delegateConcStackOp),390 vm.DUP3: fromExec(delegateConcStackOp),391 vm.DUP4: fromExec(delegateConcStackOp),392 vm.DUP5: fromExec(delegateConcStackOp),393 vm.DUP6: fromExec(delegateConcStackOp),394 vm.DUP7: fromExec(delegateConcStackOp),395 vm.DUP8: fromExec(delegateConcStackOp),396 vm.DUP9: fromExec(delegateConcStackOp),397 vm.DUP10: fromExec(delegateConcStackOp),398 vm.DUP11: fromExec(delegateConcStackOp),399 vm.DUP12: fromExec(delegateConcStackOp),400 vm.DUP13: fromExec(delegateConcStackOp),401 vm.DUP14: fromExec(delegateConcStackOp),402 vm.DUP15: fromExec(delegateConcStackOp),403 vm.DUP16: fromExec(delegateConcStackOp),404405 vm.SWAP1: fromExec(delegateConcStackOp),406 vm.SWAP2: fromExec(delegateConcStackOp),407 vm.SWAP3: fromExec(delegateConcStackOp),408 vm.SWAP4: fromExec(delegateConcStackOp),409 vm.SWAP5: fromExec(delegateConcStackOp),410 vm.SWAP6: fromExec(delegateConcStackOp),411 vm.SWAP7: fromExec(delegateConcStackOp),412 vm.SWAP8: fromExec(delegateConcStackOp),413 vm.SWAP9: fromExec(delegateConcStackOp),414 vm.SWAP10: fromExec(delegateConcStackOp),415 vm.SWAP11: fromExec(delegateConcStackOp),416 vm.SWAP12: fromExec(delegateConcStackOp),417 vm.SWAP13: fromExec(delegateConcStackOp),418 vm.SWAP14: fromExec(delegateConcStackOp),419 vm.SWAP15: fromExec(delegateConcStackOp),420 vm.SWAP16: fromExec(delegateConcStackOp),421422 vm.LOG0: makeOpLog(0),423 vm.LOG1: makeOpLog(1),424 vm.LOG2: makeOpLog(2),425 vm.LOG3: makeOpLog(3),426 vm.LOG4: makeOpLog(4),427428 vm.CREATE: opCreate,429 // TODO(wuestholz): Maybe improve analysis precision for precompiled contracts.430 vm.CALL: opCall,431 vm.CALLCODE: opCallCode,432 vm.RETURN: emptyResOp,433 vm.DELEGATECALL: opDelegateCall,434 vm.CREATE2: opCreate2,435 vm.STATICCALL: opStaticCall,436 vm.REVERT: emptyResOp,437 vm.SELFDESTRUCT: emptyResOp,438 }439}440441// delegateConcStackOp is an abstract operation that just delegates to the underlying concrete operation.442// It assumes that the concrete operation does not modify the memory.443func delegateConcStackOp(env execEnv) (stepRes, error) {444 env2 := env.withStackCopy().withPcCopy()445 if err := execConc(env2); err != nil {446 return emptyRes(), nil447 }448 return nextPcRes(env2), nil449}450451// makeStackOp returns an abstract operation that mutates the (abstract) stack by popping values and pushing values.452func makeStackOp(pop, push uint) absOp {453 return fromExec(func(env execEnv) (stepRes, error) {454 env2 := env.withStackCopy().withPcCopy()455 stack2, _ := env2.unpack()456 anyTops := false457 for i := 0; uint(i) < pop; i++ {458 if isTop(stack2.Back(i)) {459 anyTops = true460 break461 }462 }463 if anyTops {464 // We pop values from the stack and conservatively push top values.465 for i := 0; uint(i) < pop; i++ {466 stack2.Pop()467 }468 for i := 0; uint(i) < push; i++ {469 stack2.Push(topVal())470 }471 return nextPcRes(env2), nil472 }473 // Just execute the operation concretely (modifying the environment).474 if err := execConc(env2); err != nil {475 return emptyRes(), nil476 }477 return nextPcRes(env2), nil478 })479}480481// makePopPushToapOp returns an operation that first pops stack elements and then pushes top values.482func makePopPushTopOp(pop, push int) absOp {483 return fromExec(makePopPushTopFn(pop, push))484}485486func makePopPushTopFn(pop, push int) execFn {487 return func(env execEnv) (stepRes, error) {488 env2 := env.withStackCopy().withPcCopy()489 stack2, _ := env2.unpack()490 for i := 0; i < pop; i++ {491 stack2.Pop()492 }493 for i := 0; i < push; i++ {494 stack2.Push(topVal())495 }496 return nextPcRes(env2), nil497 }498}499500func makePopPushMemTopFn(pop, push, memOffsetIdx, memSizeArgIdx int) execFn {501 return func(env execEnv) (stepRes, error) {502 env2 := env.withStackCopy().withMemCopy().withPcCopy()503 stack2, _ := env2.unpack()504 memOffset := stack2.Back(memOffsetIdx)505 memSize := stack2.Back(memSizeArgIdx)506 for i := 0; i < pop; i++ {507 stack2.Pop()508 }509 for i := 0; i < push; i++ {510 stack2.Push(topVal())511 }512 if isTop(memOffset) || isTop(memSize) {513 env2.st.mem = topMem()514 } else {515 env2.st.mem.set(memOffset.Uint64(), memSize.Uint64(), topBytes())516 }517 return nextPcRes(env2), nil518 }519}520521func makeOpLog(size int) absOp {522 return absOp{523 valid: true,524 exec: makePopPushTopFn(2+size, 0),525 memSize: makeMemFn(0, 1),526 }527}528529func opSha3(env execEnv) (stepRes, error) {530 env2 := env.withStackCopy().withMemCopy().withPcCopy()531 stack2, mem2 := env2.unpack()532 offset, size := stack2.Back(0), stack2.Back(1)533 if isTop(offset) || isTop(size) || mem2.get(offset.Int64(), size.Int64()).isTop {534 stack2.Pop()535 stack2.Pop()536 stack2.Push(topVal())537 return nextPcRes(env2), nil538 }539 if err := execConc(env2); err != nil {540 return emptyRes(), nil541 }542 return nextPcRes(env2), nil543}544545func opMload(env execEnv) (stepRes, error) {546 env2 := env.withStackCopy().withMemCopy().withPcCopy()547 stack2, mem2 := env2.unpack()548 offset := stack2.Pop()549 if isTop(offset) {550 stack2.Push(topVal())551 } else {552 loadedBytes := mem2.get(offset.Int64(), 32)553 stack2.Push(loadedBytes.toBigInt())554 }555 return nextPcRes(env2), nil556}557558func opMstore(env execEnv) (stepRes, error) {559 env2 := env.withStackCopy().withMemCopy().withPcCopy()560 stack2, mem2 := env2.unpack()561 off, val := stack2.Back(0), stack2.Back(1)562 if mem2.isTop {563 stack2.Pop()564 stack2.Pop()565 return nextPcRes(env2), nil566 }567 if isTop(off) {568 stack2.Pop()569 stack2.Pop()570 env2.st.mem = topMem()571 return nextPcRes(env2), nil572 }573 if isTop(val) {574 stack2.Pop()575 stack2.Pop()576 mem2.set(off.Uint64(), 32, topBytes())577 return nextPcRes(env2), nil578 }579 if err := execConc(env2); err != nil {580 return emptyRes(), nil581 }582 return nextPcRes(env2), nil583}584585func opMstore8(env execEnv) (stepRes, error) {586 env2 := env.withStackCopy().withMemCopy().withPcCopy()587 stack2, mem2 := env2.unpack()588 off, val := stack2.Back(0), stack2.Back(1)589 if mem2.isTop {590 stack2.Pop()591 stack2.Pop()592 return nextPcRes(env2), nil593 }594 if isTop(off) {595 stack2.Pop()596 stack2.Pop()597 env2.st.mem = topMem()598 return nextPcRes(env2), nil599 }600 if isTop(val) {601 stack2.Pop()602 stack2.Pop()603 mem2.set(off.Uint64(), 1, topBytes())604 return nextPcRes(env2), nil605 }606 if err := execConc(env2); err != nil {607 return emptyRes(), nil608 }609 return nextPcRes(env2), nil610}611612func opJump(env execEnv) (stepRes, error) {613 env2 := env.withStackCopy().withPcCopy()614 stack2, _ := env2.unpack()615 dest := stack2.Peek()616 if isTop(dest) {617 return failRes(JumpToTopFail), nil618 }619 if err := execConc(env2); err != nil {620 return emptyRes(), nil621 }622 return stepRes{623 postStates: []pcAndSt{624 {625 pc: *env2.pc, // The PC was already updated by the concrete execution.626 st: env2.st,627 },628 },629 }, nil630}631632func opJumpi(env execEnv) (stepRes, error) {633 stack, _ := env.unpack()634 cond := stack.Back(1)635 var alts []absState636 if isTop(cond) {637 ppc, exists := env.ppcMap.getPrevPC(*env.pc)638 if !exists {639 return failRes(InternalFail), nil640 }641642 thenSt := env.st.withStackCopy()643 // We check if the condition is boolean based on what opcodes where executed earlier.644 isBooleanCond, _, _ := matchesBackwards(env.contract, env.ppcMap, ppc, []vm.OpCode{vm.PUSH, vm.ISZERO})645 if !isBooleanCond {646 isBooleanCond, _, _ = matchesBackwards(env.contract, env.ppcMap, ppc, []vm.OpCode{vm.PUSH, vm.EQ})647 }648 if !isBooleanCond {649 isBooleanCond, _, _ = matchesBackwards(env.contract, env.ppcMap, ppc, []vm.OpCode{vm.PUSH, vm.LT})650 }651 if !isBooleanCond {652 isBooleanCond, _, _ = matchesBackwards(env.contract, env.ppcMap, ppc, []vm.OpCode{vm.PUSH, vm.GT})653 }654 if !isBooleanCond {655 isBooleanCond, _, _ = matchesBackwards(env.contract, env.ppcMap, ppc, []vm.OpCode{vm.PUSH, vm.SLT})656 }657 if !isBooleanCond {658 isBooleanCond, _, _ = matchesBackwards(env.contract, env.ppcMap, ppc, []vm.OpCode{vm.PUSH, vm.SGT})659 }660 if !isBooleanCond {661 isBooleanCond, _, _ = matchesBackwards(env.contract, env.ppcMap, ppc, []vm.OpCode{vm.PUSH, vm.CALL})662 }663 if !isBooleanCond {664 isBooleanCond, _, _ = matchesBackwards(env.contract, env.ppcMap, ppc, []vm.OpCode{vm.PUSH, vm.STATICCALL})665 }666 if !isBooleanCond {667 isBooleanCond, _, _ = matchesBackwards(env.contract, env.ppcMap, ppc, []vm.OpCode{vm.PUSH, vm.DELEGATECALL})668 }669 if !isBooleanCond {670 isBooleanCond, _, _ = matchesBackwards(env.contract, env.ppcMap, ppc, []vm.OpCode{vm.PUSH, vm.CALLCODE})671 }672 if isBooleanCond {673 thenStack := thenSt.stack.stack674 thenCond := thenStack.Back(1)675 thenCond.Set(big.NewInt(1))676 refinedStack := backwardsRefineStack(thenStack, env.contract, env.ppcMap, ppc, MagicInt(16))677 thenSt.stack.stack = refinedStack678 }679680 elseSt := env.st.withStackCopy()681 elseStack := elseSt.stack.stack682 elseCond := elseStack.Back(1)683 elseCond.Set(big.NewInt(0))684685 refinedStack := backwardsRefineStack(elseStack, env.contract, env.ppcMap, ppc, MagicInt(16))686 elseSt.stack.stack = refinedStack687688 alts = []absState{thenSt, elseSt}689 } else {690 alts = []absState{env.st.withStackCopy()}691 }692693 var newStates []pcAndSt694 for _, st := range alts {695 altEnv := env.withSt(st).withPcCopy()696 altDest, _ := altEnv.unpack()697 if isTop(altDest.Peek()) {698 return failRes(JumpToTopFail), nil699 }700 if err := execConc(altEnv); err == nil {701 // We ignore states that would lead to an error (e.g., invalid jump destination).702 postJmpSt := pcAndSt{703 pc: *altEnv.pc, // The PC was already updated by the concrete execution.704 st: altEnv.st,705 }706 newStates = append(newStates, postJmpSt)707 }708 }709 return stepRes{postStates: newStates}, nil710}711712func opMsize(env execEnv) (stepRes, error) {713 env2 := env.withStackCopy().withPcCopy()714 stack2, mem2 := env2.unpack()715 if mem2.isTop {716 stack2.Push(topVal())717 return nextPcRes(env2), nil718 }719 if err := execConc(env2); err != nil {720 return emptyRes(), nil721 }722 return nextPcRes(env2), nil723}724725func opCallDataCopy(env execEnv) (stepRes, error) {726 env2 := env.withStackCopy().withMemCopy().withPcCopy()727 stack2, mem2 := env2.unpack()728 memOffset, _, size := stack2.Pop(), stack2.Pop(), stack2.Pop()729 if mem2.isTop {730 return nextPcRes(env2), nil731 }732 if isTop(memOffset) || isTop(size) {733 env2.st.mem = topMem()734 return nextPcRes(env2), nil735 }736 // Since we don't track the input to the contract, we have to set737 // all bytes to top.738 mem2.set(memOffset.Uint64(), size.Uint64(), topBytes())739 return nextPcRes(env2), nil740}741742func opExtCodeCopy(env execEnv) (stepRes, error) {743 env2 := env.withStackCopy().withMemCopy().withPcCopy()744 stack2, mem2 := env2.unpack()745 _, memOffset, _, size := stack2.Pop(), stack2.Pop(), stack2.Pop(), stack2.Pop()746 if mem2.isTop {747 return nextPcRes(env2), nil748 }749 if isTop(memOffset) || isTop(size) {750 env2.st.mem = topMem()751 return nextPcRes(env2), nil752 }753 mem2.set(memOffset.Uint64(), size.Uint64(), topBytes())754 return nextPcRes(env2), nil755}756757func opCodeCopy(env execEnv) (stepRes, error) {758 env2 := env.withStackCopy().withMemCopy().withPcCopy()759 stack2, mem2 := env2.unpack()760 memOffset, _, size := stack2.Pop(), stack2.Pop(), stack2.Pop()761 if mem2.isTop {762 return nextPcRes(env2), nil763 }764 if isTop(memOffset) || isTop(size) {765 env2.st.mem = topMem()766 return nextPcRes(env2), nil767 }768 // We currently just store top values even though we could copy the contract's code.769 mem2.set(memOffset.Uint64(), size.Uint64(), topBytes())770 return nextPcRes(env2), nil771}772773func opReturnDataCopy(env execEnv) (stepRes, error) {774 env2 := env.withStackCopy().withMemCopy().withPcCopy()775 stack2, mem2 := env2.unpack()776 memOffset, dataOffset, size := stack2.Pop(), stack2.Pop(), stack2.Pop()777 if isTop(dataOffset) {778 return failRes(TopOffsetFail), nil779 }780 if mem2.isTop {781 return nextPcRes(env2), nil782 }783 if isTop(memOffset) || isTop(size) {784 env2.st.mem = topMem()785 return nextPcRes(env2), nil786 }787 if err := execConc(env2); err != nil {788 return emptyRes(), nil ...

Full Screen

Full Screen

neovm_value_test.go

Source:neovm_value_test.go Github

copy

Full Screen

1/*2 * Copyright (C) 2018 The ontology Authors3 * This file is part of The ontology library.4 *5 * The ontology is free software: you can redistribute it and/or modify6 * it under the terms of the GNU Lesser General Public License as published by7 * the Free Software Foundation, either version 3 of the License, or8 * (at your option) any later version.9 *10 * The ontology is distributed in the hope that it will be useful,11 * but WITHOUT ANY WARRANTY; without even the implied warranty of12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 * GNU Lesser General Public License for more details.14 *15 * You should have received a copy of the GNU Lesser General Public License16 * along with The ontology. If not, see <http://www.gnu.org/licenses/>.17 */18package types19import (20 "fmt"21 "github.com/ontio/ontology/common"22 "github.com/stretchr/testify/assert"23 "math"24 "math/big"25 "testing"26)27func buildStruct(item []VmValue) (*StructValue, error) {28 s := NewStructValue()29 for _, val := range item {30 err := s.Append(val)31 if err != nil {32 return nil, err33 }34 }35 return s, nil36}37func buildArray(item []VmValue) *ArrayValue {38 arr := NewArrayValue()39 for _, val := range item {40 arr.Append(val)41 }42 return arr43}44func TestSerialize(t *testing.T) {45 bsValue, err := VmValueFromBytes([]byte("test"))46 assert.Equal(t, err, nil)47 boolValue := VmValueFromBool(true)48 bigin := new(big.Int)49 bigin.SetInt64(int64(1000))50 biginValue, err := VmValueFromBigInt(bigin)51 assert.Equal(t, err, nil)52 uint64Value := VmValueFromUint64(uint64(100))53 s, err := buildStruct([]VmValue{bsValue, boolValue, biginValue, uint64Value})54 assert.Nil(t, err)55 structValue := VmValueFromStructVal(s)56 sink := new(common.ZeroCopySink)57 structValue.Serialize(sink)58 assert.Equal(t, common.ToHexString(sink.Bytes()), "810400047465737401010202e803020164")59 source := common.NewZeroCopySource(sink.Bytes())60 vs := VmValue{}61 vs.Deserialize(source)62 assert.Equal(t, structValue, vs)63 arr := buildArray([]VmValue{bsValue, boolValue, biginValue, uint64Value})64 sinkArr := new(common.ZeroCopySink)65 arrValue := VmValueFromArrayVal(arr)66 arrValue.Serialize(sinkArr)67 assert.Equal(t, common.ToHexString(sinkArr.Bytes()), "800400047465737401010202e803020164")68 arrValue2 := VmValue{}69 source = common.NewZeroCopySource(sinkArr.Bytes())70 arrValue2.Deserialize(source)71 assert.Equal(t, arrValue2, arrValue)72 m := NewMapValue()73 m.Set(bsValue, arrValue)74 m.Set(biginValue, structValue)75 m.Set(uint64Value, boolValue)76 mValue := VmValueFromMapValue(m)77 sinkMap := new(common.ZeroCopySink)78 mValue.Serialize(sinkMap)79 assert.Equal(t, "82030201640101000474657374800400047465737401010202e8030201640202e803810400047465737401010202e803020164", common.ToHexString(sinkMap.Bytes()))80 arr = NewArrayValue()81 b, _ := new(big.Int).SetString("9923372036854775807", 10)82 bi, err := VmValueFromBigInt(b)83 assert.Nil(t, err)84 arr.Append(bi)85 val_arr := VmValueFromArrayVal(arr)86 res_t, err := val_arr.ConvertNeoVmValueHexString()87 assert.Nil(t, err)88 fmt.Println("res_t:", res_t)89 assert.Equal(t, "ffffc58e4ae6b68900", res_t.([]interface{})[0])90}91func TestVmValue_ConvertNeoVmValueHexString(t *testing.T) {92 bs := make([]byte, 0, 64*1024)93 for i := 0; i < 64*1024; i++ {94 bs = append(bs, byte(1))95 }96 vm, err := VmValueFromBytes(bs)97 assert.Nil(t, err)98 _, err = vm.ConvertNeoVmValueHexString()99 assert.Nil(t, err)100 bs2 := make([]byte, 0, 64*1024)101 for i := 0; i < 64*1024+1; i++ {102 bs2 = append(bs2, byte(1))103 }104 vm2, err := VmValueFromBytes(bs2)105 assert.Nil(t, err)106 _, err = vm2.ConvertNeoVmValueHexString()107 assert.NotNil(t, err)108}109func TestStructValue_Clone(t *testing.T) {110 bsValue, err := VmValueFromBytes([]byte("test"))111 assert.Equal(t, err, nil)112 boolValue := VmValueFromBool(true)113 bigin := new(big.Int)114 bigin.SetInt64(int64(1000))115 biginValue, err := VmValueFromBigInt(bigin)116 assert.Equal(t, err, nil)117 uint64Value := VmValueFromUint64(uint64(100))118 m := NewMapValue()119 m.Set(bsValue, bsValue)120 s, err := buildStruct([]VmValue{bsValue, boolValue, biginValue, uint64Value, VmValueFromMapValue(m)})121 assert.Nil(t, err)122 s2, _ := s.Clone()123 structValue := VmValueFromStructVal(s)124 m2 := s2.Data[s2.Len()-1]125 mm2, _ := m2.AsMapValue()126 mm2.Set(bsValue, uint64Value)127 structValue2 := VmValueFromStructVal(s2)128 assert.Equal(t, structValue.Equals(structValue2), true)129}130func TestVmValue_Equals(t *testing.T) {131 bsValue, err := VmValueFromBytes([]byte("test"))132 assert.Equal(t, err, nil)133 boolValue := VmValueFromBool(true)134 bigin := new(big.Int)135 bigin.SetInt64(int64(1000))136 biginValue, err := VmValueFromBigInt(bigin)137 assert.Equal(t, err, nil)138 uint64Value := VmValueFromUint64(uint64(100))139 s, err := buildStruct([]VmValue{bsValue, boolValue, biginValue, uint64Value})140 assert.Nil(t, err)141 structValue := VmValueFromStructVal(s)142 s2, err := buildStruct([]VmValue{bsValue, boolValue, biginValue, uint64Value})143 assert.Nil(t, err)144 structValue2 := VmValueFromStructVal(s2)145 res := structValue.Equals(structValue2)146 assert.True(t, res)147 m := NewMapValue()148 m3 := VmValueFromMapValue(m)149 m2 := NewMapValue()150 assert.False(t, m3.Equals(VmValueFromMapValue(m2)))151 assert.True(t, m3.Equals(m3))152 arr := VmValueFromArrayVal(NewArrayValue())153 arr2 := VmValueFromArrayVal(NewArrayValue())154 assert.False(t, arr.Equals(arr2))155 intero := VmValueFromInteropValue(NewInteropValue(nil))156 intero2 := VmValueFromInteropValue(NewInteropValue(nil))157 assert.False(t, intero.Equals(intero2))158 _, err = intero.AsInteropValue()159 assert.Nil(t, err)160 _, err = arr.AsInteropValue()161 assert.NotNil(t, err)162}163func TestVmValue_BuildParamToNative(t *testing.T) {164 inte, err := VmValueFromBigInt(new(big.Int).SetUint64(math.MaxUint64))165 assert.Nil(t, err)166 boo := VmValueFromBool(false)167 bs, err := VmValueFromBytes([]byte("hello"))168 assert.Nil(t, err)169 stru, err := buildStruct([]VmValue{inte, boo, bs})170 assert.Nil(t, err)171 arr := NewArrayValue()172 s := VmValueFromStructVal(stru)173 r, _ := s.AsBool()174 assert.True(t, r)175 arr.Append(s)176 res := VmValueFromArrayVal(arr)177 _, err = res.AsBool()178 assert.NotNil(t, err)179 sink := common.NewZeroCopySink(nil)180 err = res.BuildParamToNative(sink)181 assert.Nil(t, err)182 assert.Equal(t, "010109ffffffffffffffff00000568656c6c6f", common.ToHexString(sink.Bytes()))183}184func TestVmValueFromUint64(t *testing.T) {185 val := VmValueFromUint64(math.MaxUint64)186 assert.Equal(t, val.valType, bigintType)187}188func TestVmValue_Deserialize(t *testing.T) {189 b, _ := new(big.Int).SetString("9923372036854775807", 10)190 val_b, err := VmValueFromBigInt(b)191 assert.Nil(t, err)192 m := NewMapValue()193 bs, err := VmValueFromBytes([]byte("key"))194 assert.Nil(t, err)195 m.Set(bs, val_b)196 val_m := VmValueFromMapValue(m)197 sink := common.NewZeroCopySink(nil)198 val_m.Serialize(sink)199 assert.Equal(t, "820100036b65790209ffffc58e4ae6b68900", common.ToHexString(sink.Bytes()))200 val_m2 := VmValueFromMapValue(nil)201 bss, err := common.HexToBytes("820100036b65790209ffffc58e4ae6b68900")202 assert.Nil(t, err)203 source := common.NewZeroCopySource(bss)204 val_m2.Deserialize(source)205 assert.Equal(t, val_m, val_m2)206}207func TestVmValue_DeserializeArray(t *testing.T) {208 val := VmValue{}209 sink := common.NewZeroCopySink(nil)210 for i := 0; i < MAX_COUNT; i++ {211 sink.WriteByte(arrayType)212 sink.WriteVarUint(1)213 }214 sink.WriteByte(boolType)215 sink.WriteBool(true)216 source := common.NewZeroCopySource(sink.Bytes())217 err := val.Deserialize(source)218 assert.Nil(t, err)219 val2 := VmValue{}220 sink2 := common.NewZeroCopySink(nil)221 for i := 0; i < MAX_COUNT+1; i++ {222 sink2.WriteByte(arrayType)223 sink2.WriteVarUint(1)224 }225 sink2.WriteByte(boolType)226 sink2.WriteBool(true)227 source2 := common.NewZeroCopySource(sink2.Bytes())228 err = val2.Deserialize(source2)229 assert.NotNil(t, err)230}231func TestVmValue_DeserializeMap(t *testing.T) {232 val := VmValue{}233 sink := common.NewZeroCopySink(nil)234 sink.WriteByte(mapType)235 sink.WriteVarUint(1)236 for i := 0; i < MAX_COUNT-1; i++ {237 sink.WriteByte(bytearrayType)238 sink.WriteVarUint(1)239 sink.WriteByte(1)240 sink.WriteByte(mapType)241 sink.WriteVarUint(1)242 }243 sink.WriteByte(bytearrayType)244 sink.WriteVarUint(1)245 sink.WriteByte(1)246 sink.WriteByte(bytearrayType)247 sink.WriteVarUint(1)248 sink.WriteByte(1)249 source := common.NewZeroCopySource(sink.Bytes())250 err := val.Deserialize(source)251 assert.Nil(t, err)252 val2 := VmValue{}253 sink2 := common.NewZeroCopySink(nil)254 sink2.WriteByte(mapType)255 sink2.WriteVarUint(1)256 for i := 0; i < MAX_COUNT; i++ {257 sink2.WriteByte(bytearrayType)258 sink2.WriteVarUint(1)259 sink2.WriteByte(1)260 sink2.WriteByte(mapType)261 sink2.WriteVarUint(1)262 }263 sink2.WriteByte(boolType)264 sink2.WriteBool(true)265 sink2.WriteByte(boolType)266 sink2.WriteBool(true)267 source2 := common.NewZeroCopySource(sink2.Bytes())268 err = val2.Deserialize(source2)269 assert.Equal(t, "vmvalue depth over the uplimit", err.Error())270}271func TestVmValue_DeserializeStruct(t *testing.T) {272 sink := common.NewZeroCopySink(nil)273 for i := 0; i < MAX_COUNT-1; i++ {274 sink.WriteByte(structType)275 sink.WriteVarUint(1)276 }277 sink.WriteByte(boolType)278 sink.WriteBool(true)279 source := common.NewZeroCopySource(sink.Bytes())280 val := VmValue{}281 err := val.Deserialize(source)282 assert.Nil(t, err)283 val2 := VmValue{}284 sink2 := common.NewZeroCopySink(nil)285 for i := 0; i < MAX_COUNT+1; i++ {286 sink2.WriteByte(structType)287 sink2.WriteVarUint(1)288 }289 sink2.WriteByte(boolType)290 sink2.WriteBool(true)291 source2 := common.NewZeroCopySource(sink2.Bytes())292 err = val2.Deserialize(source2)293 assert.Equal(t, "vmvalue depth over the uplimit", err.Error())294}295func TestVmValue_AsBool(t *testing.T) {296 b, _ := new(big.Int).SetString("9923372036854775807", 10)297 val, err := VmValueFromBigInt(b)298 assert.Nil(t, err)299 res, err := val.AsBool()300 assert.Nil(t, err)301 assert.Equal(t, true, res)302 //9223372036854775807303 bb, _ := new(big.Int).SetString("9223372036854775807", 10)304 val, err = VmValueFromBigInt(bb)305 assert.Nil(t, err)...

Full Screen

Full Screen

zz_generated.deepcopy.go

Source:zz_generated.deepcopy.go Github

copy

Full Screen

1/*2Copyright 2019 The Kubernetes Authors.3Licensed under the Apache License, Version 2.0 (the "License");4you may not use this file except in compliance with the License.5You may obtain a copy of the License at6 http://www.apache.org/licenses/LICENSE-2.07Unless required by applicable law or agreed to in writing, software8distributed under the License is distributed on an "AS IS" BASIS,9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.10See the License for the specific language governing permissions and11limitations under the License.12*/13// +build !ignore_autogenerated14// Code generated by operator-sdk. DO NOT EDIT.15package v1alpha116import (17 runtime "k8s.io/apimachinery/pkg/runtime"18)19// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.20func (in *CnsNodeVmAttachment) DeepCopyInto(out *CnsNodeVmAttachment) {21 *out = *in22 out.TypeMeta = in.TypeMeta23 in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)24 out.Spec = in.Spec25 in.Status.DeepCopyInto(&out.Status)26 return27}28// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CnsNodeVmAttachment.29func (in *CnsNodeVmAttachment) DeepCopy() *CnsNodeVmAttachment {30 if in == nil {31 return nil32 }33 out := new(CnsNodeVmAttachment)34 in.DeepCopyInto(out)35 return out36}37// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.38func (in *CnsNodeVmAttachment) DeepCopyObject() runtime.Object {39 if c := in.DeepCopy(); c != nil {40 return c41 }42 return nil43}44// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.45func (in *CnsNodeVmAttachmentList) DeepCopyInto(out *CnsNodeVmAttachmentList) {46 *out = *in47 out.TypeMeta = in.TypeMeta48 out.ListMeta = in.ListMeta49 if in.Items != nil {50 in, out := &in.Items, &out.Items51 *out = make([]CnsNodeVmAttachment, len(*in))52 for i := range *in {53 (*in)[i].DeepCopyInto(&(*out)[i])54 }55 }56 return57}58// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CnsNodeVmAttachmentList.59func (in *CnsNodeVmAttachmentList) DeepCopy() *CnsNodeVmAttachmentList {60 if in == nil {61 return nil62 }63 out := new(CnsNodeVmAttachmentList)64 in.DeepCopyInto(out)65 return out66}67// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.68func (in *CnsNodeVmAttachmentList) DeepCopyObject() runtime.Object {69 if c := in.DeepCopy(); c != nil {70 return c71 }72 return nil73}74// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.75func (in *CnsNodeVmAttachmentSpec) DeepCopyInto(out *CnsNodeVmAttachmentSpec) {76 *out = *in77 return78}79// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CnsNodeVmAttachmentSpec.80func (in *CnsNodeVmAttachmentSpec) DeepCopy() *CnsNodeVmAttachmentSpec {81 if in == nil {82 return nil83 }84 out := new(CnsNodeVmAttachmentSpec)85 in.DeepCopyInto(out)86 return out87}88// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.89func (in *CnsNodeVmAttachmentStatus) DeepCopyInto(out *CnsNodeVmAttachmentStatus) {90 *out = *in91 if in.AttachmentMetadata != nil {92 in, out := &in.AttachmentMetadata, &out.AttachmentMetadata93 *out = make(map[string]string, len(*in))94 for key, val := range *in {95 (*out)[key] = val96 }97 }98 return99}100// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CnsNodeVmAttachmentStatus.101func (in *CnsNodeVmAttachmentStatus) DeepCopy() *CnsNodeVmAttachmentStatus {102 if in == nil {103 return nil104 }105 out := new(CnsNodeVmAttachmentStatus)106 in.DeepCopyInto(out)107 return out108}...

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx, cancel := context.WithCancel(context.Background())4 defer cancel()5 c, err := NewClient(ctx)6 if err != nil {7 panic(err)8 }9 finder := object.NewFinder(c.Client, true)10 dc, err := finder.Datacenter(ctx, c.Datacenter)11 if err != nil {12 panic(err)13 }14 finder.SetDatacenter(dc)15 vm, err := finder.VirtualMachine(ctx, "test")16 if err != nil {17 panic(err)18 }19 folder, err := finder.Folder(ctx, "test")20 if err != nil {21 panic(err)22 }23 vm2, err := folder.CreateVM(ctx, types.VirtualMachineConfigSpec{24 }, vm.ResourcePool, nil)25 if err != nil {26 panic(err)27 }28 task, err := vm2.Copy(ctx, folder, "newvm-copy")29 if err != nil {30 panic(err)31 }32 err = task.Wait(ctx)33 if err != nil {34 panic(err)35 }36 info, err := task.WaitForResult(ctx, nil)37 if err != nil {38 panic(err)39 }40 fmt.Println(info.Result.(string))41}42import (43func main() {44 ctx, cancel := context.WithCancel(context.Background())45 defer cancel()46 c, err := NewClient(ctx)47 if err != nil {48 panic(err)49 }50 finder := object.NewFinder(c.Client, true)51 dc, err := finder.Datacenter(ctx, c.Datacenter)52 if err != nil {53 panic(err)54 }55 finder.SetDatacenter(dc)56 vm, err := finder.VirtualMachine(ctx, "test")57 if err != nil {58 panic(err)59 }

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 ctx, cancel := context.WithCancel(context.Background())4 defer cancel()5 u.User = url.UserPassword("user", "password")6 c, _ := govmomi.NewClient(ctx, u, true)7 f := find.NewFinder(c.Client, true)8 dc, _ := f.DefaultDatacenter(ctx)9 vm, _ := f.VirtualMachine(ctx, "source_vm")10 folder, _ := f.Folder(ctx, "destination_folder")11 host, _ := f.HostSystem(ctx, "destination_host")12 ds, _ := f.Datastore(ctx, "destination_datastore")13 spec := types.VirtualMachineRelocateSpec{14 Host: host.Reference(),15 Datastore: ds.Reference(),16 DiskMoveType: string(types.VirtualMachineRelocateDiskMoveOptionsCreateNewChildDiskBacking),17 }18 cloneSpec := types.VirtualMachineCloneSpec{19 }20 task, _ := vm.Clone(ctx, folder, "destination_vm", cloneSpec)21 _, _ = task.WaitForResult(ctx, nil)22 task, _ = vm.Destroy(ctx)23 _, _ = task.WaitForResult(ctx, nil)24}25import (

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var (4 env = vm.NewEVM(vm.Context{}, nil, nil, nil)5 value = new(vm.IntPool).Get()6 offset = new(vm.IntPool).Get()7 value.SetInt64(100)8 offset.SetInt64(200)9 env.Copy(value, offset)10 fmt.Println(env.GetState(vm.Address{}, vm.Hash{}))11}12{200 100}

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 vm := NewVM()4 vm.Run()5}6type VM struct {7}8func NewVM() *VM {9 return &VM{}10}11func (vm *VM) Run() {12}13func (vm *VM) Copy(src, dst string) error {14}15import (16func main() {17 vm := NewVM()18 vm.Run()19}20type VM struct {21}22func NewVM() *VM {23 return &VM{}24}25func (vm *VM) Run() {26}27func (vm *VM) Copy(src, dst string) error {28}29import (30func main() {31 vm := NewVM()32 vm.Run()33}34type VM struct {35}36func NewVM() *VM {37 return &VM{}38}39func (vm *VM) Run() {40}41func (vm *VM) Copy(src, dst string) error {42}43import (44func main() {45 vm := NewVM()46 vm.Run()47}48type VM struct {49}50func NewVM() *VM {51 return &VM{}52}53func (vm *VM) Run() {54}55func (vm *VM) Copy(src, dst string) error {56}57import (58func main() {59 vm := NewVM()60 vm.Run()61}62type VM struct {63}64func NewVM() *VM {65 return &VM{}66}67func (vm *VM) Run() {68}69func (vm *VM) Copy(src, dst string) error {70}

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1import java.io.*;2{3public static void main(String args[])throws IOException4{5FileReader fr=new FileReader("D:\\java\\file.txt");6FileWriter fw=new FileWriter("D:\\java\\file1.txt");7int ch;8while((ch=fr.read())!=-1)9fw.write(ch);10fw.close();11fr.close();12}13}14import java.io.*;15{16public static void main(String args[])throws IOException17{18FileReader fr=new FileReader("D:\\java\\file.txt");19BufferedReader br=new BufferedReader(fr);20FileWriter fw=new FileWriter("D:\\java\\file1.txt");21String s;22while((s=br.readLine())!=null)23fw.write(s);24fw.close();25fr.close();26}27}28import java.io.*;

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1import (2type VM struct {3}4func (v VM) Copy() {5 fmt.Println("Copy method of VM class")6}7func main() {

Full Screen

Full Screen

Copy

Using AI Code Generation

copy

Full Screen

1func main() {2 vm := goja.New()3 vm.Set("Copy", Copy)4 vm.RunString(`5 var a = {6 }7 var b = Copy(a)8 console.log(b)9}10func Copy(v interface{}) interface{} {11 var b interface{}12 enc := gob.NewEncoder(&buf)13 dec := gob.NewDecoder(&buf)14 err := enc.Encode(v)15 if err != nil {16 log.Fatal("encode error:", err)17 }18 err = dec.Decode(&b)19 if err != nil {20 log.Fatal("decode error:", err)21 }22}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful