Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARC56: Extended App Description #258

Open
wants to merge 57 commits into
base: main
Choose a base branch
from

Conversation

joe-p
Copy link
Contributor

@joe-p joe-p commented Nov 15, 2023

Basically takes most of the ideas in ARC32 and reorgs it in a way that is backwards compatible with ARC4 clients. Main benefit of this is HLLs can simply generate one JSON artifact.

@robdmoore
Copy link
Contributor

I know the eventual goal is to use simulate, but I wonder if we add in optional per-method hints for things like:

  • Fees
  • Boxes
  • Foreign arrays (? where you don't want that in the method selector)

And also:

  • Template variables?

Are there other things that have come up in the past worth considering while we are looking at this?

@joe-p
Copy link
Contributor Author

joe-p commented Nov 15, 2023

I know the eventual goal is to use simulate, but I wonder if we add in optional per-method hints for things like:

Fees
Boxes
Foreign arrays (? where you don't want that in the method selector)

My rationale for not including a field for these sort of things is that they can be dynamic which can be hard to describe in JSON and they could be network dependent. It also is not easy for a HLL to autogenerate these sorts of things and if the dev is required to manually write them out might as well just have them write a standardized readonly method that returns this information so they have the full power of the language and contract state/methods at their disposal (see ARC51).

Template variables?

Yes good call.

Co-authored-by: Rob Moore (MakerX) <robertmooreweb@gmail.com>
@joe-p
Copy link
Contributor Author

joe-p commented Oct 3, 2024

Nice thing is that also gives future extensibility for other pcOffset values in the future?

This is why I think just having a completely seperate key in each SourceInfo is nice. Clients can look for pc or cblocksPcOffset. In the future we can just use a different key name for different methods if we want to implement them. Clients that don't support this new method will simply not resolve errors, but nothing will crash and burn.

@joe-p
Copy link
Contributor Author

joe-p commented Oct 3, 2024

I do like putting pcOffset at the top level though so it's easy to discover which method is being used

@robdmoore
Copy link
Contributor

Exactly, the thing is the same treatment will apply to all items so it makes more sense to have a key at the top level than change the key at the lower levels.

Then, for optimisation purposes it should be possible (default even?) to indicate there is no offset and they are absolute vs it's a cBlock offset.

The worst case of a client not supporting the offset type isn't a huge deal it just means the debugging info will be off, but if the mechanism to specify the type of offset exists on day 1 clients can read that value and act base don it (including opting out of debugging if it's a value they don't understand). I think that's way cleaner and less confusing than needing to read individual items and look for different keys. It's more efficient and more explicit.

On reflection, we also probably don't need the teal line offset since we can calculate that from source map if we have it and if we don't have it we can calculate it from the program bytes!

@robdmoore
Copy link
Contributor

i.e.

sourceInfo: {
  approval: {
    pcOffset: 'cBlock' | 'none',
    mappings: [{pc: 4, ...}, ...]
  }
}

@daniel-makerx
Copy link
Contributor

daniel-makerx commented Oct 4, 2024

On reflection, we also probably don't need the teal line offset since we can calculate that from source map if we have it and if we don't have it we can calculate it from the program bytes!

Unfortunately source map on it's own isn't enough to know which line has the constant blocks as it only has line -> pc mappings

So if we are going to have the tealOffset option then that would need to be in the spec. But if we are going to support parsing bytecode anyway for the cBlock option maybe that is enough for now? It is explicit which is the key thing I wanted to see in the spec.

@robdmoore
Copy link
Contributor

Ahh yeah that was my mistake.

I think it would be good to have an optional tealOffset key if the pcOffset is cBlock to avoid the extra byte code lookup, but it's not a hill I'd die on so comfortable if we don't have it.

@cusma
Copy link
Contributor

cusma commented Oct 9, 2024

@robdmoore @joe-p here you can find the ARC about AVM run time error in program bytecode I was mentioning in previous comments: #315 (cc: @nullun)

@joe-p
Copy link
Contributor Author

joe-p commented Oct 10, 2024

@daniel-makerx @robdmoore In 35a19b3 I added ProgramSourceInfo interface that includes a pcOffsetMethod key.

I think it would be good to have an optional tealOffset key if the pcOffset is cBlock to avoid the extra byte code lookup, but it's not a hill I'd die on so comfortable if we don't have it.

Depending on consistency in decompiled output makes me a bit nervous. I think it's unlikely to change but I also think it's relatively easy to parse the cblocks if they are at the top of the program.

ARCs/arc-0056.md Outdated Show resolved Hide resolved
ARCs/arc-0056.md Outdated Show resolved Hide resolved
ARCs/arc-0056.md Outdated Show resolved Hide resolved
ARCs/arc-0056.md Outdated Show resolved Hide resolved
ARCs/arc-0056.md Outdated Show resolved Hide resolved
};
/** The scratch variables used during runtime */
scratchVariables?: {
[name: string]: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume name is meant to be a variable name?

Wondering if this should be an array with an optional name (and maybe description?) as scratch slots might be used without an associated name? Or perhaps the key should be the slot number since that is required and unique?

Additionally I also assume this is just for documenting scratch variables intended to be read by other applications, not necessarily every scratch slot used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally I also assume this is just for documenting scratch variables intended to be read by other applications, not necessarily every scratch slot used?

Yeah exactly. The main purpose of having this field is so other contracts can easily access scratch variables. For example, TEALScript compiler uses scratch but this is only populated by user-defined scratch slots. I think forcing a name to be defined is fine because that's how it would be defined in the HLL. You can't have a property that is just a number so a name needs to be defined. I definitely like adding a desc though

joe-p and others added 4 commits October 16, 2024 08:18
Co-authored-by: Daniel McGregor <daniel.mcgregor@makerx.com.au>
Co-authored-by: Daniel McGregor <daniel.mcgregor@makerx.com.au>
};
};
/** Named structs use by the application. Each struct field appears in the same order as ABI encoding. */
structs: { [structName: StructName]: StructField[] };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing, noticed both StructField and this mapping don't have any sort of desc property, might be useful to have?

@joe-p
Copy link
Contributor Author

joe-p commented Oct 23, 2024

In 19c6269 I removed teal from SourceInfo because we agreed it was only useful for developers reading the file. I realized, however, that the TEAL line numbers are also used to give better error messages even without an explicit error message, so I've added it back as an optional field RECOMMENDED for development, along with a source string

* The key is the base64 genesis hash of the network, and the value contains
* information about the deployed contract in the network indicated by the
* key. A key containing the human-readable name of the network MAY be
* included, but the corresponding genesis hash key MUST also be define

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* included, but the corresponding genesis hash key MUST also be define
* included, but the corresponding genesis hash key MUST also be defined

appID: number;
};
};
/** Named structs use by the application. Each struct field appears in the same order as ABI encoding. */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** Named structs use by the application. Each struct field appears in the same order as ABI encoding. */
/** Named structs used by the application. Each struct field appears in the same order as ABI encoding. */

};
/** ARC-28 events that MAY be emitted by this contract */
events?: Array<Event>;
/** A mapping of template variable names as they appear in the teal (not including TMPL_ prefix) to their respective types and values (if applicable) */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** A mapping of template variable names as they appear in the teal (not including TMPL_ prefix) to their respective types and values (if applicable) */
/** A mapping of template variable names as they appear in the TEAL (not including TMPL_ prefix) to their respective types and values (if applicable) */

[name: string]: {
/** The type of the template variable */
type: ABIType | AVMType | StructName;
/** If given, the the base64 encoded value used for the given app/program */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** If given, the the base64 encoded value used for the given app/program */
/** If given, the base64 encoded value used for the given app/program */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants