Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
tzip
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
Tezos
tzip
Merge requests
!117
An error occurred while fetching the assigned milestone of the selected merge_request.
Draft: Dh@table of constants
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Draft: Dh@table of constants
marigold/tzip:dh@table-of-constants
into
master
Overview
68
Commits
27
Pipelines
13
Changes
1
Closed
Daniel Hines
requested to merge
marigold/tzip:dh@table-of-constants
into
master
4 years ago
Overview
68
Commits
27
Pipelines
13
Changes
1
Expand
0
0
Merge request reports
Compare
master
version 12
623dcb7b
3 years ago
version 11
c317e0c3
3 years ago
version 10
46864fc9
3 years ago
version 9
92a480e6
3 years ago
version 8
f9814b28
3 years ago
version 7
e5d2e06d
3 years ago
version 6
e9246a93
3 years ago
version 5
209ed668
3 years ago
version 4
c9596c02
3 years ago
version 3
0932bb7d
3 years ago
version 2
b979c1ab
4 years ago
version 1
3a5908e7
4 years ago
master (base)
and
latest version
latest version
8f69c829
27 commits,
3 years ago
version 12
623dcb7b
26 commits,
3 years ago
version 11
c317e0c3
23 commits,
3 years ago
version 10
46864fc9
21 commits,
3 years ago
version 9
92a480e6
20 commits,
3 years ago
version 8
f9814b28
9 commits,
3 years ago
version 7
e5d2e06d
8 commits,
3 years ago
version 6
e9246a93
7 commits,
3 years ago
version 5
209ed668
6 commits,
3 years ago
version 4
c9596c02
5 commits,
3 years ago
version 3
0932bb7d
4 commits,
3 years ago
version 2
b979c1ab
3 commits,
4 years ago
version 1
3a5908e7
1 commit,
4 years ago
1 file
+
100
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
drafts/current/draft-table-of-constants.md
0 → 100644
+
100
−
0
Options
---
title
:
Table of Micheline feature
status
:
Draft
author
:
realD4hines
type
:
L
created
:
2020-01-05
date
:
2021-01-05
version
:
0
---
## Summary
We propose adding a global table to the protocol for storing Michelson values,
accessible from any contract.
## Motivation
Contracts have a fixed upper size limit. Unfortunately, the current size limit
severely restricts the complexity of smart contracts, forcing users to resort to a
kind of Michelson code golf to compensate.
Our proposed solution to this problem is a shared table of Michelson values that
contracts can reference by hash, allowing users to factor large chunks of code
out of their contract. We expect the primary things to be factored out to be
lambdas and large types.
Factoring out lambdas and types has many benefits:
-
Globally available lambdas form libraries of reusable logic, enabling much
more complex applications to fit into the same size.
-
As the table becomes more widely adopted it serves as a reference of the
the most frequently reused functions. This supplies us with fine grained data to
further optimize the most heavily used contracts:
-
Large types for complex storages or parameters are often repeated throughout a
contract, taking up precious space. Referencing these types via constants
alleviates this problem.
## Specification
-
A new manager operation
`Register_global`
is created, which allows the user to
store a valid Micheline representation of a Michelson value in a
globally-accessible table and returns the hash of this value.
-
Expressions registered as constants may contain references to other constants.
However, the depth of a fully-expanded expression is constrained so as to not
exceed the depth of a contract that can be type checked (currently the typechecker
fails after 10,000 iterations.)
-
To prevent the need to iterate through deep chains of constants, the depth of
a constant is stored along with its value.
-
The storage table is implemented similarly to the existing one for
`big_map`
's, but is shared by all contracts instead of accessible only to
one.
-
A new Michelson primitive
`constant`
is added for referencing these values.
-
When applying a transaction, right before type elaboration, we substitute each
occurrence of a constant primitive with the value it points to in storage.
If no value is found, the transaction fails.
-
The typed Michelson IR has no knowledge of constants, and the Michelson type
elaborator and interpreter do not change in any way.
-
Users will be presented with several new
`tezos-client`
commands (we may add
others as we see the need):
-
`tezos-client register global constant <expression> from <src>`
Registers a new expression in the table.
-
`tezos-client get global constant <hash>`
Returns the value of the hash in the current context (if it exists).
-
`tezos-client expand constants in <contract>`
Substitutes every constant with its value in the current context (or
fails if a hash is not found).
## Backwards Compatibility
To the author's knowledge, the change does not break any existing functionality
and is only additive.
## Security Considerations
Once contracts are loading libraries, an obvious attack is to try to trick
developers into loading malicious libraries. Users must take care to use the
correct hash and review all the code they load into their contracts.
At the same time, libraries could improve security overall, since code be
audited and certified at the function level rather than the contract level. As a
user, I will find it easier to review 100 lines of logic that uses trusted
libraries than 1000 lines of in-lined code that does the same thing.
## Implementation
The global table of micheline is implemented in MR 2962: https://gitlab.com/tezos/tezos/-/merge_requests/2962
## Appendix
Much credit goes to Arthur Breitman's
[
post on the Agora
](
https://forum.tezosagora.org/t/global-constants/2025
)
and Tom Jack's insights and critiques.
## Copyright
Copyright and related rights waived via
[
CC0
](
https://creativecommons.org/publicdomain/zero/1.0/
)
.
Loading