mirror of
https://github.com/luxfi/precompile.git
synced 2026-07-27 03:33:45 +00:00
fix: gofmt -s across repo (CI format check)
This commit is contained in:
+36
-27
@@ -47,30 +47,34 @@ func (m *testStateDB) SetState(addr common.Address, key, val common.Hash) common
|
||||
return old
|
||||
}
|
||||
|
||||
func (m *testStateDB) SetNonce(common.Address, uint64, tracing.NonceChangeReason) {}
|
||||
func (m *testStateDB) GetNonce(common.Address) uint64 { return 0 }
|
||||
func (m *testStateDB) GetBalance(common.Address) *uint256.Int { return new(uint256.Int) }
|
||||
func (m *testStateDB) AddBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int { return uint256.Int{} }
|
||||
func (m *testStateDB) SubBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int { return uint256.Int{} }
|
||||
func (m *testStateDB) GetBalanceMultiCoin(common.Address, common.Hash) *big.Int { return big.NewInt(0) }
|
||||
func (m *testStateDB) AddBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *testStateDB) SubBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *testStateDB) CreateAccount(common.Address) {}
|
||||
func (m *testStateDB) Exist(common.Address) bool { return false }
|
||||
func (m *testStateDB) AddLog(*ethtypes.Log) {}
|
||||
func (m *testStateDB) Logs() []*ethtypes.Log { return nil }
|
||||
func (m *testStateDB) GetPredicateStorageSlots(common.Address, int) ([]byte, bool) { return nil, false }
|
||||
func (m *testStateDB) TxHash() common.Hash { return common.Hash{} }
|
||||
func (m *testStateDB) Snapshot() int { return 0 }
|
||||
func (m *testStateDB) RevertToSnapshot(int) {}
|
||||
func (m *testStateDB) SetNonce(common.Address, uint64, tracing.NonceChangeReason) {}
|
||||
func (m *testStateDB) GetNonce(common.Address) uint64 { return 0 }
|
||||
func (m *testStateDB) GetBalance(common.Address) *uint256.Int { return new(uint256.Int) }
|
||||
func (m *testStateDB) AddBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int {
|
||||
return uint256.Int{}
|
||||
}
|
||||
func (m *testStateDB) SubBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int {
|
||||
return uint256.Int{}
|
||||
}
|
||||
func (m *testStateDB) GetBalanceMultiCoin(common.Address, common.Hash) *big.Int { return big.NewInt(0) }
|
||||
func (m *testStateDB) AddBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *testStateDB) SubBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *testStateDB) CreateAccount(common.Address) {}
|
||||
func (m *testStateDB) Exist(common.Address) bool { return false }
|
||||
func (m *testStateDB) AddLog(*ethtypes.Log) {}
|
||||
func (m *testStateDB) Logs() []*ethtypes.Log { return nil }
|
||||
func (m *testStateDB) GetPredicateStorageSlots(common.Address, int) ([]byte, bool) { return nil, false }
|
||||
func (m *testStateDB) TxHash() common.Hash { return common.Hash{} }
|
||||
func (m *testStateDB) Snapshot() int { return 0 }
|
||||
func (m *testStateDB) RevertToSnapshot(int) {}
|
||||
|
||||
var _ contract.StateDB = (*testStateDB)(nil)
|
||||
|
||||
type testBlockCtx struct{}
|
||||
|
||||
func (t *testBlockCtx) Number() *big.Int { return big.NewInt(1) }
|
||||
func (t *testBlockCtx) Timestamp() uint64 { return 1000 }
|
||||
func (t *testBlockCtx) GetPredicateResults(common.Hash, common.Address) []byte { return nil }
|
||||
func (t *testBlockCtx) Number() *big.Int { return big.NewInt(1) }
|
||||
func (t *testBlockCtx) Timestamp() uint64 { return 1000 }
|
||||
func (t *testBlockCtx) GetPredicateResults(common.Hash, common.Address) []byte { return nil }
|
||||
|
||||
var _ contract.BlockContext = (*testBlockCtx)(nil)
|
||||
|
||||
@@ -90,11 +94,13 @@ type testAccessibleState struct {
|
||||
db *testStateDB
|
||||
}
|
||||
|
||||
func (t *testAccessibleState) GetStateDB() contract.StateDB { return t.db }
|
||||
func (t *testAccessibleState) GetBlockContext() contract.BlockContext { return &testBlockCtx{} }
|
||||
func (t *testAccessibleState) GetConsensusContext() context.Context { return context.Background() }
|
||||
func (t *testAccessibleState) GetChainConfig() precompileconfig.ChainConfig { return &testChainCfg{} }
|
||||
func (t *testAccessibleState) GetPrecompileEnv() contract.PrecompileEnvironment { return &testPrecompileEnv{} }
|
||||
func (t *testAccessibleState) GetStateDB() contract.StateDB { return t.db }
|
||||
func (t *testAccessibleState) GetBlockContext() contract.BlockContext { return &testBlockCtx{} }
|
||||
func (t *testAccessibleState) GetConsensusContext() context.Context { return context.Background() }
|
||||
func (t *testAccessibleState) GetChainConfig() precompileconfig.ChainConfig { return &testChainCfg{} }
|
||||
func (t *testAccessibleState) GetPrecompileEnv() contract.PrecompileEnvironment {
|
||||
return &testPrecompileEnv{}
|
||||
}
|
||||
|
||||
var _ contract.AccessibleState = (*testAccessibleState)(nil)
|
||||
|
||||
@@ -105,6 +111,7 @@ func newTestAS() *testAccessibleState {
|
||||
// --- Config tests ---
|
||||
|
||||
type fakeConfig struct{}
|
||||
|
||||
func (f *fakeConfig) Key() string { return "fake" }
|
||||
func (f *fakeConfig) Timestamp() *uint64 { return nil }
|
||||
func (f *fakeConfig) IsDisabled() bool { return false }
|
||||
@@ -286,7 +293,9 @@ func TestRunVerifyTEE(t *testing.T) {
|
||||
receipt := make([]byte, 48)
|
||||
binary.BigEndian.PutUint64(receipt[32:40], 1700000000)
|
||||
sig := make([]byte, 64)
|
||||
for i := range sig { sig[i] = byte(i + 1) }
|
||||
for i := range sig {
|
||||
sig[i] = byte(i + 1)
|
||||
}
|
||||
|
||||
data := make([]byte, 4+len(receipt)+4+len(sig))
|
||||
binary.BigEndian.PutUint32(data[:4], uint32(len(receipt)))
|
||||
@@ -387,8 +396,8 @@ func TestRunVerifyMLDSARealSig(t *testing.T) {
|
||||
|
||||
// Invalid signature length
|
||||
fakeData2 := make([]byte, 200)
|
||||
binary.BigEndian.PutUint32(fakeData2[:4], 10) // pkLen=10
|
||||
binary.BigEndian.PutUint32(fakeData2[14:18], 10) // msgLen=10
|
||||
binary.BigEndian.PutUint32(fakeData2[:4], 10) // pkLen=10
|
||||
binary.BigEndian.PutUint32(fakeData2[14:18], 10) // msgLen=10
|
||||
binary.BigEndian.PutUint32(fakeData2[28:32], 0xFFFF) // sigLen = huge
|
||||
fullFake2 := make([]byte, 4+len(fakeData2))
|
||||
binary.BigEndian.PutUint32(fullFake2[:4], SelectorVerifyMLDSA)
|
||||
|
||||
+25
-21
@@ -45,22 +45,26 @@ func (m *mockStateDB) SetState(addr common.Address, key, value common.Hash) comm
|
||||
}
|
||||
|
||||
// Stubs to satisfy contract.StateDB interface.
|
||||
func (m *mockStateDB) SetNonce(common.Address, uint64, tracing.NonceChangeReason) {}
|
||||
func (m *mockStateDB) GetNonce(common.Address) uint64 { return 0 }
|
||||
func (m *mockStateDB) GetBalance(common.Address) *uint256.Int { return new(uint256.Int) }
|
||||
func (m *mockStateDB) AddBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int { return uint256.Int{} }
|
||||
func (m *mockStateDB) SubBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int { return uint256.Int{} }
|
||||
func (m *mockStateDB) GetBalanceMultiCoin(common.Address, common.Hash) *big.Int { return big.NewInt(0) }
|
||||
func (m *mockStateDB) AddBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *mockStateDB) SubBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *mockStateDB) CreateAccount(common.Address) {}
|
||||
func (m *mockStateDB) Exist(common.Address) bool { return false }
|
||||
func (m *mockStateDB) AddLog(*ethtypes.Log) {}
|
||||
func (m *mockStateDB) Logs() []*ethtypes.Log { return nil }
|
||||
func (m *mockStateDB) GetPredicateStorageSlots(common.Address, int) ([]byte, bool) { return nil, false }
|
||||
func (m *mockStateDB) TxHash() common.Hash { return common.Hash{} }
|
||||
func (m *mockStateDB) Snapshot() int { return 0 }
|
||||
func (m *mockStateDB) RevertToSnapshot(int) {}
|
||||
func (m *mockStateDB) SetNonce(common.Address, uint64, tracing.NonceChangeReason) {}
|
||||
func (m *mockStateDB) GetNonce(common.Address) uint64 { return 0 }
|
||||
func (m *mockStateDB) GetBalance(common.Address) *uint256.Int { return new(uint256.Int) }
|
||||
func (m *mockStateDB) AddBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int {
|
||||
return uint256.Int{}
|
||||
}
|
||||
func (m *mockStateDB) SubBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int {
|
||||
return uint256.Int{}
|
||||
}
|
||||
func (m *mockStateDB) GetBalanceMultiCoin(common.Address, common.Hash) *big.Int { return big.NewInt(0) }
|
||||
func (m *mockStateDB) AddBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *mockStateDB) SubBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *mockStateDB) CreateAccount(common.Address) {}
|
||||
func (m *mockStateDB) Exist(common.Address) bool { return false }
|
||||
func (m *mockStateDB) AddLog(*ethtypes.Log) {}
|
||||
func (m *mockStateDB) Logs() []*ethtypes.Log { return nil }
|
||||
func (m *mockStateDB) GetPredicateStorageSlots(common.Address, int) ([]byte, bool) { return nil, false }
|
||||
func (m *mockStateDB) TxHash() common.Hash { return common.Hash{} }
|
||||
func (m *mockStateDB) Snapshot() int { return 0 }
|
||||
func (m *mockStateDB) RevertToSnapshot(int) {}
|
||||
|
||||
// --- mock AccessibleState ---
|
||||
|
||||
@@ -68,11 +72,11 @@ type mockAccessibleState struct {
|
||||
db *mockStateDB
|
||||
}
|
||||
|
||||
func (m *mockAccessibleState) GetStateDB() contract.StateDB { return m.db }
|
||||
func (m *mockAccessibleState) GetBlockContext() contract.BlockContext { return nil }
|
||||
func (m *mockAccessibleState) GetConsensusContext() context.Context { return context.Background() }
|
||||
func (m *mockAccessibleState) GetChainConfig() precompileconfig.ChainConfig { return nil }
|
||||
func (m *mockAccessibleState) GetPrecompileEnv() contract.PrecompileEnvironment { return nil }
|
||||
func (m *mockAccessibleState) GetStateDB() contract.StateDB { return m.db }
|
||||
func (m *mockAccessibleState) GetBlockContext() contract.BlockContext { return nil }
|
||||
func (m *mockAccessibleState) GetConsensusContext() context.Context { return context.Background() }
|
||||
func (m *mockAccessibleState) GetChainConfig() precompileconfig.ChainConfig { return nil }
|
||||
func (m *mockAccessibleState) GetPrecompileEnv() contract.PrecompileEnvironment { return nil }
|
||||
|
||||
// --- helpers ---
|
||||
|
||||
|
||||
+47
-30
@@ -29,50 +29,66 @@ func newTestStateDB() *testStateDB {
|
||||
}
|
||||
|
||||
func (m *testStateDB) GetState(addr common.Address, key common.Hash) common.Hash {
|
||||
if m.state[addr] == nil { return common.Hash{} }
|
||||
if m.state[addr] == nil {
|
||||
return common.Hash{}
|
||||
}
|
||||
return m.state[addr][key]
|
||||
}
|
||||
func (m *testStateDB) SetState(addr common.Address, key, val common.Hash) common.Hash {
|
||||
if m.state[addr] == nil { m.state[addr] = make(map[common.Hash]common.Hash) }
|
||||
old := m.state[addr][key]; m.state[addr][key] = val; return old
|
||||
if m.state[addr] == nil {
|
||||
m.state[addr] = make(map[common.Hash]common.Hash)
|
||||
}
|
||||
old := m.state[addr][key]
|
||||
m.state[addr][key] = val
|
||||
return old
|
||||
}
|
||||
func (m *testStateDB) SetNonce(common.Address, uint64, tracing.NonceChangeReason) {}
|
||||
func (m *testStateDB) GetNonce(common.Address) uint64 { return 0 }
|
||||
func (m *testStateDB) GetBalance(common.Address) *uint256.Int { return new(uint256.Int) }
|
||||
func (m *testStateDB) AddBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int { return uint256.Int{} }
|
||||
func (m *testStateDB) SubBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int { return uint256.Int{} }
|
||||
func (m *testStateDB) GetBalanceMultiCoin(common.Address, common.Hash) *big.Int { return big.NewInt(0) }
|
||||
func (m *testStateDB) AddBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *testStateDB) SubBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *testStateDB) CreateAccount(common.Address) {}
|
||||
func (m *testStateDB) Exist(common.Address) bool { return false }
|
||||
func (m *testStateDB) AddLog(*ethtypes.Log) {}
|
||||
func (m *testStateDB) Logs() []*ethtypes.Log { return nil }
|
||||
func (m *testStateDB) GetNonce(common.Address) uint64 { return 0 }
|
||||
func (m *testStateDB) GetBalance(common.Address) *uint256.Int { return new(uint256.Int) }
|
||||
func (m *testStateDB) AddBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int {
|
||||
return uint256.Int{}
|
||||
}
|
||||
func (m *testStateDB) SubBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int {
|
||||
return uint256.Int{}
|
||||
}
|
||||
func (m *testStateDB) GetBalanceMultiCoin(common.Address, common.Hash) *big.Int { return big.NewInt(0) }
|
||||
func (m *testStateDB) AddBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *testStateDB) SubBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *testStateDB) CreateAccount(common.Address) {}
|
||||
func (m *testStateDB) Exist(common.Address) bool { return false }
|
||||
func (m *testStateDB) AddLog(*ethtypes.Log) {}
|
||||
func (m *testStateDB) Logs() []*ethtypes.Log { return nil }
|
||||
func (m *testStateDB) GetPredicateStorageSlots(common.Address, int) ([]byte, bool) { return nil, false }
|
||||
func (m *testStateDB) TxHash() common.Hash { return common.Hash{} }
|
||||
func (m *testStateDB) Snapshot() int { return 0 }
|
||||
func (m *testStateDB) RevertToSnapshot(int) {}
|
||||
func (m *testStateDB) TxHash() common.Hash { return common.Hash{} }
|
||||
func (m *testStateDB) Snapshot() int { return 0 }
|
||||
func (m *testStateDB) RevertToSnapshot(int) {}
|
||||
|
||||
var _ contract.StateDB = (*testStateDB)(nil)
|
||||
|
||||
type testBlockCtx struct{}
|
||||
func (t *testBlockCtx) Number() *big.Int { return big.NewInt(1) }
|
||||
func (t *testBlockCtx) Timestamp() uint64 { return 1000 }
|
||||
|
||||
func (t *testBlockCtx) Number() *big.Int { return big.NewInt(1) }
|
||||
func (t *testBlockCtx) Timestamp() uint64 { return 1000 }
|
||||
func (t *testBlockCtx) GetPredicateResults(common.Hash, common.Address) []byte { return nil }
|
||||
|
||||
var _ contract.BlockContext = (*testBlockCtx)(nil)
|
||||
|
||||
type testChainCfg struct{}
|
||||
|
||||
func (t *testChainCfg) IsDurango(uint64) bool { return true }
|
||||
|
||||
type testPrecompileEnv struct{}
|
||||
|
||||
func (t *testPrecompileEnv) ReadOnly() bool { return false }
|
||||
|
||||
type testAS struct{ db *testStateDB }
|
||||
func (t *testAS) GetStateDB() contract.StateDB { return t.db }
|
||||
func (t *testAS) GetBlockContext() contract.BlockContext { return &testBlockCtx{} }
|
||||
func (t *testAS) GetConsensusContext() context.Context { return context.Background() }
|
||||
func (t *testAS) GetChainConfig() precompileconfig.ChainConfig { return &testChainCfg{} }
|
||||
|
||||
func (t *testAS) GetStateDB() contract.StateDB { return t.db }
|
||||
func (t *testAS) GetBlockContext() contract.BlockContext { return &testBlockCtx{} }
|
||||
func (t *testAS) GetConsensusContext() context.Context { return context.Background() }
|
||||
func (t *testAS) GetChainConfig() precompileconfig.ChainConfig { return &testChainCfg{} }
|
||||
func (t *testAS) GetPrecompileEnv() contract.PrecompileEnvironment { return &testPrecompileEnv{} }
|
||||
|
||||
var _ contract.AccessibleState = (*testAS)(nil)
|
||||
|
||||
func newTestAS() *testAS { return &testAS{db: newTestStateDB()} }
|
||||
@@ -88,10 +104,11 @@ func abiUint64(v uint64) []byte {
|
||||
// --- Config ---
|
||||
|
||||
type fakeConfig struct{}
|
||||
func (f *fakeConfig) Key() string { return "fake" }
|
||||
func (f *fakeConfig) Timestamp() *uint64 { return nil }
|
||||
func (f *fakeConfig) IsDisabled() bool { return false }
|
||||
func (f *fakeConfig) Equal(precompileconfig.Config) bool { return false }
|
||||
|
||||
func (f *fakeConfig) Key() string { return "fake" }
|
||||
func (f *fakeConfig) Timestamp() *uint64 { return nil }
|
||||
func (f *fakeConfig) IsDisabled() bool { return false }
|
||||
func (f *fakeConfig) Equal(precompileconfig.Config) bool { return false }
|
||||
func (f *fakeConfig) Verify(precompileconfig.ChainConfig) error { return nil }
|
||||
|
||||
func TestConfigLifecycle(t *testing.T) {
|
||||
@@ -192,8 +209,8 @@ func TestListToBeforeFrom(t *testing.T) {
|
||||
appID := [32]byte{0x01}
|
||||
data := make([]byte, 96)
|
||||
copy(data[:32], appID[:])
|
||||
binary.BigEndian.PutUint64(data[56:64], 10) // from=10
|
||||
binary.BigEndian.PutUint64(data[88:96], 5) // to=5 (invalid)
|
||||
binary.BigEndian.PutUint64(data[56:64], 10) // from=10
|
||||
binary.BigEndian.PutUint64(data[88:96], 5) // to=5 (invalid)
|
||||
input := append(selectorList, data...)
|
||||
_, _, err := p.Run(state, common.Address{}, ContractAddress, input, 100000, false)
|
||||
require.ErrorIs(t, err, ErrInputTooShort)
|
||||
@@ -206,7 +223,7 @@ func TestListRangeTooLarge(t *testing.T) {
|
||||
data := make([]byte, 96)
|
||||
copy(data[:32], appID[:])
|
||||
binary.BigEndian.PutUint64(data[56:64], 1) // from=1
|
||||
binary.BigEndian.PutUint64(data[88:96], 1000) // to=1000 (range=999 > 256)
|
||||
binary.BigEndian.PutUint64(data[88:96], 1000) // to=1000 (range=999 > 256)
|
||||
input := append(selectorList, data...)
|
||||
_, _, err := p.Run(state, common.Address{}, ContractAddress, input, 10000000, false)
|
||||
require.ErrorIs(t, err, ErrRangeTooLarge)
|
||||
|
||||
@@ -62,9 +62,9 @@ var (
|
||||
// Without this guard, concurrent writes would data-race and cause consensus
|
||||
// splits across validators.
|
||||
var (
|
||||
verifierMu sync.RWMutex
|
||||
globalVerifier = attestation.NewVerifier()
|
||||
nvtrustVerifier = attestation.NewNvtrustVerifier(attestation.DefaultNvtrustConfig())
|
||||
verifierMu sync.RWMutex
|
||||
globalVerifier = attestation.NewVerifier()
|
||||
nvtrustVerifier = attestation.NewNvtrustVerifier(attestation.DefaultNvtrustConfig())
|
||||
)
|
||||
|
||||
// VerifyNVTrustInput represents input for GPU attestation verification
|
||||
|
||||
+15
-14
@@ -11,24 +11,25 @@
|
||||
// This precompile operates on Baby Jubjub in the REDUCED twisted Edwards
|
||||
// form used by circom, iden3, Polygon zkEVM, and gnark-crypto:
|
||||
//
|
||||
// a' x^2 + y^2 = 1 + d' x^2 y^2 over F_r (r = BN254 scalar order)
|
||||
// a' = -1
|
||||
// d' = 12181644023421730124874158521699555681764249180949974110617291017600649128846
|
||||
// Base B' = (
|
||||
// 9671717474070082183213120605117400219616337014328744928644933853176787189663,
|
||||
// 16950150798460657717958625567821834550301663161624707787222815936182638968203
|
||||
// )
|
||||
// a' x^2 + y^2 = 1 + d' x^2 y^2 over F_r (r = BN254 scalar order)
|
||||
// a' = -1
|
||||
// d' = 12181644023421730124874158521699555681764249180949974110617291017600649128846
|
||||
// Base B' = (
|
||||
// 9671717474070082183213120605117400219616337014328744928644933853176787189663,
|
||||
// 16950150798460657717958625567821834550301663161624707787222815936182638968203
|
||||
// )
|
||||
//
|
||||
// EIP-2494 defines Baby Jubjub primarily in the STANDARD twisted Edwards
|
||||
// form (a=168700, d=168696, base (5299..., 16950...)). The two forms are
|
||||
// birationally equivalent via the scaling factor
|
||||
//
|
||||
// f = 6360561867910373094066688120553762416144456282423235903351243436111059670888
|
||||
// -f = 15527681003928902128179717624703512672403908117992798440346960750464748824729
|
||||
// f = 6360561867910373094066688120553762416144456282423235903351243436111059670888
|
||||
// -f = 15527681003928902128179717624703512672403908117992798440346960750464748824729
|
||||
//
|
||||
// Standard (x, y) <-> Reduced (x', y'):
|
||||
// x' = x * (-f) mod r
|
||||
// y' = y
|
||||
//
|
||||
// x' = x * (-f) mod r
|
||||
// y' = y
|
||||
//
|
||||
// Callers that produce points in EIP-2494 standard form MUST convert to
|
||||
// reduced form before submitting to this precompile. The conversion is
|
||||
@@ -64,9 +65,9 @@ var (
|
||||
|
||||
_ contract.StatefulPrecompiledContract = &babyJubJubPrecompile{}
|
||||
|
||||
ErrInvalidInput = contract.ErrInvalidInput
|
||||
ErrInvalidOp = errors.New("invalid babyjubjub operation")
|
||||
ErrNotOnCurve = errors.New("point not on baby jubjub curve")
|
||||
ErrInvalidInput = contract.ErrInvalidInput
|
||||
ErrInvalidOp = errors.New("invalid babyjubjub operation")
|
||||
ErrNotOnCurve = errors.New("point not on baby jubjub curve")
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -22,12 +22,15 @@ func TestPrecompileAddress(t *testing.T) {
|
||||
// gnark-crypto. This is the iden3/circom/Polygon-zkEVM convention.
|
||||
//
|
||||
// Reduced form (a = -1):
|
||||
// Bx' = 9671717474070082183213120605117400219616337014328744928644933853176787189663
|
||||
// By' = 16950150798460657717958625567821834550301663161624707787222815936182638968203
|
||||
//
|
||||
// Bx' = 9671717474070082183213120605117400219616337014328744928644933853176787189663
|
||||
// By' = 16950150798460657717958625567821834550301663161624707787222815936182638968203
|
||||
//
|
||||
// The equivalent EIP-2494 STANDARD form base point (a = 168700) is:
|
||||
// Bx = 5299619240641551281634865583518297030282874472190772894086521144482721001553
|
||||
// By = 16950150798460657717958625567821834550301663161624707787222815936182638968203
|
||||
//
|
||||
// Bx = 5299619240641551281634865583518297030282874472190772894086521144482721001553
|
||||
// By = 16950150798460657717958625567821834550301663161624707787222815936182638968203
|
||||
//
|
||||
// and the conversion is Bx' = Bx * (-f) mod r (y is unchanged).
|
||||
// See TestEIP2494_ConversionStandardToReduced and the package doc comment.
|
||||
func getGenerator() twistededwards.PointAffine {
|
||||
@@ -196,8 +199,8 @@ func TestInCurve_InvalidPoint(t *testing.T) {
|
||||
// (1, 1) is not on the Baby Jubjub curve
|
||||
input := make([]byte, 1+PointLen)
|
||||
input[0] = OpInCurve
|
||||
input[32] = 1 // x = 1
|
||||
input[64] = 1 // y = 1
|
||||
input[32] = 1 // x = 1
|
||||
input[64] = 1 // y = 1
|
||||
|
||||
gas := p.RequiredGas(input)
|
||||
ret, _, err := p.Run(nil, common.Address{}, ContractAddress, input, gas, true)
|
||||
@@ -235,8 +238,8 @@ func TestPointAdd_PointNotOnCurve(t *testing.T) {
|
||||
genBytes := encodeTestPoint(&gen)
|
||||
|
||||
bogus := make([]byte, PointLen)
|
||||
bogus[31] = 2 // x = 2
|
||||
bogus[63] = 3 // y = 3
|
||||
bogus[31] = 2 // x = 2
|
||||
bogus[63] = 3 // y = 3
|
||||
|
||||
input := make([]byte, 1+2*PointLen)
|
||||
input[0] = OpPointAdd
|
||||
|
||||
@@ -37,7 +37,8 @@ var rBN254, _ = new(big.Int).SetString(
|
||||
// negF is the scaling constant (−f mod r) that maps standard-form
|
||||
// Baby Jubjub to reduced-form Baby Jubjub.
|
||||
// EIP-2494: f = 6360561867910373094066688120553762416144456282423235903351243436111059670888
|
||||
// −f = r − f = 15527681003928902128179717624703512672403908117992798440346960750464748824729
|
||||
//
|
||||
// −f = r − f = 15527681003928902128179717624703512672403908117992798440346960750464748824729
|
||||
var negF, _ = new(big.Int).SetString(
|
||||
"15527681003928902128179717624703512672403908117992798440346960750464748824729", 10,
|
||||
)
|
||||
|
||||
@@ -33,6 +33,7 @@ import (
|
||||
_ "github.com/luxfi/precompile/dead"
|
||||
_ "github.com/luxfi/precompile/dex"
|
||||
// REMOVED: ecies — secret keys in calldata are public on-chain
|
||||
_ "github.com/luxfi/precompile/corona"
|
||||
_ "github.com/luxfi/precompile/fhe"
|
||||
_ "github.com/luxfi/precompile/frost"
|
||||
_ "github.com/luxfi/precompile/graph"
|
||||
@@ -40,7 +41,6 @@ import (
|
||||
_ "github.com/luxfi/precompile/mldsa"
|
||||
_ "github.com/luxfi/precompile/mlkem"
|
||||
_ "github.com/luxfi/precompile/ring"
|
||||
_ "github.com/luxfi/precompile/corona"
|
||||
_ "github.com/luxfi/precompile/slhdsa"
|
||||
_ "github.com/luxfi/precompile/sr25519"
|
||||
_ "github.com/luxfi/precompile/zk"
|
||||
@@ -97,9 +97,9 @@ func lux_precompile_run(
|
||||
// Precompiles that need state (DEX, AI mining, dead) will panic on nil state;
|
||||
// recover and return -3 (needs state) to distinguish from execution errors.
|
||||
var (
|
||||
ret []byte
|
||||
gasLeft uint64
|
||||
runErr error
|
||||
ret []byte
|
||||
gasLeft uint64
|
||||
runErr error
|
||||
panicked bool
|
||||
)
|
||||
func() {
|
||||
|
||||
+9
-9
@@ -81,16 +81,16 @@ const (
|
||||
|
||||
// Errors.
|
||||
var (
|
||||
ErrRegistrarInputTooShort = errors.New("registrar: input too short")
|
||||
ErrRegistrarInputTooShort = errors.New("registrar: input too short")
|
||||
ErrRegistrarUnknownSelector = errors.New("registrar: unknown selector")
|
||||
ErrRegistrarReadOnly = errors.New("registrar: write in read-only mode")
|
||||
ErrAlreadyRegistered = errors.New("registrar: chain already registered")
|
||||
ErrNotRegistered = errors.New("registrar: chain not registered")
|
||||
ErrIndexOutOfRange = errors.New("registrar: index out of range")
|
||||
ErrUnauthorized = errors.New("registrar: threshold not met")
|
||||
ErrInvalidSignatureBytes = errors.New("registrar: invalid signature bytes")
|
||||
ErrDuplicateSigner = errors.New("registrar: duplicate signer in signature set")
|
||||
ErrChainNameTooLong = errors.New("registrar: chain name exceeds max length")
|
||||
ErrRegistrarReadOnly = errors.New("registrar: write in read-only mode")
|
||||
ErrAlreadyRegistered = errors.New("registrar: chain already registered")
|
||||
ErrNotRegistered = errors.New("registrar: chain not registered")
|
||||
ErrIndexOutOfRange = errors.New("registrar: index out of range")
|
||||
ErrUnauthorized = errors.New("registrar: threshold not met")
|
||||
ErrInvalidSignatureBytes = errors.New("registrar: invalid signature bytes")
|
||||
ErrDuplicateSigner = errors.New("registrar: duplicate signer in signature set")
|
||||
ErrChainNameTooLong = errors.New("registrar: chain name exceeds max length")
|
||||
)
|
||||
|
||||
// ABI arg sizes for RegisterChain.
|
||||
|
||||
+10
-10
@@ -51,15 +51,15 @@ func (m *regStateDB) SetState(a common.Address, k, v common.Hash) common.Hash {
|
||||
}
|
||||
|
||||
func (*regStateDB) SetNonce(common.Address, uint64, tracing.NonceChangeReason) {}
|
||||
func (*regStateDB) GetNonce(common.Address) uint64 { return 0 }
|
||||
func (*regStateDB) GetBalance(common.Address) *uint256.Int { return new(uint256.Int) }
|
||||
func (*regStateDB) GetNonce(common.Address) uint64 { return 0 }
|
||||
func (*regStateDB) GetBalance(common.Address) *uint256.Int { return new(uint256.Int) }
|
||||
func (*regStateDB) AddBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int {
|
||||
return uint256.Int{}
|
||||
}
|
||||
func (*regStateDB) SubBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int {
|
||||
return uint256.Int{}
|
||||
}
|
||||
func (*regStateDB) GetBalanceMultiCoin(common.Address, common.Hash) *big.Int { return big.NewInt(0) }
|
||||
func (*regStateDB) GetBalanceMultiCoin(common.Address, common.Hash) *big.Int { return big.NewInt(0) }
|
||||
func (*regStateDB) AddBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (*regStateDB) SubBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (*regStateDB) CreateAccount(common.Address) {}
|
||||
@@ -77,9 +77,9 @@ var _ contract.StateDB = (*regStateDB)(nil)
|
||||
|
||||
type regBlockCtx struct{}
|
||||
|
||||
func (*regBlockCtx) Number() *big.Int { return big.NewInt(1) }
|
||||
func (*regBlockCtx) Timestamp() uint64 { return 1700000000 }
|
||||
func (*regBlockCtx) GetPredicateResults(common.Hash, common.Address) []byte { return nil }
|
||||
func (*regBlockCtx) Number() *big.Int { return big.NewInt(1) }
|
||||
func (*regBlockCtx) Timestamp() uint64 { return 1700000000 }
|
||||
func (*regBlockCtx) GetPredicateResults(common.Hash, common.Address) []byte { return nil }
|
||||
|
||||
type regChainCfg struct{}
|
||||
|
||||
@@ -91,10 +91,10 @@ func (*regEnv) ReadOnly() bool { return false }
|
||||
|
||||
type regAS struct{ db *regStateDB }
|
||||
|
||||
func (a *regAS) GetStateDB() contract.StateDB { return a.db }
|
||||
func (a *regAS) GetBlockContext() contract.BlockContext { return ®BlockCtx{} }
|
||||
func (a *regAS) GetConsensusContext() context.Context { return context.Background() }
|
||||
func (a *regAS) GetChainConfig() precompileconfig.ChainConfig { return ®ChainCfg{} }
|
||||
func (a *regAS) GetStateDB() contract.StateDB { return a.db }
|
||||
func (a *regAS) GetBlockContext() contract.BlockContext { return ®BlockCtx{} }
|
||||
func (a *regAS) GetConsensusContext() context.Context { return context.Background() }
|
||||
func (a *regAS) GetChainConfig() precompileconfig.ChainConfig { return ®ChainCfg{} }
|
||||
func (a *regAS) GetPrecompileEnv() contract.PrecompileEnvironment { return ®Env{} }
|
||||
|
||||
func newRegAS() *regAS { return ®AS{db: newRegState()} }
|
||||
|
||||
@@ -65,16 +65,16 @@ func (*memStateDB) AddBalanceMultiCoin(common.Address, common.Hash, *big.Int) {
|
||||
func (*memStateDB) SubBalanceMultiCoin(common.Address, common.Hash, *big.Int) {
|
||||
panic("not implemented")
|
||||
}
|
||||
func (*memStateDB) CreateAccount(common.Address) { panic("not implemented") }
|
||||
func (*memStateDB) Exist(common.Address) bool { panic("not implemented") }
|
||||
func (*memStateDB) AddLog(*ethtypes.Log) { panic("not implemented") }
|
||||
func (*memStateDB) Logs() []*ethtypes.Log { panic("not implemented") }
|
||||
func (*memStateDB) CreateAccount(common.Address) { panic("not implemented") }
|
||||
func (*memStateDB) Exist(common.Address) bool { panic("not implemented") }
|
||||
func (*memStateDB) AddLog(*ethtypes.Log) { panic("not implemented") }
|
||||
func (*memStateDB) Logs() []*ethtypes.Log { panic("not implemented") }
|
||||
func (*memStateDB) GetPredicateStorageSlots(common.Address, int) ([]byte, bool) {
|
||||
panic("not implemented")
|
||||
}
|
||||
func (*memStateDB) TxHash() common.Hash { panic("not implemented") }
|
||||
func (*memStateDB) Snapshot() int { panic("not implemented") }
|
||||
func (*memStateDB) RevertToSnapshot(int) { panic("not implemented") }
|
||||
func (*memStateDB) TxHash() common.Hash { panic("not implemented") }
|
||||
func (*memStateDB) Snapshot() int { panic("not implemented") }
|
||||
func (*memStateDB) RevertToSnapshot(int) { panic("not implemented") }
|
||||
|
||||
func TestStaticRegistry_GetAndAll(t *testing.T) {
|
||||
r := NewStatic(DefaultSeed())
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
)
|
||||
|
||||
type fakeConfig struct{}
|
||||
|
||||
func (f *fakeConfig) Key() string { return "fake" }
|
||||
func (f *fakeConfig) Timestamp() *uint64 { return nil }
|
||||
func (f *fakeConfig) IsDisabled() bool { return false }
|
||||
@@ -18,6 +19,7 @@ func (f *fakeConfig) Equal(precompileconfig.Config) bool { return false }
|
||||
func (f *fakeConfig) Verify(precompileconfig.ChainConfig) error { return nil }
|
||||
|
||||
type testChainCfg struct{}
|
||||
|
||||
func (t *testChainCfg) IsDurango(uint64) bool { return true }
|
||||
|
||||
func TestConfigLifecycle(t *testing.T) {
|
||||
|
||||
@@ -15,9 +15,10 @@ import (
|
||||
//
|
||||
// Vulnerability: The gas calculation was CGGMP21VerifyBaseGas + totalSigners * CGGMP21VerifyPerSignerGas
|
||||
// where totalSigners is a uint32 read from calldata. With totalSigners = 0xFFFFFFFF:
|
||||
// 0xFFFFFFFF * 10_000 = 42_949_672_950_000 which overflows uint64? No, but it
|
||||
// produces an absurdly high gas cost (42.9 trillion) that a malicious caller
|
||||
// could use to cause unexpected behavior in gas estimation or accounting.
|
||||
//
|
||||
// 0xFFFFFFFF * 10_000 = 42_949_672_950_000 which overflows uint64? No, but it
|
||||
// produces an absurdly high gas cost (42.9 trillion) that a malicious caller
|
||||
// could use to cause unexpected behavior in gas estimation or accounting.
|
||||
//
|
||||
// Fix: Cap totalSigners at a reasonable maximum (e.g., 256) and/or cap total
|
||||
// gas to a reasonable maximum. Gas must never exceed block gas limit equivalent.
|
||||
|
||||
+9
-8
@@ -12,14 +12,15 @@
|
||||
// - 0x05: GetPrice(modelHash, inputSize) -> price in wei
|
||||
//
|
||||
// Storage layout (all keyed under ContractAddress):
|
||||
// keccak256("provider", providerID) -> gpuType (32 bytes)
|
||||
// keccak256("provider.owner", providerID) -> owner address
|
||||
// keccak256("job", jobID) -> modelHash
|
||||
// keccak256("job.provider", jobID) -> provider address
|
||||
// keccak256("job.price", jobID) -> maxPrice
|
||||
// keccak256("job.status", jobID) -> status (0=open, 1=claimed, 2=verified)
|
||||
// keccak256("job.output", jobID) -> outputHash
|
||||
// keccak256("nonce", address) -> provider nonce
|
||||
//
|
||||
// keccak256("provider", providerID) -> gpuType (32 bytes)
|
||||
// keccak256("provider.owner", providerID) -> owner address
|
||||
// keccak256("job", jobID) -> modelHash
|
||||
// keccak256("job.provider", jobID) -> provider address
|
||||
// keccak256("job.price", jobID) -> maxPrice
|
||||
// keccak256("job.status", jobID) -> status (0=open, 1=claimed, 2=verified)
|
||||
// keccak256("job.output", jobID) -> outputHash
|
||||
// keccak256("nonce", address) -> provider nonce
|
||||
//
|
||||
// Gas: 25,000 register, 10,000 submit, 50,000 verify, 5,000 claim/getPrice
|
||||
package compute
|
||||
|
||||
+29
-21
@@ -285,22 +285,26 @@ func (m *mockStateDB) SetState(addr common.Address, key, value common.Hash) comm
|
||||
return prev
|
||||
}
|
||||
|
||||
func (m *mockStateDB) GetBalance(common.Address) *uint256.Int { return uint256.NewInt(0) }
|
||||
func (m *mockStateDB) AddBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int { return uint256.Int{} }
|
||||
func (m *mockStateDB) SubBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int { return uint256.Int{} }
|
||||
func (m *mockStateDB) GetBalanceMultiCoin(common.Address, common.Hash) *big.Int { return big.NewInt(0) }
|
||||
func (m *mockStateDB) AddBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *mockStateDB) SubBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *mockStateDB) SetNonce(common.Address, uint64, tracing.NonceChangeReason) {}
|
||||
func (m *mockStateDB) GetNonce(common.Address) uint64 { return 0 }
|
||||
func (m *mockStateDB) CreateAccount(common.Address) {}
|
||||
func (m *mockStateDB) Exist(common.Address) bool { return true }
|
||||
func (m *mockStateDB) AddLog(*ethtypes.Log) {}
|
||||
func (m *mockStateDB) Logs() []*ethtypes.Log { return nil }
|
||||
func (m *mockStateDB) GetPredicateStorageSlots(common.Address, int) ([]byte, bool) { return nil, false }
|
||||
func (m *mockStateDB) TxHash() common.Hash { return common.Hash{} }
|
||||
func (m *mockStateDB) Snapshot() int { return 0 }
|
||||
func (m *mockStateDB) RevertToSnapshot(int) {}
|
||||
func (m *mockStateDB) GetBalance(common.Address) *uint256.Int { return uint256.NewInt(0) }
|
||||
func (m *mockStateDB) AddBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int {
|
||||
return uint256.Int{}
|
||||
}
|
||||
func (m *mockStateDB) SubBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int {
|
||||
return uint256.Int{}
|
||||
}
|
||||
func (m *mockStateDB) GetBalanceMultiCoin(common.Address, common.Hash) *big.Int { return big.NewInt(0) }
|
||||
func (m *mockStateDB) AddBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *mockStateDB) SubBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (m *mockStateDB) SetNonce(common.Address, uint64, tracing.NonceChangeReason) {}
|
||||
func (m *mockStateDB) GetNonce(common.Address) uint64 { return 0 }
|
||||
func (m *mockStateDB) CreateAccount(common.Address) {}
|
||||
func (m *mockStateDB) Exist(common.Address) bool { return true }
|
||||
func (m *mockStateDB) AddLog(*ethtypes.Log) {}
|
||||
func (m *mockStateDB) Logs() []*ethtypes.Log { return nil }
|
||||
func (m *mockStateDB) GetPredicateStorageSlots(common.Address, int) ([]byte, bool) { return nil, false }
|
||||
func (m *mockStateDB) TxHash() common.Hash { return common.Hash{} }
|
||||
func (m *mockStateDB) Snapshot() int { return 0 }
|
||||
func (m *mockStateDB) RevertToSnapshot(int) {}
|
||||
|
||||
type mockBlockContext struct{}
|
||||
|
||||
@@ -324,8 +328,12 @@ func newMockState() *mockAccessibleState {
|
||||
return &mockAccessibleState{stateDB: newMockStateDB()}
|
||||
}
|
||||
|
||||
func (m *mockAccessibleState) GetStateDB() contract.StateDB { return m.stateDB }
|
||||
func (m *mockAccessibleState) GetBlockContext() contract.BlockContext { return &mockBlockContext{} }
|
||||
func (m *mockAccessibleState) GetConsensusContext() context.Context { return context.Background() }
|
||||
func (m *mockAccessibleState) GetChainConfig() precompileconfig.ChainConfig { return &mockChainConfig{} }
|
||||
func (m *mockAccessibleState) GetPrecompileEnv() contract.PrecompileEnvironment { return &mockPrecompileEnv{} }
|
||||
func (m *mockAccessibleState) GetStateDB() contract.StateDB { return m.stateDB }
|
||||
func (m *mockAccessibleState) GetBlockContext() contract.BlockContext { return &mockBlockContext{} }
|
||||
func (m *mockAccessibleState) GetConsensusContext() context.Context { return context.Background() }
|
||||
func (m *mockAccessibleState) GetChainConfig() precompileconfig.ChainConfig {
|
||||
return &mockChainConfig{}
|
||||
}
|
||||
func (m *mockAccessibleState) GetPrecompileEnv() contract.PrecompileEnvironment {
|
||||
return &mockPrecompileEnv{}
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
// Shared error sentinels for all precompiles.
|
||||
var (
|
||||
ErrOutOfGas = errors.New("out of gas")
|
||||
ErrOutOfGas = errors.New("out of gas")
|
||||
ErrInvalidInput = errors.New("invalid input")
|
||||
ErrInvalidOp = errors.New("invalid operation")
|
||||
)
|
||||
|
||||
+3
-3
@@ -10,12 +10,12 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/luxfi/corona/sign"
|
||||
"github.com/luxfi/corona/threshold"
|
||||
"github.com/luxfi/geth/common"
|
||||
"github.com/luxfi/lattice/v7/ring"
|
||||
"github.com/luxfi/lattice/v7/utils/structs"
|
||||
"github.com/luxfi/precompile/contract"
|
||||
"github.com/luxfi/corona/sign"
|
||||
"github.com/luxfi/corona/threshold"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -29,7 +29,7 @@ var (
|
||||
|
||||
_ contract.StatefulPrecompiledContract = &coronaThresholdPrecompile{}
|
||||
|
||||
ErrInvalidInputLength = contract.ErrInvalidInput
|
||||
ErrInvalidInputLength = contract.ErrInvalidInput
|
||||
ErrInvalidThreshold = errors.New("invalid threshold: t must be > 0 and <= n")
|
||||
ErrInvalidSignature = errors.New("signature verification failed")
|
||||
ErrInsufficientParties = errors.New("insufficient parties for threshold")
|
||||
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/luxfi/corona/sign"
|
||||
"github.com/luxfi/corona/threshold"
|
||||
"github.com/luxfi/geth/common"
|
||||
"github.com/luxfi/lattice/v7/ring"
|
||||
"github.com/luxfi/precompile/contract"
|
||||
"github.com/luxfi/corona/sign"
|
||||
"github.com/luxfi/corona/threshold"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
)
|
||||
|
||||
type fakeConfig struct{}
|
||||
|
||||
func (f *fakeConfig) Key() string { return "fake" }
|
||||
func (f *fakeConfig) Timestamp() *uint64 { return nil }
|
||||
func (f *fakeConfig) IsDisabled() bool { return false }
|
||||
@@ -18,6 +19,7 @@ func (f *fakeConfig) Equal(precompileconfig.Config) bool { return false }
|
||||
func (f *fakeConfig) Verify(precompileconfig.ChainConfig) error { return nil }
|
||||
|
||||
type testChainCfg struct{}
|
||||
|
||||
func (t *testChainCfg) IsDurango(uint64) bool { return true }
|
||||
|
||||
func TestConfigLifecycle(t *testing.T) {
|
||||
|
||||
@@ -386,7 +386,7 @@ func (e *EmbeddedEngine) Quote(pool *Pool, amountIn *big.Int, zeroForOne bool) *
|
||||
sqrtPriceLimitX96,
|
||||
pool.Liquidity,
|
||||
new(big.Int).Neg(amountIn), // exact input convention
|
||||
3000, // default fee
|
||||
3000, // default fee
|
||||
)
|
||||
return new(big.Int).Abs(step.AmountOut)
|
||||
}
|
||||
|
||||
@@ -20,10 +20,10 @@ var settlementAddr = common.HexToAddress(LXSettlementAddress)
|
||||
// Gas costs for Settlement operations
|
||||
const (
|
||||
GasFillAttestation uint64 = 30_000 // Record a broker fill attestation
|
||||
GasFillChallenge uint64 = 50_000 // Challenge an attestation (reversal)
|
||||
GasFillFinalize uint64 = 20_000 // Finalize after fraud window
|
||||
GasFillQuery uint64 = 5_000 // Query attestation state
|
||||
GasFillSetAdmin uint64 = 25_000 // Set attester or ceiling (governance)
|
||||
GasFillChallenge uint64 = 50_000 // Challenge an attestation (reversal)
|
||||
GasFillFinalize uint64 = 20_000 // Finalize after fraud window
|
||||
GasFillQuery uint64 = 5_000 // Query attestation state
|
||||
GasFillSetAdmin uint64 = 25_000 // Set attester or ceiling (governance)
|
||||
)
|
||||
|
||||
// FillStatus tracks the lifecycle of a fill attestation.
|
||||
@@ -54,11 +54,11 @@ type Settlement struct {
|
||||
|
||||
// Storage key prefixes for Settlement state
|
||||
var (
|
||||
fillAttestPrefix = []byte("fill_attestation/attest/") // per-order attestation
|
||||
fillConfigPrefix = []byte("fill_attestation/config/") // global config
|
||||
fillAttesterKey = []byte("fill_attestation/attester") // authorized attester address
|
||||
fillCeilingKey = []byte("fill_attestation/ceiling") // max outstanding USD value
|
||||
fillOutstandingKey = []byte("fill_attestation/outstanding") // current outstanding USD
|
||||
fillAttestPrefix = []byte("fill_attestation/attest/") // per-order attestation
|
||||
fillConfigPrefix = []byte("fill_attestation/config/") // global config
|
||||
fillAttesterKey = []byte("fill_attestation/attester") // authorized attester address
|
||||
fillCeilingKey = []byte("fill_attestation/ceiling") // max outstanding USD value
|
||||
fillOutstandingKey = []byte("fill_attestation/outstanding") // current outstanding USD
|
||||
fillFraudWindowKey = []byte("fill_attestation/fraud_window") // fraud window in blocks
|
||||
)
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ func TestFillAttestationAttest(t *testing.T) {
|
||||
|
||||
orderID := OrderIDFromString("alpaca-order-12345")
|
||||
symbol := SymbolToBytes32("AAPL")
|
||||
amount := big.NewInt(100) // 100 shares
|
||||
price := new(big.Int).Mul(big.NewInt(175), big.NewInt(1e18)) // $175/share
|
||||
amount := big.NewInt(100) // 100 shares
|
||||
price := new(big.Int).Mul(big.NewInt(175), big.NewInt(1e18)) // $175/share
|
||||
|
||||
// Attest
|
||||
err := mgr.Attest(stateDB, attester, orderID, symbol, amount, price, user, 1711036800)
|
||||
|
||||
@@ -125,7 +125,7 @@ func (m *mockEngine) ModifyLiquidity(pool *PoolState, owner common.Address, para
|
||||
if !ok {
|
||||
pos = &Position{
|
||||
Owner: owner, TickLower: params.TickLower, TickUpper: params.TickUpper,
|
||||
Liquidity: big.NewInt(0),
|
||||
Liquidity: big.NewInt(0),
|
||||
FeeGrowthInside0LastX128: big.NewInt(0), FeeGrowthInside1LastX128: big.NewInt(0),
|
||||
TokensOwed0: big.NewInt(0), TokensOwed1: big.NewInt(0),
|
||||
}
|
||||
|
||||
@@ -229,4 +229,3 @@ func msb256(x *big.Int) int {
|
||||
}
|
||||
return x.BitLen() - 1
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -36,7 +36,7 @@ const (
|
||||
LXPriceAddress = "0x0000000000000000000000000000000000009040" // LP-9040 LXPrice (derived/computed pricing)
|
||||
|
||||
// Lending (LP-905x–906x)
|
||||
LXLendAddress = "0x0000000000000000000000000000000000009050" // LP-9050 LXLend (lending pool)
|
||||
LXLendAddress = "0x0000000000000000000000000000000000009050" // LP-9050 LXLend (lending pool)
|
||||
LXRepayerAddress = "0x0000000000000000000000000000000000009060" // LP-9060 LXRepayer (self-repaying loans)
|
||||
|
||||
// Liquidation + Transmutation (LP-907x–908x)
|
||||
@@ -45,7 +45,7 @@ const (
|
||||
|
||||
// Settlement (LP-909x)
|
||||
// LXSettlementAddress is defined in fill_attestation.go // LP-9090 LXSettlement (settlement attestation)
|
||||
LiquidFXAddress = LXTransmuterAddress
|
||||
LiquidFXAddress = LXTransmuterAddress
|
||||
|
||||
// Bridge Precompiles (LP-6xxx)
|
||||
TeleportAddress = "0x0000000000000000000000000000000000006010" // LP-6010 Teleport (cross-chain)
|
||||
@@ -376,11 +376,11 @@ var (
|
||||
// every Foundry user's ~/.foundry — any random caller could pause /
|
||||
// freeze the chain-wide AMM. Activation fails closed.
|
||||
ErrDEXCompromisedController = errors.New("dex: protocolFeeController is a publicly-known dev key — refusing to activate")
|
||||
ErrInvalidHookResponse = errors.New("invalid hook response")
|
||||
ErrSettlementFailed = errors.New("settlement failed")
|
||||
ErrInvalidSqrtPrice = errors.New("invalid sqrt price")
|
||||
ErrTickOutOfRange = errors.New("tick out of range")
|
||||
ErrNoLiquidity = errors.New("no liquidity in pool")
|
||||
ErrInvalidHookResponse = errors.New("invalid hook response")
|
||||
ErrSettlementFailed = errors.New("settlement failed")
|
||||
ErrInvalidSqrtPrice = errors.New("invalid sqrt price")
|
||||
ErrTickOutOfRange = errors.New("tick out of range")
|
||||
ErrNoLiquidity = errors.New("no liquidity in pool")
|
||||
)
|
||||
|
||||
// Errors - Pause/Freeze Controls (ATS regulatory compliance)
|
||||
|
||||
@@ -159,8 +159,8 @@ type MockBlockContext struct {
|
||||
BlockTimestamp uint64
|
||||
}
|
||||
|
||||
func (b *MockBlockContext) Number() *big.Int { return b.BlockNumber }
|
||||
func (b *MockBlockContext) Timestamp() uint64 { return b.BlockTimestamp }
|
||||
func (b *MockBlockContext) Number() *big.Int { return b.BlockNumber }
|
||||
func (b *MockBlockContext) Timestamp() uint64 { return b.BlockTimestamp }
|
||||
func (b *MockBlockContext) GetPredicateResults(common.Hash, common.Address) []byte {
|
||||
return nil
|
||||
}
|
||||
@@ -188,8 +188,8 @@ func NewMockAccessibleState() *MockAccessibleState {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *MockAccessibleState) GetStateDB() contract.StateDB { return s.DB }
|
||||
func (s *MockAccessibleState) GetBlockContext() contract.BlockContext { return s.Block }
|
||||
func (s *MockAccessibleState) GetConsensusContext() context.Context { return context.Background() }
|
||||
func (s *MockAccessibleState) GetChainConfig() precompileconfig.ChainConfig { return s.Chain }
|
||||
func (s *MockAccessibleState) GetStateDB() contract.StateDB { return s.DB }
|
||||
func (s *MockAccessibleState) GetBlockContext() contract.BlockContext { return s.Block }
|
||||
func (s *MockAccessibleState) GetConsensusContext() context.Context { return context.Background() }
|
||||
func (s *MockAccessibleState) GetChainConfig() precompileconfig.ChainConfig { return s.Chain }
|
||||
func (s *MockAccessibleState) GetPrecompileEnv() contract.PrecompileEnvironment { return nil }
|
||||
|
||||
@@ -38,7 +38,7 @@ func TestAnchorCheckpoint_FullLifecycle(t *testing.T) {
|
||||
submitInput = append(submitInput, submitSelector...)
|
||||
submitInput = append(submitInput, appID[:]...) // appID (32 bytes)
|
||||
submitInput = append(submitInput, harness.Uint256(1)...) // height = 1
|
||||
submitInput = append(submitInput, stateHash[:]...) // root (32 bytes)
|
||||
submitInput = append(submitInput, stateHash[:]...) // root (32 bytes)
|
||||
|
||||
out, gas, err := harness.CallStateful(
|
||||
anchor.AnchorPrecompile,
|
||||
|
||||
@@ -57,8 +57,8 @@ func TestAttestationRegister_ComputeMarketplace(t *testing.T) {
|
||||
// Step 1: Register provider
|
||||
regInput := make([]byte, 0, 1+32+32)
|
||||
regInput = append(regInput, compute.OpRegisterProvider)
|
||||
regInput = append(regInput, harness.PadLeft([]byte("H100-80GB"), 32)...) // gpuType
|
||||
regInput = append(regInput, harness.Uint256(0xCAFEBABE)...) // TEE attestation hash
|
||||
regInput = append(regInput, harness.PadLeft([]byte("H100-80GB"), 32)...) // gpuType
|
||||
regInput = append(regInput, harness.Uint256(0xCAFEBABE)...) // TEE attestation hash
|
||||
|
||||
regOut, regGas, err := harness.CallStateful(
|
||||
compute.Precompile,
|
||||
@@ -78,7 +78,7 @@ func TestAttestationRegister_ComputeMarketplace(t *testing.T) {
|
||||
jobInput = append(jobInput, compute.OpSubmitJob)
|
||||
jobInput = append(jobInput, harness.Uint256(0x1234)...) // modelHash
|
||||
jobInput = append(jobInput, harness.Uint256(0x5678)...) // inputHash
|
||||
jobInput = append(jobInput, harness.Uint256(1e15)...) // maxPrice in wei
|
||||
jobInput = append(jobInput, harness.Uint256(1e15)...) // maxPrice in wei
|
||||
|
||||
jobOut, jobGas, err := harness.CallStateful(
|
||||
compute.Precompile,
|
||||
@@ -96,7 +96,7 @@ func TestAttestationRegister_ComputeMarketplace(t *testing.T) {
|
||||
// Step 3: Claim reward (provider completes the job)
|
||||
claimInput := make([]byte, 0, 1+32+32)
|
||||
claimInput = append(claimInput, compute.OpClaimReward)
|
||||
claimInput = append(claimInput, jobOut...) // jobID
|
||||
claimInput = append(claimInput, jobOut...) // jobID
|
||||
claimInput = append(claimInput, harness.Uint256(0xABCD)...) // outputHash
|
||||
|
||||
claimOut, claimGas, err := harness.CallStateful(
|
||||
|
||||
@@ -62,10 +62,10 @@ func TestDEXSwap_StableSwapGetDy(t *testing.T) {
|
||||
|
||||
input := make([]byte, 0, 1+1+1+32+1+64+32)
|
||||
input = append(input, stableswap.OpGetDy)
|
||||
input = append(input, 0) // i = token 0
|
||||
input = append(input, 1) // j = token 1
|
||||
input = append(input, 0) // i = token 0
|
||||
input = append(input, 1) // j = token 1
|
||||
input = append(input, dx...) // swap 1000
|
||||
input = append(input, 2) // numTokens
|
||||
input = append(input, 2) // numTokens
|
||||
input = append(input, balance...)
|
||||
input = append(input, balance...)
|
||||
input = append(input, amp...)
|
||||
|
||||
@@ -53,8 +53,8 @@ func TestKeygenSignVerify_CGGMP21(t *testing.T) {
|
||||
|
||||
// Input: threshold(4) + totalSigners(4) + pubkey(65) + hash(32) + sig(65)
|
||||
input := make([]byte, 0, 4+4+65+32+65)
|
||||
input = append(input, harness.Uint32BE(2)...) // threshold = 2
|
||||
input = append(input, harness.Uint32BE(3)...) // total signers = 3
|
||||
input = append(input, harness.Uint32BE(2)...) // threshold = 2
|
||||
input = append(input, harness.Uint32BE(3)...) // total signers = 3
|
||||
input = append(input, pubKey...)
|
||||
input = append(input, hash[:]...)
|
||||
input = append(input, sig...)
|
||||
@@ -120,8 +120,8 @@ func TestKeygenSignVerify_FROST(t *testing.T) {
|
||||
|
||||
// Input: threshold(4) + totalSigners(4) + pubkey(32) + hash(32) + sig(64)
|
||||
input := make([]byte, 0, 4+4+32+32+64)
|
||||
input = append(input, harness.Uint32BE(2)...) // threshold = 2
|
||||
input = append(input, harness.Uint32BE(3)...) // total signers = 3
|
||||
input = append(input, harness.Uint32BE(2)...) // threshold = 2
|
||||
input = append(input, harness.Uint32BE(3)...) // total signers = 3
|
||||
input = append(input, pubBytes...)
|
||||
input = append(input, hash[:]...)
|
||||
input = append(input, frostSig...)
|
||||
|
||||
@@ -23,10 +23,10 @@ func BenchmarkStableSwap_GetDy_10K(b *testing.B) {
|
||||
|
||||
input := make([]byte, 0, 1+1+1+32+1+64+32)
|
||||
input = append(input, stableswap.OpGetDy)
|
||||
input = append(input, 0) // i
|
||||
input = append(input, 1) // j
|
||||
input = append(input, 0) // i
|
||||
input = append(input, 1) // j
|
||||
input = append(input, dx...)
|
||||
input = append(input, 2) // numTokens
|
||||
input = append(input, 2) // numTokens
|
||||
input = append(input, balance...)
|
||||
input = append(input, balance...)
|
||||
input = append(input, amp...)
|
||||
|
||||
+5
-5
@@ -122,12 +122,12 @@ const (
|
||||
// so that gasLimit / GasMul ≥ MinSafeGasMulRatio.
|
||||
const (
|
||||
// Bootstrap-dominated arithmetic ops.
|
||||
GasAdd uint64 = WallClockMsAddUint8 * 12_000 // 180_000_000
|
||||
GasSub uint64 = GasAdd // same algorithm
|
||||
GasMul uint64 = WallClockMsMulUint8 * 12_000 // 936_000_000
|
||||
GasAdd uint64 = WallClockMsAddUint8 * 12_000 // 180_000_000
|
||||
GasSub uint64 = GasAdd // same algorithm
|
||||
GasMul uint64 = WallClockMsMulUint8 * 12_000 // 936_000_000
|
||||
GasDiv uint64 = (WallClockMsMulUint8 * 12_000) * 70 / 100 // 655_200_000 — binary long div ~0.7x mul
|
||||
GasRem uint64 = GasDiv // same algorithm
|
||||
GasNeg uint64 = GasAdd // single subtraction from zero
|
||||
GasRem uint64 = GasDiv // same algorithm
|
||||
GasNeg uint64 = GasAdd // single subtraction from zero
|
||||
|
||||
// Comparison ops (O(n) bootstraps; measured ratio ≈ Add).
|
||||
GasEq uint64 = GasAdd
|
||||
|
||||
+7
-7
@@ -44,8 +44,8 @@ func (s *testStateDB) SetState(addr common.Address, key, value common.Hash) comm
|
||||
}
|
||||
|
||||
func (s *testStateDB) SetNonce(common.Address, uint64, tracing.NonceChangeReason) {}
|
||||
func (s *testStateDB) GetNonce(common.Address) uint64 { return 0 }
|
||||
func (s *testStateDB) GetBalance(common.Address) *uint256.Int { return uint256.NewInt(0) }
|
||||
func (s *testStateDB) GetNonce(common.Address) uint64 { return 0 }
|
||||
func (s *testStateDB) GetBalance(common.Address) *uint256.Int { return uint256.NewInt(0) }
|
||||
func (s *testStateDB) AddBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int {
|
||||
return *uint256.NewInt(0)
|
||||
}
|
||||
@@ -55,15 +55,15 @@ func (s *testStateDB) SubBalance(common.Address, *uint256.Int, tracing.BalanceCh
|
||||
func (s *testStateDB) GetBalanceMultiCoin(common.Address, common.Hash) *big.Int { return big.NewInt(0) }
|
||||
func (s *testStateDB) AddBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (s *testStateDB) SubBalanceMultiCoin(common.Address, common.Hash, *big.Int) {}
|
||||
func (s *testStateDB) CreateAccount(common.Address) {}
|
||||
func (s *testStateDB) Exist(common.Address) bool { return false }
|
||||
func (s *testStateDB) AddLog(*ethtypes.Log) {}
|
||||
func (s *testStateDB) Logs() []*ethtypes.Log { return nil }
|
||||
func (s *testStateDB) CreateAccount(common.Address) {}
|
||||
func (s *testStateDB) Exist(common.Address) bool { return false }
|
||||
func (s *testStateDB) AddLog(*ethtypes.Log) {}
|
||||
func (s *testStateDB) Logs() []*ethtypes.Log { return nil }
|
||||
func (s *testStateDB) GetPredicateStorageSlots(common.Address, int) ([]byte, bool) {
|
||||
return nil, false
|
||||
}
|
||||
func (s *testStateDB) TxHash() common.Hash { return common.Hash{} }
|
||||
func (s *testStateDB) Snapshot() int { return 0 }
|
||||
func (s *testStateDB) Snapshot() int { return 0 }
|
||||
func (s *testStateDB) RevertToSnapshot(int) {}
|
||||
|
||||
var _ contract.StateDB = (*testStateDB)(nil)
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
)
|
||||
|
||||
type fakeConfig struct{}
|
||||
|
||||
func (f *fakeConfig) Key() string { return "fake" }
|
||||
func (f *fakeConfig) Timestamp() *uint64 { return nil }
|
||||
func (f *fakeConfig) IsDisabled() bool { return false }
|
||||
@@ -18,6 +19,7 @@ func (f *fakeConfig) Equal(precompileconfig.Config) bool { return false }
|
||||
func (f *fakeConfig) Verify(precompileconfig.ChainConfig) error { return nil }
|
||||
|
||||
type testChainCfg struct{}
|
||||
|
||||
func (t *testChainCfg) IsDurango(uint64) bool { return true }
|
||||
|
||||
func TestConfigLifecycle(t *testing.T) {
|
||||
|
||||
@@ -288,7 +288,7 @@ func TestParseSealParams_ShortAADData(t *testing.T) {
|
||||
input[4], input[5] = 0x00, 0x01
|
||||
binary.BigEndian.PutUint16(input[6+SeedSize:], uint16(pkSize))
|
||||
offset := 6 + SeedSize + 2 + pkSize
|
||||
binary.BigEndian.PutUint16(input[offset:], 0) // info len = 0
|
||||
binary.BigEndian.PutUint16(input[offset:], 0) // info len = 0
|
||||
binary.BigEndian.PutUint16(input[offset+2:], 10) // aad len = 10 but no data
|
||||
_, err := p.parseSealParams(input)
|
||||
require.Error(t, err)
|
||||
|
||||
@@ -16,11 +16,11 @@ import (
|
||||
|
||||
// TestRun_E2E_HQC128 — full end-to-end under the cgo-PQClean backend.
|
||||
//
|
||||
// 1. Generate an HQC-128 keypair off-chain (crypto/hqc.KeyGen).
|
||||
// 2. Build the precompile wire input: op(0x01) || mode(0x00) || seed(32B) || pk.
|
||||
// 3. Run the precompile → returns ct || ss.
|
||||
// 4. Off-chain decapsulate the ct with the sk → recovered ss must
|
||||
// equal the precompile's ss byte-for-byte.
|
||||
// 1. Generate an HQC-128 keypair off-chain (crypto/hqc.KeyGen).
|
||||
// 2. Build the precompile wire input: op(0x01) || mode(0x00) || seed(32B) || pk.
|
||||
// 3. Run the precompile → returns ct || ss.
|
||||
// 4. Off-chain decapsulate the ct with the sk → recovered ss must
|
||||
// equal the precompile's ss byte-for-byte.
|
||||
//
|
||||
// This is the property the HQC precompile exists to provide on-chain:
|
||||
// a verifier can generate a ciphertext that decapsulates (off-chain)
|
||||
@@ -36,9 +36,9 @@ func TestRun_E2E_HQC128(t *testing.T) {
|
||||
|
||||
seed := bytes.Repeat([]byte{0xAB}, SeedSize)
|
||||
in := make([]byte, 0, 2+SeedSize+params.PublicKeySize)
|
||||
in = append(in, 0x01) // op = Encapsulate
|
||||
in = append(in, 0x00) // mode = HQC-128
|
||||
in = append(in, seed...) // 32-byte deterministic-rng seed
|
||||
in = append(in, 0x01) // op = Encapsulate
|
||||
in = append(in, 0x00) // mode = HQC-128
|
||||
in = append(in, seed...) // 32-byte deterministic-rng seed
|
||||
in = append(in, pk.Bytes...)
|
||||
|
||||
out, _, err := HQCPrecompile.Run(nil, common.Address{}, ContractAddress,
|
||||
|
||||
@@ -81,4 +81,3 @@ func TestRun_WrongPubkeyLen(t *testing.T) {
|
||||
t.Errorf("wrong pubkey len: want ErrInvalidInputLength, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ var (
|
||||
|
||||
_ contract.StatefulPrecompiledContract = &mldsaVerifyPrecompile{}
|
||||
|
||||
ErrInvalidInputLength = contract.ErrInvalidInput
|
||||
ErrInvalidInputLength = contract.ErrInvalidInput
|
||||
ErrInvalidMode = errors.New("invalid ML-DSA mode")
|
||||
ErrUnsupportedMode = errors.New("unsupported ML-DSA mode")
|
||||
|
||||
|
||||
@@ -285,8 +285,8 @@ func TestBatchVerify_SingleValid(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBatchVerify_SingleInvalid(t *testing.T) {
|
||||
pk := make([]byte, MLDSA44PublicKeySize) // garbage key
|
||||
sig := make([]byte, MLDSA44SignatureSize) // garbage sig
|
||||
pk := make([]byte, MLDSA44PublicKeySize) // garbage key
|
||||
sig := make([]byte, MLDSA44SignatureSize) // garbage sig
|
||||
message := []byte("test")
|
||||
|
||||
entry := make([]byte, 0)
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ var (
|
||||
|
||||
_ contract.StatefulPrecompiledContract = &mlkemPrecompile{}
|
||||
|
||||
ErrInvalidInputLength = contract.ErrInvalidInput
|
||||
ErrInvalidInputLength = contract.ErrInvalidInput
|
||||
ErrInvalidMode = errors.New("invalid ML-KEM mode")
|
||||
ErrUnsupportedMode = errors.New("unsupported ML-KEM mode")
|
||||
ErrUnsupportedOperation = errors.New("unsupported operation")
|
||||
|
||||
+4
-4
@@ -18,7 +18,7 @@
|
||||
// 0x012203 = SLH-DSA (hash-based signature, FIPS 205)
|
||||
// 0x012204 = Pulsar (Module-LWE threshold FIPS 204, byte-equal)
|
||||
// 0x012205 = P3Q ← this precompile (strict-PQ STARK)
|
||||
// 0x012206 = Corona
|
||||
// 0x012206 = Corona
|
||||
//
|
||||
// Wire format (single dispatch, version byte differentiates future
|
||||
// proof formats; first deployment is v0x01):
|
||||
@@ -61,7 +61,7 @@ const MagicHeader = "P3Q1"
|
||||
|
||||
// Wire layout constants.
|
||||
const (
|
||||
versionByte = 1
|
||||
versionByte = 1
|
||||
proofLenByte = 4
|
||||
pubLenByte = 4
|
||||
|
||||
@@ -78,8 +78,8 @@ const (
|
||||
// size), but on-chain we only see the serialized proof; charge a flat
|
||||
// base plus a per-byte cost so callers pay for bandwidth and decode.
|
||||
const (
|
||||
BaseVerifyGas uint64 = 200_000
|
||||
PerByteGas uint64 = 10
|
||||
BaseVerifyGas uint64 = 200_000
|
||||
PerByteGas uint64 = 10
|
||||
)
|
||||
|
||||
// Error sentinels returned by this precompile.
|
||||
|
||||
@@ -124,7 +124,7 @@ const (
|
||||
ECDSACChain = "0x3210000000000000000000000000000000000000" // Extended ECDSA
|
||||
Ed25519CChain = "0x3211000000000000000000000000000000000000" // Ed25519
|
||||
BLS381CChain = "0x3212000000000000000000000000000000000000" // BLS12-381
|
||||
VRFCChain = "0x0000000000000000000000000000000000003213" // ECVRF (RFC 9381)
|
||||
VRFCChain = "0x0000000000000000000000000000000000003213" // ECVRF (RFC 9381)
|
||||
|
||||
// Encryption (II = 0x20-0x2F)
|
||||
AESGCMCChain = "0x3220000000000000000000000000000000000000" // AES-GCM
|
||||
@@ -199,8 +199,8 @@ const (
|
||||
FROSTQChain = "0x5300000000000000000000000000000000000000" // Q-Chain FROST
|
||||
CGGMP21CChain = "0x5201000000000000000000000000000000000000" // C-Chain CGGMP21
|
||||
CGGMP21QChain = "0x5301000000000000000000000000000000000000" // Q-Chain CGGMP21
|
||||
CoronaCChain = "0x5202000000000000000000000000000000000000" // C-Chain Corona
|
||||
CoronaQChain = "0x5302000000000000000000000000000000000000" // Q-Chain Corona
|
||||
CoronaCChain = "0x5202000000000000000000000000000000000000" // C-Chain Corona
|
||||
CoronaQChain = "0x5302000000000000000000000000000000000000" // Q-Chain Corona
|
||||
DoernerCChain = "0x5203000000000000000000000000000000000000" // C-Chain Doerner
|
||||
DoernerQChain = "0x5303000000000000000000000000000000000000" // Q-Chain Doerner
|
||||
BLSThreshCChain = "0x5204000000000000000000000000000000000000" // C-Chain BLS Threshold
|
||||
|
||||
@@ -15,8 +15,8 @@ func TestGasZero_Rejected(t *testing.T) {
|
||||
// Valid OpVerify + valid SchemeLSAGSecp256k1 ensures we reach the
|
||||
// gas check path rather than failing scheme validation first.
|
||||
input := make([]byte, 128)
|
||||
input[0] = OpVerify // 0x02 — only supported op
|
||||
input[1] = SchemeLSAGSecp256k1 // 0x01
|
||||
input[0] = OpVerify // 0x02 — only supported op
|
||||
input[1] = SchemeLSAGSecp256k1 // 0x01
|
||||
_, remainingGas, err := RingSignaturePrecompile.Run(nil, common.Address{}, ContractAddress, input, 0, true)
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, contract.ErrOutOfGas)
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ var (
|
||||
|
||||
_ contract.StatefulPrecompiledContract = &slhdsaVerifyPrecompile{}
|
||||
|
||||
ErrInvalidInputLength = contract.ErrInvalidInput
|
||||
ErrInvalidInputLength = contract.ErrInvalidInput
|
||||
ErrInvalidMode = errors.New("invalid SLH-DSA mode")
|
||||
ErrUnsupportedMode = errors.New("unsupported SLH-DSA mode")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user