Skip to content

Commit

Permalink
Fix opcode global CallerApplicationID
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeena840 committed Oct 12, 2022
1 parent 759c502 commit 48b58b5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ from `algosdk` and sends it to the network.
- Fix `gitxna 1 Logs 0` opcode. Previously any attempt to use this opcode would result in a "Not supported" error.
- Fix `TxParams.noteb64` encoding - should use base64 decoder rather than TextEncoder.
- Fix `ed25519verify` opcode implementation. Previously the signature was only checked against the data not the concatenation of "ProgData"||program||data. Additionally test scenarios was added to check the correct implementation.
- Fix `global CallerApplicationID` opcode. Previously the opcode get the wrong caller application ID.

### Breaking Changes

Expand Down
1 change: 1 addition & 0 deletions packages/runtime/src/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export class Ctx implements Context {

getCallerApplicationID(): number {
let callerApplicationID = 0;
// the top value in the `innerTxAppIDCallStack` is the own appID not the caller appID
if (this.innerTxAppIDCallStack.length > 1) {
callerApplicationID = this.innerTxAppIDCallStack[this.innerTxAppIDCallStack.length - 2];
}
Expand Down
8 changes: 4 additions & 4 deletions packages/runtime/test/src/interpreter/opcode-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3039,10 +3039,10 @@ describe("Teal Opcodes", function () {
interpreter.runtime.ctx.innerTxAppIDCallStack = [1, 2];
});
it("Tealv6: CalllerApplicationAddress", function () {
// caller app id = 2
// caller app id = 1
const op = new Global(["CallerApplicationAddress"], 1, interpreter);
op.execute(stack);
assert.deepEqual(decodeAddress(getApplicationAddress(2n)).publicKey, stack.pop());
assert.deepEqual(decodeAddress(getApplicationAddress(1n)).publicKey, stack.pop());

// no caller
interpreter.runtime.ctx.innerTxAppIDCallStack = [];
Expand All @@ -3051,10 +3051,10 @@ describe("Teal Opcodes", function () {
});

it("Tealv6: CallerApplicationID", function () {
// caller app id = 2
// caller app id = 1
const op = new Global(["CallerApplicationID"], 1, interpreter);
op.execute(stack);
assert.equal(2n, stack.pop());
assert.equal(1n, stack.pop());

// no caller
interpreter.runtime.ctx.innerTxAppIDCallStack = [];
Expand Down

0 comments on commit 48b58b5

Please sign in to comment.