diff --git a/asm/compiler.go b/asm/compiler.go index 76a1cca..198cd55 100644 --- a/asm/compiler.go +++ b/asm/compiler.go @@ -301,12 +301,8 @@ func (c *Compiler) generateOutput(prog *compilerProg) []byte { // resolve the op var op *evm.Op - var size = inst.pushSize if inst.op == "PUSH" { - if size == 0 && !prog.evm.SupportsPush0() { - size = 1 - } - op = prog.evm.PushBySize(size) + op = prog.evm.PushBySize(inst.pushSize) } else { op = prog.evm.OpByName(inst.op) } @@ -316,8 +312,8 @@ func (c *Compiler) generateOutput(prog *compilerProg) []byte { // Add opcode and data padding to output. output = append(output, op.Code) - if len(inst.data) < size { - output = append(output, make([]byte, size-len(inst.data))...) + if len(inst.data) < inst.pushSize { + output = append(output, make([]byte, inst.pushSize-len(inst.data))...) } case inst.op != "": diff --git a/asm/compiler_eval.go b/asm/compiler_eval.go index 82174eb..659c031 100644 --- a/asm/compiler_eval.go +++ b/asm/compiler_eval.go @@ -48,7 +48,7 @@ func (c *Compiler) assignInitialPushSizes(e *evaluator, prog *compilerProg) { c.addError(inst.ast, err) continue } - if err := c.assignPushArg(inst, v, true); err != nil { + if err := prog.assignPushArg(inst, v, true); err != nil { c.addError(inst.ast, err) continue } @@ -91,7 +91,7 @@ func (c *Compiler) assignArgs(e *evaluator, prog *compilerProg) (inst *instructi if err != nil { return inst, err } - if err := c.assignPushArg(inst, v, false); err != nil { + if err := prog.assignPushArg(inst, v, false); err != nil { return inst, err } } @@ -103,7 +103,7 @@ func (c *Compiler) assignArgs(e *evaluator, prog *compilerProg) (inst *instructi // // If setSize is true, the pushSize of variable-size "PUSH" instructions will be assigned // based on the value. -func (c *Compiler) assignPushArg(inst *instruction, v *big.Int, setSize bool) error { +func (prog *compilerProg) assignPushArg(inst *instruction, v *big.Int, setSize bool) error { if v.Sign() < 0 { return ecNegativeResult } @@ -115,7 +115,7 @@ func (c *Compiler) assignPushArg(inst *instruction, v *big.Int, setSize bool) er _, hasExplicitSize := inst.explicitPushSize() if setSize && !hasExplicitSize { - inst.pushSize = c.autoPushSize(b) + inst.pushSize = prog.autoPushSize(b) } if len(b) > inst.pushSize { if !hasExplicitSize { @@ -130,9 +130,12 @@ func (c *Compiler) assignPushArg(inst *instruction, v *big.Int, setSize bool) er return nil } -func (c *Compiler) autoPushSize(value []byte) int { +func (prog *compilerProg) autoPushSize(value []byte) int { if len(value) > 32 { panic("value too big") } + if len(value) == 0 && !prog.evm.SupportsPush0() { + return 1 + } return len(value) }